Copyright (c) 2000-2002 ChurchillObjects.com

churchillobjects.rss4j.parser
Class RssParser

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--churchillobjects.rss4j.parser.RssParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, RssVersion
Direct Known Subclasses:
RssParserImpl090

public class RssParser
extends org.xml.sax.helpers.DefaultHandler
implements RssVersion

This parser is really a 'bootstrap' parser, whose only real purpose is to identify what version the RSS document is and then instantiate and pass processing along to a parser appropriate to that version. Its functionality is available to client code only through its set of public static parse methods, each of which takes a different variety of input and converts it to an InputSource for the SAX handler.


Field Summary
private  java.lang.StringBuffer characters
          Holds a buffer of characters for the current element.
protected  churchillobjects.rss4j.RssChannel currentChannel
          Holds the current channel object while the parser executes.
protected  churchillobjects.rss4j.RssChannelImage currentImage
          Holds the current image object while the parser executes.
protected  churchillobjects.rss4j.RssChannelItem currentItem
          Holds the current item object while the parser executes.
protected  churchillobjects.rss4j.RssChannelTextInput currentTextInput
          Holds the current text input object while the parser executes.
protected  churchillobjects.rss4j.RssDocument document
          The main document object to be used as the parser runs through its events.
protected  java.util.Vector namespaces
          Holds the namespaces that were found in the document.
private  org.xml.sax.XMLReader parser
          The xml reader object
 
Fields inherited from interface churchillobjects.rss4j.model.RssVersion
VERSION_10, VERSION_90, VERSION_91
 
Constructor Summary
(package private) RssParser()
          Blank constructor, used by the static parse methods before the version of the document is known.
(package private) RssParser(churchillobjects.rss4j.RssDocument document, java.util.Vector namespaces)
          In-package constructor, used by subclasses to set their already set-up document and namespace objects.
 
Method Summary
 void characters(char[] ch, int start, int length)
          SAX event.
protected  void cleanUp()
          Releases local attributes of the parser for gc
protected  java.lang.String getAttribute(org.xml.sax.Attributes attrs, java.lang.String name)
          Returns the value of the attribute if it is found in the hashmap.
protected  java.lang.String getChars()
          Returns the characters string buffer as a string, then resets it for the next element.
protected  boolean hasChars()
          Indicates that characters are available.
static churchillobjects.rss4j.RssDocument parseRss(java.io.File file)
          Invokes a parse of an RSS document made available from a file object.
(package private)  churchillobjects.rss4j.RssDocument parseRss(org.xml.sax.InputSource is)
          Starts the parsing of a document from the specified input source.
static churchillobjects.rss4j.RssDocument parseRss(java.io.InputStream is)
          Invokes a parse of an RSS document made available from an input stream.
static churchillobjects.rss4j.RssDocument parseRss(java.io.Reader r)
          Invokes a parse of an RSS document made available from a reader object.
static churchillobjects.rss4j.RssDocument parseRss(java.lang.String rss)
          Invokes a parse of an RSS document contained in a String as unicode text.
protected  void resetChars()
          Resets the characters string buffer.
 void startElement(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes atts)
          SAX event.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          SAX event.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

private org.xml.sax.XMLReader parser
The xml reader object


document

protected churchillobjects.rss4j.RssDocument document
The main document object to be used as the parser runs through its events.


currentChannel

protected churchillobjects.rss4j.RssChannel currentChannel
Holds the current channel object while the parser executes.


currentItem

protected churchillobjects.rss4j.RssChannelItem currentItem
Holds the current item object while the parser executes.


currentTextInput

protected churchillobjects.rss4j.RssChannelTextInput currentTextInput
Holds the current text input object while the parser executes.


currentImage

protected churchillobjects.rss4j.RssChannelImage currentImage
Holds the current image object while the parser executes.


characters

private java.lang.StringBuffer characters
Holds a buffer of characters for the current element.


namespaces

protected java.util.Vector namespaces
Holds the namespaces that were found in the document.

Constructor Detail

RssParser

RssParser()
Blank constructor, used by the static parse methods before the version of the document is known.


RssParser

RssParser(churchillobjects.rss4j.RssDocument document,
          java.util.Vector namespaces)
In-package constructor, used by subclasses to set their already set-up document and namespace objects.

Parameters:
document -
namespaces -
Method Detail

parseRss

public static churchillobjects.rss4j.RssDocument parseRss(java.lang.String rss)
                                                   throws RssParseException
Invokes a parse of an RSS document contained in a String as unicode text. An input source will be created from a string reader based off of that string which will be used by the xml parser.

Parameters:
rss -
Returns:
Throws:
RssParseException

parseRss

public static churchillobjects.rss4j.RssDocument parseRss(java.io.InputStream is)
                                                   throws RssParseException
Invokes a parse of an RSS document made available from an input stream. An input source will be created from the input stream which will be used by the xml parser.

Parameters:
is -
Returns:
Throws:
RssParseException

parseRss

public static churchillobjects.rss4j.RssDocument parseRss(java.io.Reader r)
                                                   throws RssParseException
Invokes a parse of an RSS document made available from a reader object. An input source will be created from the reader which will be used by the xml parser.

Parameters:
r -
Returns:
Throws:
RssParseException

parseRss

public static churchillobjects.rss4j.RssDocument parseRss(java.io.File file)
                                                   throws RssParseException
Invokes a parse of an RSS document made available from a file object. An input source will be created from in input stream off of the file which will be used by the xml parser.

Parameters:
file -
Returns:
Throws:
RssParseException

parseRss

churchillobjects.rss4j.RssDocument parseRss(org.xml.sax.InputSource is)
                                      throws RssParseException
Starts the parsing of a document from the specified input source. Through the SAX events, the RSS document object model is created and returned. If something should go wrong, then the exception is caught and thrown as an RssParseException, unless of course it is a SAXException wrapping an RssParseException, in which case the RssParseException will be unwrapped and rethrown. Either way, the client code only needs to worry about the RssParseException.

Parameters:
is - The input source to parse.
Returns:
The RssDocument object structure.
Throws:
RssParseException

cleanUp

protected void cleanUp()
Releases local attributes of the parser for gc


startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
SAX event. Signifies that a prefix mapping has been encountered. This is used to identify RSS document versions .90 and 1.0.

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Overrides:
startPrefixMapping in class org.xml.sax.helpers.DefaultHandler
Parameters:
prefix -
uri -
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String name,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
SAX event. Signifies the start of an element. This method is only used to get the version of the RSS document being parsed; subclassed events will handle the data values and add them to the RSS document object model.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Parameters:
uri -
name -
qName -
atts -
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
SAX event. Adds characters to the string buffer. This may be called several times for an element even though only a few characters are present.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Parameters:
ch -
start -
length -

getChars

protected java.lang.String getChars()
Returns the characters string buffer as a string, then resets it for the next element. This is a read-once value, then the value is gone.

Returns:

hasChars

protected boolean hasChars()
Indicates that characters are available. This is different from getChars because it does not clear the string buffer.

Returns:

resetChars

protected void resetChars()
Resets the characters string buffer. This is done after parsing an element so that tht next element gets a clean buffer to add to.


getAttribute

protected java.lang.String getAttribute(org.xml.sax.Attributes attrs,
                                        java.lang.String name)
Returns the value of the attribute if it is found in the hashmap. If not, then returns null.

Parameters:
attrs -
name -
Returns:

Copyright (c) 2000-2002 ChurchillObjects.com