|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcwi.GraphXML.AbstractParser
public abstract class AbstractParser
Abstract parser. This is a superclass for various xml parsers using different XML packages. It implements the management of error listeners, and provides the basic interface to access the real parser.
The code relies on the fact that entity reference nodes are expanded by the parser. Although some defence mechanisms are built in (to catch and ignore DOM node types for entities), entities are not expanded by the rest of the code!
Here is a typical usage of the parser (using the IBM parser as an example):
AbstractParser theParser = new IBMParser(); theParser.setGraphSemantics(new MyGraphSemantics()); theParser.addParserErrorListener(new ParserListenerAdapter()); theParser.interpret("XMLFileName");Which uses a specific implementation of a parser, uses a graph semantic class instance, (which should implement the
GraphSemantics
interface), a default
parser listener for error handling (which prints all messages on the standard error). It then
calls the parser to interpret a specific file.
By default, a validating parser is used. However, if the system property
XMLGraph_Validate
is set to No
, no
, False
,
or false
, a non-validating parser is used instead.
The error listener mechanism follows the standard Java style, and allows for several error reactions to be 'checked in' to the parser.
The parser mechanism is "reentrant", ie no static variables are used. This means that the parser can be invoked recursively by creating a new Parser instance. This may be important when handling, for example, metanodes.
The code ensures the DTDPATH facility: if the system property DTDPATH is set, it is considered to be a series of directory specification (much like the CLASSPATH variable) and it looks for a dtd file in those directory. This is preceded by an attempt to locate the dtd file in the same directory as the xml file itself, in the case this latter is specified in term of a file and not as a stream. Note, however, that this feature may not work with all xml parser implementation. It is known to work with xml4j from IBM, but it does not work properly with JAX version 1.0 of SUN.
GraphSemantics
Field Summary | |
---|---|
protected org.xml.sax.EntityResolver |
entityResolver
|
Constructor Summary | |
---|---|
AbstractParser()
|
Method Summary | |
---|---|
void |
addParserErrorListener(ParserErrorListener l)
Add new listener. |
StructureIterator |
decompose(java.io.InputStream xmlStream)
Decompose the document into a structure for a partial interpretation of a document. |
StructureIterator |
decompose(java.lang.String xmlFile)
Decompose the document into a structure for a partial interpretation of a document. |
void |
fireParserError(java.lang.String m)
Fire parser error. |
void |
fireParserFatalError(java.lang.String m)
Fire fatal parser error. |
void |
fireParserWarning(java.lang.String m)
Fire parser warning. |
static java.lang.String[] |
getKeywords()
Return the GraphXML keywords. |
static java.lang.String[] |
getStoppers()
Return the 'stopper' keywords. |
void |
interpret(java.io.InputStream xmlStream)
Parse and iterpret an xml graph |
void |
interpret(java.lang.String xmlFile)
Parse and interpret an xml graph file as one unit. |
org.w3c.dom.Document |
parse(java.io.InputStream xmlStream)
Parse a document, return a Document element. |
protected abstract org.w3c.dom.Document |
parse(java.io.InputStream xmlStream,
boolean validate)
Parse a document, return a Document element. |
org.w3c.dom.Document |
parse(java.lang.String xmlFile)
Parse a document, return a Document element. |
void |
removeParserErrorListener(ParserErrorListener l)
Remove a listener |
void |
setGraphSemantics(GraphSemantics semantics)
Set the collection of graph semantic methods. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected org.xml.sax.EntityResolver entityResolver
Constructor Detail |
---|
public AbstractParser()
Method Detail |
---|
public static java.lang.String[] getStoppers()
At this time, these are "graph", "edit", "edit-bundle", "node", and "edge"
public static java.lang.String[] getKeywords()
public void addParserErrorListener(ParserErrorListener l)
l
- new listenerpublic void removeParserErrorListener(ParserErrorListener l)
listener
- to be removed.public void fireParserWarning(java.lang.String m)
fireParserWarning
in interface ParserError
m
- warning messagepublic void fireParserError(java.lang.String m)
fireParserError
in interface ParserError
m
- warning messagepublic void fireParserFatalError(java.lang.String m)
fireParserFatalError
in interface ParserError
m
- warning messagepublic org.w3c.dom.Document parse(java.lang.String xmlFile)
This access to the parser is rarely used; use the interpret and decompose methods below instead.
xmlFile
- the xml file to parse.public org.w3c.dom.Document parse(java.io.InputStream xmlStream)
This access to the parser is rarely used; use the interpret and decompose methods below instead.
The system property XMLGraph_Validate is checked agains a "true" or "false" value to decide whether a validating or a non-validating parser is used. If the property is not set, validation is used.
xmlStream
- the xml stream to parse.protected abstract org.w3c.dom.Document parse(java.io.InputStream xmlStream, boolean validate)
This access to the parser is rarely used; use the interpret and decompose methods below instead.
This is the only abstract method in the class, which should be 'filled in' by the XML parser specific sub-class. All other methods can be left intact.
The subclass should take care of including the following code:
theParser.setEntityResolver(entityResolver);
This is a SAX call which should be used to ensure the DTDPATH facility, ie, that DTD calls may refer to dtd files at various places in the local file directory. Note that not all parser implementation may include that feature yet, or their behaviour might not be appropriate.
xmlStream
- the xml stream to parsevalidate
- decide whether the parser is validating or notpublic void setGraphSemantics(GraphSemantics semantics)
semantics
- GraphSemantics class instancepublic void interpret(java.lang.String xmlFile)
xmlFile
- The xml filepublic void interpret(java.io.InputStream xmlStream)
xmlStream
- the xml stream to parse.public StructureIterator decompose(java.lang.String xmlFile)
xmlFile
- the xml file to parse.
public StructureIterator decompose(java.io.InputStream xmlStream)
xmlStream
- the xml stream to parse.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |