com.cassinidivision.oce.content
Class XMLParser

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended bycom.cassinidivision.oce.content.XMLParser
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class XMLParser
extends DefaultHandler

This class parses content in an internal XML format from a file or string, pushing all created objects into a designated target parent.

The content objects themselves have the necessary import logic from their tag information, so this object simply acts as a stack of current content items being imported. All messages to do with parsed XML are sent to the content item on top of the stack.

The messages sent to the content objects on the stack are named identically to the parsing methods (startElement, endElement and characterData). The return values and arguments differ somewhat. The arguments are cleaned up; only local tag names are passed on, as the XML content importing does not recognise namespaces. Argument types are also rendered more WebObjects-friendly: character data is turned into a string, and attributes are turned into dictionaries.

The return values allow the content objects receiving the messages to have some control over their life on the top of the stack. When a startElement message is sent to a content object, it must return the new child if it wishes to have one put on the stack. If not, it can return null, and will remain on the top. Similarly, in endElement, the object can return true (to be removed from the stack) or false (to stay there).

The only content object which currently uses this system to customise its XML handling is C_TextContent. There are further child tags inside C_TextContent tags, but the text content object remains on top of the stack while it handles all these start/end tags and cdata blocks itself.


Constructor Summary
XMLParser()
           
 
Method Summary
 void characters(char[] ch, int start, int length)
          Called automatically while parsing; deals with character data by passing it to the top object on the stack.
 void endElement(String uri, String localName, String qName)
          Called automatically while parsing; deals with an ending tag by passing it to the top object on the stack.
 void parseXML()
          Parses the xml in the file or string provided, putting the resulting objects into the target parent.
 void setTargetParent(C_ContentContainer value)
          Sets the parent content item into which all imported items will be placed.
 void setXmlPath(String value)
          Sets the receiver to take input from a file.
 void setXmlString(String value)
          Sets the receiver to take input from a string.
 void startElement(String uri, String local, String raw, Attributes attrs)
          Called automatically while parsing; deals with a starting tag.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLParser

public XMLParser()
Method Detail

setXmlPath

public void setXmlPath(String value)
Sets the receiver to take input from a file.

Parameters:
value - the path to the input file

setXmlString

public void setXmlString(String value)
Sets the receiver to take input from a string.

Parameters:
value - the string

setTargetParent

public void setTargetParent(C_ContentContainer value)
Sets the parent content item into which all imported items will be placed.

Parameters:
value - the parent content item for the import

parseXML

public void parseXML()
Parses the xml in the file or string provided, putting the resulting objects into the target parent.


startElement

public void startElement(String uri,
                         String local,
                         String raw,
                         Attributes attrs)
Called automatically while parsing; deals with a starting tag. Passes relevant information on to the content object on top of the stack. Could result in a new object being added to the top of the stack.

See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

characters

public void characters(char[] ch,
                       int start,
                       int length)
Called automatically while parsing; deals with character data by passing it to the top object on the stack.

See Also:
ContentHandler.characters(char[], int, int)

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
Called automatically while parsing; deals with an ending tag by passing it to the top object on the stack. Could result in the top object being removed from the stack.

See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)