|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.xml.sax.helpers.DefaultHandler
com.xerceo.xml.Sax
public class Sax
Much like its parent class, this is a base class for application specific SAX event handlers to extend. It helps minimize duplication of common SAX processing code. Also provides some class-level convenience methods for reading and writing XML.
| Field Summary | |
|---|---|
protected java.lang.StringBuffer |
buf
Internal buffer that gets reused. |
static java.lang.String |
CDATA
Constant used by XML serializers for CDATA attribute types. |
protected java.lang.StringBuffer |
charsBuf
Interal buffer used to save characters received from characters SAX events. |
static java.lang.String |
DECL_HANDLER
SAX property name for adding the DeclHandler to the XMLReader. |
protected java.lang.String |
dtdResourceName
The resource name of the DTD on the classpath. |
protected java.lang.String |
dtdSystemId
The external form of the URL to the DTD for the document this handler processes. |
protected java.util.Stack |
elementNameStack
Keeps track of depth in the document. |
static java.lang.String |
INDENT
Constant for enabling indentation during output formatting. |
static java.lang.String |
LEXICAL_SAX_PROPERTY
SAX property name for adding a LexicalHandler to the XMLReader. |
protected java.lang.String |
namespace
Holds the namespace URI for the XMLInteraction spec document. |
static java.lang.String |
NMTOKEN
Constant used by XML serializers for NMTOKEN attribute types. |
static org.xml.sax.helpers.AttributesImpl |
NO_ATTRS
Reference to an empty AttributesImpl instance for creating elements with no attributes. |
protected java.lang.String |
rootName
Holds the root element name for the document. |
static java.lang.String |
UTF_8_ENCODING
Constant for the default XML character encoding: UTF-8. |
protected Version |
version
Holds version information for a version element; only valid after handleVersionStart() method invoked. |
| Constructor Summary | |
|---|---|
Sax()
Constructs a new Sax and ensures all member variables are initialized to prepare for handling SAX events. |
|
Sax(java.lang.String dtdSystemId,
java.lang.String dtdResourceName,
java.lang.String namespace,
java.lang.String rootName,
boolean trackElementNames)
Constructs a new Sax and ensures all member variables are initialized to prepare for handling SAX events. |
|
| Method Summary | |
|---|---|
static void |
applySAXExtensions(org.xml.sax.XMLReader xmlReader,
org.xml.sax.ContentHandler handler)
Applies the SAX extension handlers to the XMLReader if available. |
void |
characters(char[] ch,
int start,
int length)
Read characters from ch into an internal buffer; if an
element is interested in receiving character data, it will ensure the
internal buffer is not null. |
void |
comment(char[] ch,
int start,
int length)
No-op implementation required by the LexicalHandler interface. |
void |
endCDATA()
No-op implementation required by the LexicalHandler interface. |
void |
endDocument()
Resets the state of this instance back to its initialized state. |
void |
endDTD()
No-op implementation required by the LexicalHandler interface. |
protected void |
endElement(java.lang.String localName)
Convenience method for processing endElement events using the localName, as determined by the getElementName method. |
void |
endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
|
void |
endEntity(java.lang.String name)
No-op implementation required by the LexicalHandler interface. |
protected void |
endUnknownElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
Convenience method for processing endElement events where the appropriate element name is unknown as determined by a null return value form getElementName. |
void |
error(org.xml.sax.SAXParseException spe)
Called by the SAX parser to indicate a non-fatal (recoverable) parse error, such as the violation of a validity constraint. |
void |
fatalError(org.xml.sax.SAXParseException spe)
Called by the SAX parser to indicate a fatal parse error that prevents the SAX parser from processing the document, such as a violation of a well-formedness constraint. |
static void |
fromXML(org.xml.sax.InputSource saxIn,
boolean validate,
org.xml.sax.helpers.DefaultHandler handler)
Helper method for parsing an XML document using SAX. |
protected java.lang.String |
getChars()
|
protected java.lang.String |
getElementName(java.lang.String ns,
java.lang.String lName,
java.lang.String qName)
Determines the name of the element to process in the startElement(String, Attributes) method based
on the namespace URI, local name, and qualified name provided by
the SAX2 event generator. |
protected java.lang.String |
getElementPath()
Returns a guess at the current element path where an error or warning occured. |
protected java.lang.Object[] |
getParamsFromSAXException(org.xml.sax.SAXParseException spe)
Convenience method for extracting information from the SAXParseException into an array of replaceable parameters for generating a message. |
static org.xml.sax.ContentHandler |
getSerializer(java.io.OutputStream out)
Helper method for getting a SAX ContentHandler interface for serializing an object as XML. |
static org.xml.sax.ContentHandler |
getSerializer(java.io.OutputStream out,
java.util.Properties props)
Helper method for getting a SAX ContentHandler interface for serializing an object as XML. |
static org.xml.sax.ContentHandler |
getSerializer(javax.xml.transform.Result result,
java.util.Properties props)
Helper method for getting a SAX ContentHandler interface for serializing an object as XML. |
static org.xml.sax.ContentHandler |
getToStringSerializer(java.io.StringWriter writer)
Helper method for getting a SAX ContentHandler interface for serializing an object as XML to |
static javax.xml.transform.Transformer |
getTransformer()
Gets a TrAX Transformer instance with the default configuration. |
static javax.xml.transform.TransformerFactory |
getTransformerFactory()
Gets the TransformerFactory that this class uses to access any transformation resources it needs. |
protected void |
handleVersionEnd()
Sets the version member variable back to null; sub-classes should over-ride this method to do something with the version object before setting it back to null. |
protected void |
handleVersionStart(org.xml.sax.Attributes attrs)
Initializes the version member variable using the attributes from a version element found in the document. |
protected java.io.InputStream |
openSystemIdStream(java.lang.String systemId)
Opens an I/O InputStream to the supplied
systemId. |
protected java.io.InputStream |
openURLStream(java.lang.String systemId)
Opens a network I/O InputStream to the supplied URL. |
org.xml.sax.InputSource |
resolveEntity(java.lang.String publicId,
java.lang.String systemId)
Provides a SAX InputSource to the DTD for validating the instance document. |
void |
startCDATA()
No-op implementation required by the LexicalHandler interface. |
void |
startDocument()
Sets all members used during a parse to null. |
void |
startDTD(java.lang.String name,
java.lang.String pubId,
java.lang.String sysId)
No-op implementation required by the LexicalHandler interface. |
protected void |
startElement(java.lang.String localName,
org.xml.sax.Attributes attrs)
Convenience method for processing startElement events using the localName, as determined by the getElementName method. |
void |
startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
|
void |
startEntity(java.lang.String name)
No-op implementation required by the LexicalHandler interface. |
protected void |
startUnknownElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
Convenience method for processing startElement events where the appropriate element name is unknown as determined by a null return value form getElementName. |
static java.lang.String |
toAttrString(org.xml.sax.Attributes attrs)
|
static void |
toCDATA(char[] ach,
org.xml.sax.ContentHandler sax)
|
static void |
toCDATA(java.lang.String cdata,
org.xml.sax.ContentHandler sax)
|
static void |
toChars(java.lang.String cdata,
org.xml.sax.ContentHandler sax)
|
static void |
toSimple(java.lang.String name,
java.lang.String cdata,
org.xml.sax.ContentHandler sax)
|
static void |
toSimple(java.lang.String nsUri,
java.lang.String name,
java.lang.String cdata,
org.xml.sax.ContentHandler sax)
|
void |
warning(org.xml.sax.SAXParseException spe)
Called by the SAX parser to indicate a condition that is not an error or fatal error, but is still cause for concern. |
| Methods inherited from class org.xml.sax.helpers.DefaultHandler |
|---|
endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String LEXICAL_SAX_PROPERTY
public static final java.lang.String DECL_HANDLER
public static final java.lang.String CDATA
public static final java.lang.String NMTOKEN
public static final java.lang.String UTF_8_ENCODING
public static final java.lang.String INDENT
public static final org.xml.sax.helpers.AttributesImpl NO_ATTRS
protected java.lang.String dtdSystemId
protected java.lang.String dtdResourceName
protected java.lang.String namespace
protected java.lang.String rootName
protected java.lang.StringBuffer charsBuf
characters SAX events. If an element is interested
in retrieving character content, it should make sure that
it sets this member to buf in the
startElement method.
protected java.lang.StringBuffer buf
buf.setLength(0); after retrieving content
from it with a call to buf.toString();
protected java.util.Stack elementNameStack
protected Version version
handleVersionStart() method invoked.
| Constructor Detail |
|---|
public Sax()
public Sax(java.lang.String dtdSystemId,
java.lang.String dtdResourceName,
java.lang.String namespace,
java.lang.String rootName,
boolean trackElementNames)
dtdSystemId - The external form of the URL for the DTD; may be
null of the document doesn't have a DTD.dtdResourceName - The CLASSPATH resource path for the DTD if it
is available on the CLASSPATH; to avoid a call to the Internet.namespace - The default namespace URI used by the source
document.rootName - The root name (local) of the document.trackElementNames - A flag to indicate if element name tracking
(using a standard Stack) is desired by the application.| Method Detail |
|---|
public static final void toCDATA(char[] ach,
org.xml.sax.ContentHandler sax)
throws org.xml.sax.SAXException
org.xml.sax.SAXException
public static final void toCDATA(java.lang.String cdata,
org.xml.sax.ContentHandler sax)
throws org.xml.sax.SAXException
org.xml.sax.SAXException
public static final void toChars(java.lang.String cdata,
org.xml.sax.ContentHandler sax)
throws org.xml.sax.SAXException
org.xml.sax.SAXException
public static final void toSimple(java.lang.String name,
java.lang.String cdata,
org.xml.sax.ContentHandler sax)
throws org.xml.sax.SAXException
org.xml.sax.SAXException
public static final void toSimple(java.lang.String nsUri,
java.lang.String name,
java.lang.String cdata,
org.xml.sax.ContentHandler sax)
throws org.xml.sax.SAXException
org.xml.sax.SAXExceptionpublic static javax.xml.transform.TransformerFactory getTransformerFactory()
public static javax.xml.transform.Transformer getTransformer()
throws javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerConfigurationException
public static org.xml.sax.ContentHandler getToStringSerializer(java.io.StringWriter writer)
throws org.xml.sax.SAXException
out - The destination for the XML output.
org.xml.sax.SAXException - if an error occurs while creating the serializer.
public static org.xml.sax.ContentHandler getSerializer(java.io.OutputStream out)
throws org.xml.sax.SAXException
out - The destination for the XML output.
org.xml.sax.SAXException - if an error occurs while creating the serializer.
public static org.xml.sax.ContentHandler getSerializer(java.io.OutputStream out,
java.util.Properties props)
throws org.xml.sax.SAXException
out - The destination for the XML output.props - The output formatting properties.
org.xml.sax.SAXException - if an error occurs while creating the serializer.
public static org.xml.sax.ContentHandler getSerializer(javax.xml.transform.Result result,
java.util.Properties props)
throws org.xml.sax.SAXException
result - The destination for the XML output.props - The output formatting properties.
org.xml.sax.SAXException - if an error occurs while creating the serializer.
public static void fromXML(org.xml.sax.InputSource saxIn,
boolean validate,
org.xml.sax.helpers.DefaultHandler handler)
throws org.xml.sax.SAXException
saxIn - The SAX InputSource to the XML document.validate - A boolean flag that governs whether the parser
validates the document against its DTD or schema.handler - The SAX ContentHandler to send SAX2 events to.
org.xml.sax.SAXException - if the document is not well-formed.
public static void applySAXExtensions(org.xml.sax.XMLReader xmlReader,
org.xml.sax.ContentHandler handler)
xmlReader - The XMLReader to apply the extensions to.handler - The object that possibly implements the SAX extension
interfaces.
public void startDocument()
throws org.xml.sax.SAXException
startDocument in interface org.xml.sax.ContentHandlerstartDocument in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException - if an error occurs while initializing.
public void endDocument()
throws org.xml.sax.SAXException
endDocument in interface org.xml.sax.ContentHandlerendDocument in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException - if an error occurs while resetting.
public void startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
throws org.xml.sax.SAXException
startElement in interface org.xml.sax.ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXExceptionpublic static java.lang.String toAttrString(org.xml.sax.Attributes attrs)
public void endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
throws org.xml.sax.SAXException
endElement in interface org.xml.sax.ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXException
protected final java.lang.String getElementName(java.lang.String ns,
java.lang.String lName,
java.lang.String qName)
startElement(String, Attributes) method based
on the namespace URI, local name, and qualified name provided by
the SAX2 event generator.
ns - The namespace URI.lName - The local element name.qName - The qualified element name.
protected void startElement(java.lang.String localName,
org.xml.sax.Attributes attrs)
throws org.xml.sax.SAXException
getElementName method.
localName - The local element name, as determined by the
getElementName method.attrs - The element attributes.
org.xml.sax.SAXException - if the element processing encounters an error.getElementName(java.lang.String, java.lang.String, java.lang.String)
protected void startUnknownElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
throws org.xml.sax.SAXException
getElementName.
namespaceURI - The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace processing is not being
performed.localName - The local element name, as determined by the
getElementName method.qName - The qualified name (with prefix), or the empty string
if qualified names are not available.attrs - The element attributes.
org.xml.sax.SAXException - if the element processing encounters an error.getElementName(java.lang.String, java.lang.String, java.lang.String)
protected void endElement(java.lang.String localName)
throws org.xml.sax.SAXException
getElementName method.
localName - The local element name, as determined by the
getElementName method.
org.xml.sax.SAXException - if the element processing encounters an error.getElementName(java.lang.String, java.lang.String, java.lang.String)
protected void endUnknownElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
throws org.xml.sax.SAXException
getElementName.
namespaceURI - The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace processing is not being
performed.localName - The local element name, as determined by the
getElementName method.qName - The qualified name (with prefix), or the empty string
if qualified names are not available.
org.xml.sax.SAXException - if the element processing encounters an error.getElementName(java.lang.String, java.lang.String, java.lang.String)
public void characters(char[] ch,
int start,
int length)
ch into an internal buffer; if an
element is interested in receiving character data, it will ensure the
internal buffer is not null. This implies that the endElement()
implementation needs to be sure to reset the charsBuf member back to
null after reading its contents.
characters in interface org.xml.sax.ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandlerch - An array of characters that are currently available to be
read from the XML stream; should be appended to an internal buffer.start - The index from which to start reading characters from
ch.length - The number of characters to extract from ch.
public void comment(char[] ch,
int start,
int length)
comment in interface org.xml.sax.ext.LexicalHandlerch - An array of characters that are currently available to be
read from the XML stream.start - The index from which to start reading characters from
ch.length - The number of characters to extract from ch.
public void startDTD(java.lang.String name,
java.lang.String pubId,
java.lang.String sysId)
startDTD in interface org.xml.sax.ext.LexicalHandlername - The document type name.pubId - The public ID of the document type.sysId - The system ID of the document type.public void endDTD()
endDTD in interface org.xml.sax.ext.LexicalHandlerpublic void startEntity(java.lang.String name)
startEntity in interface org.xml.sax.ext.LexicalHandlername - The entity name.public void endEntity(java.lang.String name)
endEntity in interface org.xml.sax.ext.LexicalHandlername - The entity name.public void startCDATA()
characters method with this no-op
implementation.
startCDATA in interface org.xml.sax.ext.LexicalHandlerpublic void endCDATA()
endCDATA in interface org.xml.sax.ext.LexicalHandler
public void error(org.xml.sax.SAXParseException spe)
throws org.xml.sax.SAXException
error in interface org.xml.sax.ErrorHandlererror in class org.xml.sax.helpers.DefaultHandlerspe - The error information encapsulated in a SAXParseException
org.xml.sax.SAXException - Any SAX exception, possible wrapping another
exception.
public void fatalError(org.xml.sax.SAXParseException spe)
throws org.xml.sax.SAXException
fatalError in interface org.xml.sax.ErrorHandlerfatalError in class org.xml.sax.helpers.DefaultHandlerspe - The error information encapsulated in a SAXParseException
org.xml.sax.SAXException - Any SAX exception, possible wrapping another
exception.public void warning(org.xml.sax.SAXParseException spe)
warning in interface org.xml.sax.ErrorHandlerwarning in class org.xml.sax.helpers.DefaultHandlerspe - The warning information encapsulated in a SAXParseExceptionprotected java.lang.Object[] getParamsFromSAXException(org.xml.sax.SAXParseException spe)
spe - The error information encapsulated in a SAXParseException
protected java.lang.String getElementPath()
elementNameStack in its processing.
public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
java.lang.String systemId)
systemId is used to locate the DTD. This
method supports two approaches to reading the DTD: 1) a well-formed
URL with a supported protocol handler, such as HTTP or file; or 2)
"http://www.xerceo.com/dtd/xmmb_1_0.dtd", which is a resource
path accessible to this class' ClassLoader.
resolveEntity in interface org.xml.sax.EntityResolverresolveEntity in class org.xml.sax.helpers.DefaultHandlerpublicId - A well-known directory; not used by this
implementation.systemId - A URL to the external entity.
systemId; null otherwise. This method logs any exceptions
or error conditions and does not generate an exception in the event that
the entity is not accessible.protected java.io.InputStream openSystemIdStream(java.lang.String systemId)
InputStream to the supplied
systemId.
systemId - A URL to the entity.
protected java.io.InputStream openURLStream(java.lang.String systemId)
InputStream to the supplied URL.
systemId - A URL to the entity.
protected void handleVersionStart(org.xml.sax.Attributes attrs)
throws org.xml.sax.SAXException
attrs - The SAX attributes container.
org.xml.sax.SAXException - if an error occurs while trying to read the
attributes and initialize a version object.
protected void handleVersionEnd()
throws org.xml.sax.SAXException
org.xml.sax.SAXException - if an error occurs.protected java.lang.String getChars()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||