net.chaosserver.bilbo.data
Class DirectoryHandler

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--net.chaosserver.bilbo.data.DirectoryHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class DirectoryHandler
extends DefaultHandler

A Sax helper customized to read in the Xml representation of a Directory object.

Since:
Bilbo 1.0

Field Summary
protected  Directory directory
          Holds the directory currently being read in.
protected  Stack directoryStack
          Stack of directories to allow for child mappings.
protected  String encoding
          Indicates type of encoding to try.
protected  FilenameMapping filenameMapping
          Holds the FilenameMapping currently being read in.
protected  Name name
          Holds the Name currently being read in.
 
Constructor Summary
DirectoryHandler()
          Default constructor.
DirectoryHandler(String encoding)
          Creates a directory handler that will generate strings in given encoding.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Called when character strings are reached.
 void endDocument()
          Destroyes the directory stack when the document is done.
 void endElement(String uri, String localName, String qName)
          Called at the end of an element.
protected  Directory getDirectory()
          Getter for the Directory object generated by this handler.
 void startDocument()
          Creates a new stack to hold the directories.
 void startElement(String uri, String localName, String qName, Attributes attributes)
          Called at the start of an element.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

directoryStack

protected Stack directoryStack
Stack of directories to allow for child mappings.


directory

protected Directory directory
Holds the directory currently being read in.


filenameMapping

protected FilenameMapping filenameMapping
Holds the FilenameMapping currently being read in.


name

protected Name name
Holds the Name currently being read in.


encoding

protected String encoding
Indicates type of encoding to try.

Constructor Detail

DirectoryHandler

public DirectoryHandler()
Default constructor. Uses "UTF-8" encoding.


DirectoryHandler

public DirectoryHandler(String encoding)
Creates a directory handler that will generate strings in given encoding.

Parameters:
encoding - the encoding to generate the String objects in.
Method Detail

startDocument

public void startDocument()
Creates a new stack to hold the directories. This is used when a mapping file contains child directories.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler

endDocument

public void endDocument()
Destroyes the directory stack when the document is done. Thus allowing the handler to be re-used.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler

getDirectory

protected Directory getDirectory()
Getter for the Directory object generated by this handler.

This method should be called after the handler has been used against an Xml document containing a directory.

Returns:
the Directory read in by the handler

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes attributes)
                  throws SAXException
Called at the start of an element. Deals with all valid open tags.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Parameters:
uri - the uri of the tag coming back
localName - the localname of the tag coming back
qName - this is the name it is processing against.
attributes - attributes associated with the open tag
Throws:
SAXException - if there is an error processing.

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Called when character strings are reached. Attempts to convert the loaded characters into the encoding scheme. If the scheme is unsupported it will leave it in the default encoding.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Parameters:
ch - the character array of the xml file
start - the start of the current sequence
length - the length of the current sequence
Throws:
SAXException - if there is an error processing.

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException
Called at the end of an element. Deals with all valid close tags.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Parameters:
uri - the uri of the tag coming back
localName - the localname of the tag coming back
qName - this is the name it is processing against.
Throws:
SAXException - if there is an error processing.


Copyright © 20030415