edu.stanford.db.xml.util
Class GenericParser

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--edu.stanford.db.xml.util.GenericParser
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler
Direct Known Subclasses:
GenericXML2RDF

public class GenericParser
extends org.xml.sax.helpers.DefaultHandler


Field Summary
protected static java.util.WeakHashMap atoms
           
protected  Element current
           
protected  ErrorHandler errorHandler
           
protected  Locator locator
           
protected  java.util.Hashtable namespaces
           
protected  int numInParent
           
protected  java.lang.String parserClass
           
protected  InputSource source
           
 
Constructor Summary
GenericParser()
           
GenericParser(boolean warn)
           
 
Method Summary
protected  void _endElement(java.lang.String uri, java.lang.String name)
           
protected  void _startElement(java.lang.String uri, java.lang.String name, Attributes al)
           
 void addError(java.lang.String sMsg)
          Generate an error message as a string
protected  void addNamespace(java.lang.String uri)
           
 void addWarning(java.lang.String sMsg)
          Generate a warning message as a string
 void characters(char[] ch, int start, int length)
          Receive notification of character data.
static java.lang.String create(java.lang.String s)
           
protected  Element createElement()
           
static QName createQName(java.lang.String ns, java.lang.String ln)
           
protected  XMLReader createXMLReader()
           
static XMLReader createXMLReader(java.lang.String className)
           
 void endElement(java.lang.String uri, java.lang.String name, java.lang.String qName)
          Receive notification of the end of an element.
protected  java.lang.String getDefaultParserClass()
           
static InputSource getInputSource(java.lang.String urlStr)
           
 java.util.Enumeration getNamespaces()
           
protected  java.lang.String getParserClass()
           
protected  java.lang.String getSourceURI()
           
protected  void initXMLParser(boolean warn)
           
protected  boolean preserveWhiteSpace()
           
 InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Allow the application to resolve external entities.
 void setErrorHandler(ErrorHandler handler)
           
 void startElement(java.lang.String uri, java.lang.String name, java.lang.String qName, Attributes atts)
          Receive notification of the beginning of an element.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errorHandler

protected ErrorHandler errorHandler

locator

protected Locator locator

source

protected InputSource source

current

protected Element current

namespaces

protected java.util.Hashtable namespaces

parserClass

protected java.lang.String parserClass

numInParent

protected int numInParent

atoms

protected static java.util.WeakHashMap atoms
Constructor Detail

GenericParser

public GenericParser()

GenericParser

public GenericParser(boolean warn)
Method Detail

resolveEntity

public InputSource resolveEntity(java.lang.String publicId,
                                 java.lang.String systemId)
                          throws SAXException
Description copied from interface: EntityResolver
Allow the application to resolve external entities.

The Parser will call this method before opening any external entity except the top-level document entity (including the external DTD subset, external entities referenced within the DTD, and external entities referenced within the document element): the application may request that the parser resolve the entity itself, that it use an alternative URI, or that it use an entirely different input source.

Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box).

If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.

Overrides:
resolveEntity in class org.xml.sax.helpers.DefaultHandler
Following copied from interface: org.xml.sax.EntityResolver
Parameters:
publicId - The public identifier of the external entity being referenced, or null if none was supplied.
systemId - The system identifier of the external entity being referenced.
Returns:
An InputSource object describing the new input source, or null to request that the parser open a regular URI connection to the system identifier.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
java.io.IOException - A Java-specific IO exception, possibly the result of creating a new InputStream or Reader for the InputSource.
See Also:
InputSource

createQName

public static QName createQName(java.lang.String ns,
                                java.lang.String ln)

create

public static java.lang.String create(java.lang.String s)

initXMLParser

protected void initXMLParser(boolean warn)

getDefaultParserClass

protected java.lang.String getDefaultParserClass()

getParserClass

protected java.lang.String getParserClass()

createXMLReader

protected XMLReader createXMLReader()

addWarning

public void addWarning(java.lang.String sMsg)
                throws SAXException
Generate a warning message as a string

addError

public void addError(java.lang.String sMsg)
              throws SAXException
Generate an error message as a string

setErrorHandler

public void setErrorHandler(ErrorHandler handler)

getSourceURI

protected java.lang.String getSourceURI()

startElement

public void startElement(java.lang.String uri,
                         java.lang.String name,
                         java.lang.String qName,
                         Attributes atts)
                  throws SAXException
Description copied from interface: ContentHandler
Receive notification of the beginning of an element.

The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.

This event allows up to three name components for each element:

  1. the Namespace URI;
  2. the local name; and
  3. the qualified (prefixed) name.

Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes properties:

Note that the attribute list provided will contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes will be omitted. The attribute list will contain attributes used for Namespace declarations (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes property is true (it is false by default, and support for a true value is optional).

Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Following copied from interface: org.xml.sax.ContentHandler
Parameters:
uri - 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 name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
atts - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String), Attributes

getNamespaces

public java.util.Enumeration getNamespaces()

addNamespace

protected void addNamespace(java.lang.String uri)

_startElement

protected void _startElement(java.lang.String uri,
                             java.lang.String name,
                             Attributes al)
                      throws SAXException

createElement

protected Element createElement()

endElement

public void endElement(java.lang.String uri,
                       java.lang.String name,
                       java.lang.String qName)
                throws SAXException
Description copied from interface: ContentHandler
Receive notification of the end of an element.

The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement event for every endElement event (even when the element is empty).

For information on the names, see startElement.

Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Following copied from interface: org.xml.sax.ContentHandler
Parameters:
uri - 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 name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified XML 1.0 name (with prefix), or the empty string if qualified names are not available.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

_endElement

protected void _endElement(java.lang.String uri,
                           java.lang.String name)
                    throws SAXException

preserveWhiteSpace

protected boolean preserveWhiteSpace()

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Description copied from interface: ContentHandler
Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so).

Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Following copied from interface: org.xml.sax.ContentHandler
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.ignorableWhitespace(char[], int, int), Locator

createXMLReader

public static XMLReader createXMLReader(java.lang.String className)

getInputSource

public static InputSource getInputSource(java.lang.String urlStr)
                                  throws java.net.MalformedURLException,
                                         java.io.IOException