Package com.ibm.di.parser.xml
Class XMLParser2
- java.lang.Object
-
- com.ibm.di.parser.ParserImpl
-
- com.ibm.di.parser.xml.XMLParser2
-
- All Implemented Interfaces:
ParserInterface
,VersionInfoInterface
- Direct Known Subclasses:
CBEParser
,IdMLParser
,SPMLv2Parser
public class XMLParser2 extends ParserImpl implements ParserInterface
The Parser used to parse XML documents using the XLXP implementation of the StAX XML Parser. This parser is able to write XML using the same library.- Since:
- 7.0
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
attrsDeclaration
the attributes declaration parameter as Stringprotected java.lang.String
charEncoding
String which value is used for decoding the InputStream and encoding the OutputStreamprotected boolean
coalescing
shows whether any text characters and the CDATA section will be treated as text.protected java.io.ByteArrayOutputStream
currentEntryAsXML
When parsing the XML the Parser will write in this stream so we have String representation of the returned Entryprotected java.lang.String
currentEntryAsXMLString
This variable just holds the current Entry as XML string so we do not decode the stream twice or more.static java.lang.String
DEFAULT_ENCODING
The default encoding to use if the user have not specified one or we were unable to find the actual encodingprotected static java.lang.String
DUMMY_ROOT_NAME
This is the name of the root tag that will be plugged in to handle multiple root tag XMLs.protected java.lang.String[]
entryTag
the value of the Entry Tag parameter.
position 0 holds the declared prefix or null if none
position 1 holds the declared localName or null if none
position 2 holds the declared namespaceURI or null if none definedprotected boolean
firstWriteStart
shows if the start root elements are to be written for first timeprotected boolean
indentOutput
shows whether the output should be indentedprotected java.lang.String
nsMap
the prefix to namespaceURI map as Stringprotected NamespacesTracker
nsTracker
Used for tracking the written namespacesprotected boolean
skipXMLOnReading
skip repeating XML declarations when readingprotected boolean
skipXMLOnWriting
omit XML declaration in the beginning of the outputprotected boolean
standaloneRoot
shows if the static roots should be output on each entryprotected java.lang.String[]
valueTag
the value of the Value Tag parameter.protected boolean
wrapUnwrapEntry
Flag that shows whether the entry will be wrapped in a tag or not.protected java.lang.String
xmlVersion
the XML version to put in XML declaration when writingprotected SimpleXPathEvaluator
xPath
this object is used for compiling the input parameters and when navigating through XML elementsprotected java.lang.String
xPathStr
the raw Simple xPath stringprotected java.lang.String
xsdPath
the XSD URLs String-
Fields inherited from class com.ibm.di.parser.ParserImpl
_debug, myConfiguration
-
-
Constructor Summary
Constructors Constructor Description XMLParser2()
Constructs the XMLParser2 object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeParser()
This method closes the parser's streamsjava.io.ByteArrayInputStream
getCurrentEntryAsXMLStream()
java.lang.String
getCurrentEntryAsXMLString()
Converts current entry to XML.java.util.List<javax.xml.namespace.QName>
getCurrentEntryPath()
Retrieves current xPath's nodes parser is working on.protected Log
getLogger()
Retrieves log object.java.util.HashMap<java.lang.String,java.lang.String>
getSchemaLocationFromXML()
This method runs through the XML and tries to find any XSD URLsjava.lang.String
getVersion()
print the version of the componentprotected void
initInput()
Initializes the Input.protected void
initOutput()
Initializes the Output.void
initParser()
Initializes the parser.java.lang.Object
querySchema(java.lang.Object schema)
Discover the schema for the Parser.Entry
readEntry()
Retrieves an Entry object from the XML document.void
writeEntry(Entry entry)
Writes the passed as parameter Entry object as a XML data.-
Methods inherited from class com.ibm.di.parser.ParserImpl
debug, debugMode, flush, getClassInstance, getContext, getDebug, getInputStream, getOutputStream, getParam, getParser, getReader, getWriter, isDeltaSupported, logmsg, registerScriptBeans, setConfiguration, setContext, setDebug, setInputStream, setInputStream, setInputStream, setOutputStream, setOutputStream, setParam, setParser
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.ibm.di.parser.ParserInterface
flush, getContext, getDebug, getParam, getParser, getReader, getWriter, isDeltaSupported, registerScriptBeans, setConfiguration, setContext, setDebug, setInputStream, setInputStream, setInputStream, setOutputStream, setOutputStream, setParam, setParser
-
-
-
-
Field Detail
-
DEFAULT_ENCODING
public static final java.lang.String DEFAULT_ENCODING
The default encoding to use if the user have not specified one or we were unable to find the actual encoding- See Also:
- Constant Field Values
-
DUMMY_ROOT_NAME
protected static final java.lang.String DUMMY_ROOT_NAME
This is the name of the root tag that will be plugged in to handle multiple root tag XMLs. This should never be visible to the end-user- See Also:
- Constant Field Values
-
currentEntryAsXML
protected java.io.ByteArrayOutputStream currentEntryAsXML
When parsing the XML the Parser will write in this stream so we have String representation of the returned Entry
-
currentEntryAsXMLString
protected java.lang.String currentEntryAsXMLString
This variable just holds the current Entry as XML string so we do not decode the stream twice or more.
-
xsdPath
protected java.lang.String xsdPath
the XSD URLs String
-
xPathStr
protected java.lang.String xPathStr
the raw Simple xPath string
-
nsMap
protected java.lang.String nsMap
the prefix to namespaceURI map as String
-
charEncoding
protected java.lang.String charEncoding
String which value is used for decoding the InputStream and encoding the OutputStream
-
xmlVersion
protected java.lang.String xmlVersion
the XML version to put in XML declaration when writing
-
attrsDeclaration
protected java.lang.String attrsDeclaration
the attributes declaration parameter as String
-
entryTag
protected java.lang.String[] entryTag
the value of the Entry Tag parameter.
position 0 holds the declared prefix or null if none
position 1 holds the declared localName or null if none
position 2 holds the declared namespaceURI or null if none defined
-
valueTag
protected java.lang.String[] valueTag
the value of the Value Tag parameter. If nothing specified "value" will be assumed.
position 0 holds the declared prefix or null if none
position 1 holds the declared localName or null if none
position 2 holds the declared namespaceURI or null if none defined
-
wrapUnwrapEntry
protected boolean wrapUnwrapEntry
Flag that shows whether the entry will be wrapped in a tag or not.
-
skipXMLOnWriting
protected boolean skipXMLOnWriting
omit XML declaration in the beginning of the output
-
skipXMLOnReading
protected boolean skipXMLOnReading
skip repeating XML declarations when reading
-
coalescing
protected boolean coalescing
shows whether any text characters and the CDATA section will be treated as text.
-
firstWriteStart
protected boolean firstWriteStart
shows if the start root elements are to be written for first time
-
standaloneRoot
protected boolean standaloneRoot
shows if the static roots should be output on each entry
-
indentOutput
protected boolean indentOutput
shows whether the output should be indented
-
xPath
protected SimpleXPathEvaluator xPath
this object is used for compiling the input parameters and when navigating through XML elements
-
nsTracker
protected NamespacesTracker nsTracker
Used for tracking the written namespaces
-
-
Method Detail
-
initParser
public void initParser() throws java.lang.Exception
Initializes the parser.- Specified by:
initParser
in interfaceParserInterface
- Overrides:
initParser
in classParserImpl
- Throws:
java.lang.Exception
- - if initialization error occurs
-
initInput
protected void initInput() throws java.lang.Exception
Initializes the Input. Note: this parser relies on a Reader object to read the XML document.- Throws:
java.lang.Exception
- - in case of a read error occurs.- See Also:
ParserImpl.setInputStream(java.io.Reader)
-
initOutput
protected void initOutput() throws java.lang.Exception
Initializes the Output.- Throws:
java.lang.Exception
- - in case of write error occurs.
-
readEntry
public Entry readEntry() throws java.lang.Exception
Retrieves an Entry object from the XML document.- Specified by:
readEntry
in interfaceParserInterface
- Returns:
- an Object Model of the parsed XML, or null if no more data could be retrieved
- Throws:
java.lang.Exception
- - if an error occurs while parsing
-
writeEntry
public void writeEntry(Entry entry) throws java.lang.Exception
Writes the passed as parameter Entry object as a XML data.- Specified by:
writeEntry
in interfaceParserInterface
- Parameters:
entry
- - the entry that should be written as XML- Throws:
java.lang.Exception
- - in case of write error occurs
-
getVersion
public java.lang.String getVersion()
print the version of the component- Specified by:
getVersion
in interfaceVersionInfoInterface
- Returns:
- the version as String
-
closeParser
public void closeParser() throws java.lang.Exception
This method closes the parser's streams- Specified by:
closeParser
in interfaceParserInterface
- Overrides:
closeParser
in classParserImpl
- Throws:
java.lang.Exception
- in case an error occurs
-
getCurrentEntryAsXMLStream
public java.io.ByteArrayInputStream getCurrentEntryAsXMLStream()
- Returns:
- XML representation of the last retrieved entry (or null if no entry was found) as a ByteArrayInputStream object encoded using the specified in the characterSet parameter encoding. If the specified encoding is UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE then the first few bytes will be BOM bytes.
-
getCurrentEntryAsXMLString
public java.lang.String getCurrentEntryAsXMLString() throws java.io.UnsupportedEncodingException
Converts current entry to XML.- Returns:
- XML representation of the last retrieved entry (or null if no entry was found) as a decoded String object with removed BOM
- Throws:
java.io.UnsupportedEncodingException
- - if the specified encoding is not supported
-
getCurrentEntryPath
public java.util.List<javax.xml.namespace.QName> getCurrentEntryPath()
Retrieves current xPath's nodes parser is working on.- Returns:
- current xPath's nodes parser is working on
-
getLogger
protected Log getLogger()
Retrieves log object.- Returns:
- the Log used for logging.
-
querySchema
public java.lang.Object querySchema(java.lang.Object schema) throws java.lang.Exception
Discover the schema for the Parser. For example, a XML Parser could return a representation of the XML Schema or the DTD referenced in a XML file.- Specified by:
querySchema
in interfaceParserInterface
- Overrides:
querySchema
in classParserImpl
- Parameters:
schema
- The object on which to discover schema- Returns:
- A Vector of com.ibm.di.entry.Entry objects describing each entity
- Throws:
java.lang.Exception
- If an I/O error occurs
-
getSchemaLocationFromXML
public java.util.HashMap<java.lang.String,java.lang.String> getSchemaLocationFromXML() throws java.lang.Exception
This method runs through the XML and tries to find any XSD URLs- Returns:
- HashMap - the mapping is from the xsdURL to xsdNamespace
- Throws:
java.lang.Exception
- - in case parsing exception occurs
-
-