|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.primix.tapestry.util.xml.AbstractDocumentParser
A wrapper around DocumentBuilder
(itself a wrapper around
some XML parser), this class provides error handling and entity
resolving.
Constructor Summary | |
AbstractDocumentParser()
|
Method Summary | |
protected DocumentBuilder |
constructBuilder()
Constructs a new DocumentBuilder to be used for parsing. |
void |
error(SAXParseException exception)
Throws the exception, which is caught and wrapped in a DocumentParseException by parse(InputSource,String,String) . |
void |
fatalError(SAXParseException exception)
Throws the exception, which is caught and wrapped in a DocumentParseException by parse(InputSource,String,String) . |
protected java.lang.String |
getAttribute(Node node,
java.lang.String attributeName)
Returns the value of the named attribute of the node. |
protected java.lang.String |
getId(Node node)
Returns the value of an Element node (via getValue(Node) ),
but then validates that the result is a good identifier (starts with a
letter, contains letters, numbers, dashes, underscore). |
protected java.lang.String |
getNodePath(Node node)
Returns a 'path' to the given node, which is a list of enclosing element names seperated by periods. |
protected boolean |
getRequireValidatingParser()
Used by constructBuilder() to determine if the a validating
DocumentBuilder is required. |
java.lang.String |
getResourcePath()
|
protected java.lang.String |
getValue(Node node)
Returns the value of an Element node. |
protected boolean |
isElement(Node node,
java.lang.String elementName)
Returns true if the node is an element with the specified name. |
protected Document |
parse(InputSource source,
java.lang.String resourcePath,
java.lang.String rootElementName)
Invoked by subclasses to parse a document. |
protected void |
register(java.lang.String publicId,
java.lang.String entityPath)
Invoked by subclasses (usually inside thier constructor) to register a public id and corresponding input source. |
InputSource |
resolveEntity(java.lang.String publicId,
java.lang.String systemId)
Checks for a previously registered public ID and returns the corresponding input source. |
void |
setResourcePath(java.lang.String value)
|
void |
warning(SAXParseException exception)
Throws the exception, which is caught and wrapped in a DocumentParseException by parse(InputSource,String,String) . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public AbstractDocumentParser()
Method Detail |
protected void register(java.lang.String publicId, java.lang.String entityPath)
publicId
- the public identifier to be registerred, generally
the publicId of a DTD related to the document being parsedentityPath
- the resource path of the entity, typically a DTD
file. Relative files names are expected to be stored in the same package
as the class file, otherwise a leading slash is an absolute pathname
within the classpath.public java.lang.String getResourcePath()
public void setResourcePath(java.lang.String value)
protected Document parse(InputSource source, java.lang.String resourcePath, java.lang.String rootElementName) throws DocumentParseException
DocumentBuilder
and parses the document from the InputSource
.source
- source from which to read the documentresourcePath
- a description of the source, used in errorsrootElementName
- the expected root element of the Document
DocumentParseException
- wrapped around SAXParseException
or
IOException
, or if the root element is wrong.public void warning(SAXParseException exception) throws SAXException
DocumentParseException
by parse(InputSource,String,String)
.warning
in interface ErrorHandler
public void error(SAXParseException exception) throws SAXException
DocumentParseException
by parse(InputSource,String,String)
.error
in interface ErrorHandler
public void fatalError(SAXParseException exception) throws SAXException
DocumentParseException
by parse(InputSource,String,String)
.fatalError
in interface ErrorHandler
public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException, java.io.IOException
resolveEntity
in interface EntityResolver
protected boolean isElement(Node node, java.lang.String elementName) throws DocumentParseException
protected java.lang.String getValue(Node node)
Element
node. That is, all the Text
nodes appended together. Invokes trim() to remove leading and trailing spaces.protected java.lang.String getId(Node node) throws DocumentParseException
Element
node (via getValue(Node)
),
but then validates that the result is a good identifier (starts with a
letter, contains letters, numbers, dashes, underscore).protected java.lang.String getNodePath(Node node)
protected DocumentBuilder constructBuilder() throws ParserConfigurationException
DocumentBuilder
to be used for parsing.
The builder is used and reused, at least until there is an error
parsing a document (at which point, it is discarded).
This implementation obtains a builder with the following characteristics:
getRequireValidatingParser()
returns true}
These characteristics are appropriate to parsing things such as Tapestry specifications; subclasses with unusual demands may need to override this method.
The builder uses this AbstractDocumentParser
as the entity resolver and error handler.
protected boolean getRequireValidatingParser()
constructBuilder()
to determine if the a validating
DocumentBuilder
is required. This implementation returns true,
subclasses that don't require a validating builder (such as documents
without a known DTD), may override to return false.protected java.lang.String getAttribute(Node node, java.lang.String attributeName)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |