com.samskivert.xml
Class SimpleParser

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.samskivert.xml.SimpleParser
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class SimpleParser
extends DefaultHandler

The simple parser class provides an extensible object that is intended to simplify the task of writing an object to parse a particular XML file.


Field Summary
protected  StringBuilder _chars
          The character data gathered while parsing.
 
Constructor Summary
SimpleParser()
           
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endElement(String uri, String localName, String qName)
           
protected  void finishElement(String uri, String localName, String qName, String data)
          Called when parsing an element is finished and its data is fully available.
protected  InputStream getInputStream(String path)
          Returns an input stream to read data from the given file name.
 void parseFile(String path)
          Parse the given file.
protected  int parseInt(String val)
          Parse the given string as an integer and return the integer value, or -1 if the string is malformed.
 void parseStream(InputStream stream)
          Parse the given input stream.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, 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
 

Field Detail

_chars

protected StringBuilder _chars
The character data gathered while parsing.

Constructor Detail

SimpleParser

public SimpleParser()
Method Detail

characters

public void characters(char[] ch,
                       int start,
                       int length)
Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler

parseFile

public void parseFile(String path)
               throws IOException
Parse the given file.

Parameters:
path - the full path to the file to parse.
Throws:
IOException - thrown if an error occurs while parsing the file.

parseStream

public void parseStream(InputStream stream)
                 throws IOException
Parse the given input stream.

Parameters:
stream - the input stream from which the XML source to be parsed can be loaded.
Throws:
IOException - thrown if an error occurs while parsing the stream.

finishElement

protected void finishElement(String uri,
                             String localName,
                             String qName,
                             String data)
Called when parsing an element is finished and its data is fully available. Essentially the same as endElement(java.lang.String, java.lang.String, java.lang.String) excepting that the final complete character data is provided as a parameter and is conveniently trimmed of any extraneous white space.


getInputStream

protected InputStream getInputStream(String path)
                              throws IOException
Returns an input stream to read data from the given file name.

Throws:
IOException

parseInt

protected int parseInt(String val)
Parse the given string as an integer and return the integer value, or -1 if the string is malformed.



Copyright © 2000-2008 Michael Bayne. All Rights Reserved.