|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--de.zeigermann.xml.simpleImporter.SimpleImporter
Simple and fast importer for XML configuration or import files.
It is based on SAX and can be considered an extension to it. This means it is
callback oriented and does not build an internal data structure like the DOM.
While SAX is simple, fast, and memory friendly it might be a bit too
rudimentary for most tasks. SimpleImporter
adds more high level
means for importing XML while preserving the SAX's benefits.
As with SAX you register a callback handler (SimpleImportHandler
)
that is called upon events. Consider the following example implementation
of a SimpleImportHandler
:
Registering this class with
public class DemoHandler implements SimpleImportHandler {
public void startDocument() { }
public void endDocument() { }
public void cData(SimplePath path, String cdata) { }
public void startElement(SimplePath path, String name, AttributesImpl attributes, String leadingCDdata) {
if (path.matches("/root/interesting-element")) {
System.out.println(leadingCDdata);
}
}
public void endElement(SimplePath path, String name) { }
}
addSimpleImportHandler(de.zeigermann.xml.simpleImporter.SimpleImportHandler)
and call
parse(org.xml.sax.InputSource)
on an input stream or parseUrlOrFile(java.lang.String)
will dump
the leading text of the element matching the path (SimplePath
)
"/root/interesting-element".
Note: This class is thread safe.
Field Summary | |
protected List |
callbackHandlerList
|
protected de.zeigermann.xml.simpleImporter.SimpleImporter.ParseElement |
currentElement
|
protected StringBuffer |
currentMixedPCData
|
protected String |
debugBuffer
|
protected SAXParserFactory |
factory
|
protected StringBuffer |
firstPCData
|
protected boolean |
foundMixedPCData
|
protected boolean |
isFirstPCData
|
protected de.zeigermann.xml.simpleImporter.SimpleImporter.PathStack |
parseStack
|
Constructor Summary | |
SimpleImporter()
Creates a new SimpleImporter object having default property settings. |
Method Summary | |
void |
addSimpleImportHandler(SimpleImportHandler callbackHandler)
Adds a new callback handler if it is not in the callback list, yet. |
boolean |
getFoundMixedPCData()
Determines if we have found any mixed content while parsing. |
boolean |
getFullDebugMode()
Gets the property described in setFullDebugMode(boolean) . |
boolean |
getIncludeLeadingCDataIntoStartElementCallback()
Gets property telling importer to return any leading CDATA, i.e. |
boolean |
getMakeCopy()
Gets the property describing if every callback handler gets a fresh copy of the parsed data. |
String |
getParsedStreamForDebug()
Gets the whole stream parsed in the parse(org.xml.sax.InputSource) method. |
boolean |
getTrimContent()
Sets the property described in setTrimContent(boolean) . |
boolean |
getZeroLengthIsNull()
Gets property: When findind zero length content should it be treated as null data? |
void |
parse(InputSource is)
Parses the input source using the standard SAX parser and calls back the callback handlers. |
void |
parseUrlOrFile(String urlOrFileName)
Tries to parse the file or URL named by parameter urlOrFileName .
|
void |
removeSimpleImportHandler(SimpleImportHandler callbackHandler)
Removes a callback handler if it is in the callback list. |
void |
setFullDebugMode(boolean fullDebug)
Sets the full debug mode which enables us to get the parsed stream as string via the getParsedStreamForDebug()
method even if an error occured. |
void |
setIncludeLeadingCDataIntoStartElementCallback(boolean includeLeadingCDataIntoStartElementCallback)
Sets the property described in getIncludeLeadingCDataIntoStartElementCallback() . |
void |
setMakeCopy(boolean makeCopy)
Sets the property described in getMakeCopy() . |
void |
setTrimContent(boolean trimContent)
Sets when all content shall be trimed. |
void |
setZeroLengthIsNull(boolean zeroLengthIsNull)
Sets the property described in getZeroLengthIsNull() . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected SAXParserFactory factory
protected List callbackHandlerList
protected StringBuffer currentMixedPCData
protected boolean foundMixedPCData
protected StringBuffer firstPCData
protected boolean isFirstPCData
protected de.zeigermann.xml.simpleImporter.SimpleImporter.ParseElement currentElement
protected de.zeigermann.xml.simpleImporter.SimpleImporter.PathStack parseStack
protected String debugBuffer
Constructor Detail |
public SimpleImporter()
Method Detail |
public boolean getFoundMixedPCData()
public void setFullDebugMode(boolean fullDebug)
getParsedStreamForDebug()
method even if an error occured.
public boolean getFullDebugMode()
setFullDebugMode(boolean)
.
public String getParsedStreamForDebug()
parse(org.xml.sax.InputSource)
method. As this requires some actions
significantly slowing down the whole parse, this only works if it has been enabled
by the the setFullDebugMode(boolean)
method.
public boolean getIncludeLeadingCDataIntoStartElementCallback()
SimpleImportHandler.cData(de.zeigermann.xml.simpleImporter.SimplePath, java.lang.String)
just like any CDATA in a mixed
content.
SimpleImportHandler.startElement(de.zeigermann.xml.simpleImporter.SimplePath, java.lang.String, org.xml.sax.helpers.AttributesImpl, java.lang.String)
,
setIncludeLeadingCDataIntoStartElementCallback(boolean)
public void setIncludeLeadingCDataIntoStartElementCallback(boolean includeLeadingCDataIntoStartElementCallback)
getIncludeLeadingCDataIntoStartElementCallback()
.
public boolean getTrimContent()
setTrimContent(boolean)
.
public void setTrimContent(boolean trimContent)
setZeroLengthIsNull(boolean)
all whitespace data will not be
reported to callback handlers.
public boolean getZeroLengthIsNull()
public void setZeroLengthIsNull(boolean zeroLengthIsNull)
getZeroLengthIsNull()
.
public boolean getMakeCopy()
public void setMakeCopy(boolean makeCopy)
getMakeCopy()
.
public void addSimpleImportHandler(SimpleImportHandler callbackHandler)
removeSimpleImportHandler(de.zeigermann.xml.simpleImporter.SimpleImportHandler)
public void removeSimpleImportHandler(SimpleImportHandler callbackHandler)
addSimpleImportHandler(de.zeigermann.xml.simpleImporter.SimpleImportHandler)
public void parseUrlOrFile(String urlOrFileName) throws ParserConfigurationException, SAXException, IOException, SimpleImporterException
urlOrFileName
.
First it tries to parse it as URL, if this does not work, it tries to parse it as file.
If one option works, an input stream will be opened and parse(org.xml.sax.InputSource)
will be called with it.
If both does not work, an exception is thrown.
ParserConfigurationException
SAXException
IOException
SimpleImporterException
parse(org.xml.sax.InputSource)
public void parse(InputSource is) throws ParserConfigurationException, SAXException, IOException
setFullDebugMode(boolean)
the source will be verbosely copied first.
ParserConfigurationException
SAXException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |