com.bbn.openmap.util
Class AbstractXmlParser

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.bbn.openmap.util.AbstractXmlParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public abstract class AbstractXmlParser
extends org.xml.sax.helpers.DefaultHandler

Base class for xml parsing

Author:
rshapiro

Constructor Summary
AbstractXmlParser()
           
 
Method Summary
 void characters(char[] ch, int start, int length)
          Handle multiple callbacks per element, which will happen when the data includes xml escape sequences.
 void collectCharacters(java.lang.String expectedElement)
          Inform the parser that we want to start gathering up the character data for the current element.
 java.lang.String getCollectedCharacters(java.lang.String expectedElement)
          Get the final string accumulated from all invocations of characters(char[], int, int) since the last call to collectCharacters(java.lang.String).
 boolean parseXmlResource(java.io.File file)
          Parse an XML resource by url.
 boolean parseXmlResource(java.lang.Object resourceName, org.xml.sax.InputSource source)
          Parse from the given source.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractXmlParser

public AbstractXmlParser()
Method Detail

parseXmlResource

public boolean parseXmlResource(java.io.File file)
Parse an XML resource by url. Exceptions are logged rather than thrown. If an exception occurs the return value will be false to indicate that fact.

Parameters:
file - The file to parse.
Returns:
Whether or not the parse succeeded.

parseXmlResource

public boolean parseXmlResource(java.lang.Object resourceName,
                                org.xml.sax.InputSource source)
Parse from the given source. The source will not be closed after the parse: the caller should do this. Exceptions are logged rather than thrown. If an exception occurs the return value will be false to indicate that fact.

Parameters:
resourceName - The resource name to use in warning messages.
source - The source of the xml input.
Returns:
Whether or not the parse succeeded.

collectCharacters

public void collectCharacters(java.lang.String expectedElement)
Inform the parser that we want to start gathering up the character data for the current element. This would typically be invoked in DefaultHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) with the localName as the parameter. Use getCollectedCharacters(java.lang.String), typically in the corresponding DefaultHandler.endElement(java.lang.String, java.lang.String, java.lang.String), to retrieve the result.

Parameters:
expectedElement - The element whose character data we're gathering. Caller must pass the same element to getCollectedCharacters(java.lang.String) to ensure consistency.

getCollectedCharacters

public java.lang.String getCollectedCharacters(java.lang.String expectedElement)
Get the final string accumulated from all invocations of characters(char[], int, int) since the last call to collectCharacters(java.lang.String).

Parameters:
expectedElement - The element whose character data we're gathering. Caller must pass the same element to collectCharacters(java.lang.String) to ensure consistency.
Returns:
The String accumulated from all intervening calls to characters(char[], int, int).
Throws:
java.lang.RuntimeException - if the expectedElement doesn't match.

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Handle multiple callbacks per element, which will happen when the data includes xml escape sequences. Each escape sequence comes in its own callback.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details