Copyright (c) 2000-2002 ChurchillObjects.com

churchillobjects.rss4j.parser
Class RssParserImpl100

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

class RssParserImpl100
extends RssParserImpl090

Class to parse an RSS document according to the specifications of the RSS 1.0 standard. This object is created when the base parser already started parsing the document (and knows what the version number is), so it is given the document object and the known namespaces up to that point.


Field Summary
private  java.util.Hashtable imageMappings
          Maps resource strings to image objects.
protected  boolean inChannel
          Indicates that the SAX handling process is currently in a channel.
private  boolean inChannelItems
          Flag to indicate that channel items are being parsed.
private  boolean inChannelItemsSeq
          Flag to indicate that we are within the item sequence.
protected  boolean inImage
          Indicates that the SAX handling process is currently in an image.
protected  boolean inItem
          Indicates that the SAX handling process is currently in an item.
protected  boolean inTextInput
          Indicates that the SAX handling process is currently in a text input.
private  java.util.Hashtable itemMappings
          Maps resource strings to item objects.
private  java.util.Hashtable textInputMappings
          Maps resource strings to text input objects.
private  java.util.Vector unmappedImages
          A list of image resource strings that have not yet been found in the document.
private  java.util.Vector unmappedItems
          A list of item resource strings that have not yet been found in the document.
private  java.util.Vector unmappedTextInputs
          A list of text input resource strings that have not yet been found in the document.
private static java.lang.String VERSION
          Canonical version number that is handled by this parser.
 
Fields inherited from class churchillobjects.rss4j.parser.RssParser
currentChannel, currentImage, currentItem, currentTextInput, document, namespaces
 
Fields inherited from interface churchillobjects.rss4j.model.RssVersion
VERSION_10, VERSION_90, VERSION_91
 
Constructor Summary
(package private) RssParserImpl100(churchillobjects.rss4j.RssDocument document, java.util.Vector namespaces)
          Constructor for this RSS verion's parser.
 
Method Summary
private  void addChannelAttribute(java.lang.String name, java.lang.String qName)
          Adds a channel attribute value from the characters buffer.
private  void addImageAttribute(java.lang.String name, java.lang.String qName)
          Adds an image attribute value from the characters buffer.
private  void addItemAttribute(java.lang.String name, java.lang.String qName)
          Adds an item attribute value from the characters buffer.
private  void addTextInputAttribute(java.lang.String name, java.lang.String qName)
          Adds a text input attribute value from the characters buffer.
protected  void checkDublinCore()
          Validates that this document has specified Dublin Core in its header by examining the namespaces.
private  void checkForLeftovers()
          Looks for any leftover items, images or textinputs from within channels that have not been 'matched' to items, images and textinputs outside the channels.
protected  void checkSyndication()
          Validates that this document has specified Syndication in its header by examining the namespaces.
 void endDocument()
          SAX event.
 void endElement(java.lang.String uri, java.lang.String name, java.lang.String qName)
          SAX event.
protected  java.lang.String getAttributeUnqualified(java.lang.String element, java.lang.String attName, java.lang.String prefix, org.xml.sax.Attributes attrs)
          Obtains the named attribute, whether qualified or not.
protected  void handleChannel(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes attrs)
          Handles a channel element.
protected  void handleDublinCore(churchillobjects.rss4j.model.IUsesDublinCore dcobj, java.lang.String name, java.lang.String value)
          Handle items that appear to be under dublin core (qualified names sstart with "dc:").
protected  void handleImage(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes attrs)
          Handles a new image element.
protected  void handleItem(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes attrs)
          Handles an item and rdf:li element.
protected  void handleSyndication(churchillobjects.rss4j.model.IUsesSyndication synobj, java.lang.String name, java.lang.String value)
          Handle items that appear to be under syndication (qualified names sstart with "sy:").
protected  void handleTextInput(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes attrs)
          Handles a new textinput element.
 void startElement(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes attrs)
          SAX event.
 
Methods inherited from class churchillobjects.rss4j.parser.RssParser
characters, cleanUp, getAttribute, getChars, hasChars, parseRss, parseRss, parseRss, parseRss, parseRss, resetChars, startPrefixMapping
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
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

VERSION

private static final java.lang.String VERSION
Canonical version number that is handled by this parser.

See Also:
Constant Field Values

itemMappings

private java.util.Hashtable itemMappings
Maps resource strings to item objects.


imageMappings

private java.util.Hashtable imageMappings
Maps resource strings to image objects.


textInputMappings

private java.util.Hashtable textInputMappings
Maps resource strings to text input objects.


unmappedItems

private java.util.Vector unmappedItems
A list of item resource strings that have not yet been found in the document. In a correct RSS 1.0 document, this list will be emptied before the document ends.


unmappedImages

private java.util.Vector unmappedImages
A list of image resource strings that have not yet been found in the document. In a correct RSS 1.0 document, this list will be emptied before the document ends.


unmappedTextInputs

private java.util.Vector unmappedTextInputs
A list of text input resource strings that have not yet been found in the document. In a correct RSS 1.0 document, this list will be emptied before the document ends.


inChannelItems

private boolean inChannelItems
Flag to indicate that channel items are being parsed.


inChannelItemsSeq

private boolean inChannelItemsSeq
Flag to indicate that we are within the item sequence.


inChannel

protected boolean inChannel
Indicates that the SAX handling process is currently in a channel.


inItem

protected boolean inItem
Indicates that the SAX handling process is currently in an item.


inTextInput

protected boolean inTextInput
Indicates that the SAX handling process is currently in a text input.


inImage

protected boolean inImage
Indicates that the SAX handling process is currently in an image.

Constructor Detail

RssParserImpl100

RssParserImpl100(churchillobjects.rss4j.RssDocument document,
                 java.util.Vector namespaces)
Constructor for this RSS verion's parser. Provided with an already set-up document and namespace.

Parameters:
document -
namespaces -
Method Detail

startElement

public void startElement(java.lang.String uri,
                         java.lang.String name,
                         java.lang.String qName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
SAX event. Used to set flags for where the parser is in the document and to handle major parts of the RSS document object model.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class RssParserImpl090
Parameters:
uri -
name -
qName -
attrs -
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String name,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
SAX event. Used to set flags for where the parser is in the document, and to pick up characters and set them to their elements in the RSS object hierarchy.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class RssParserImpl090
Parameters:
uri -
name -
qName -
Throws:
org.xml.sax.SAXException

addTextInputAttribute

private void addTextInputAttribute(java.lang.String name,
                                   java.lang.String qName)
                            throws RssParseException
Adds a text input attribute value from the characters buffer.

Parameters:
name -
qName -
RssParseException

addItemAttribute

private void addItemAttribute(java.lang.String name,
                              java.lang.String qName)
                       throws RssParseException
Adds an item attribute value from the characters buffer.

Parameters:
name -
qName -
RssParseException

addImageAttribute

private void addImageAttribute(java.lang.String name,
                               java.lang.String qName)
                        throws RssParseException
Adds an image attribute value from the characters buffer.

Parameters:
name -
qName -
RssParseException

addChannelAttribute

private void addChannelAttribute(java.lang.String name,
                                 java.lang.String qName)
                          throws RssParseException
Adds a channel attribute value from the characters buffer.

Parameters:
name -
qName -
RssParseException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
SAX event. Performs a check for leftover images, items and textinputs that would indicate an incomplete RSS 1.0 document.

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

handleChannel

protected void handleChannel(java.lang.String uri,
                             java.lang.String name,
                             java.lang.String qName,
                             org.xml.sax.Attributes attrs)
                      throws RssParseException
Handles a channel element. Sets the current channel to a new instance and sets its uri from the about attribute.

Parameters:
uri -
name -
qName -
attrs -
RssParseException

handleItem

protected void handleItem(java.lang.String uri,
                          java.lang.String name,
                          java.lang.String qName,
                          org.xml.sax.Attributes attrs)
                   throws RssParseException
Handles an item and rdf:li element. Matches them together based on their about/resource attributes.

Parameters:
uri -
name -
qName -
attrs -
RssParseException

handleTextInput

protected void handleTextInput(java.lang.String uri,
                               java.lang.String name,
                               java.lang.String qName,
                               org.xml.sax.Attributes attrs)
                        throws RssParseException
Handles a new textinput element. Distinguishes between a textinput that occurs within a channel and one that does not. Matches them together based on their about/resource attributes.

Parameters:
uri -
name -
qName -
attrs -
RssParseException

handleImage

protected void handleImage(java.lang.String uri,
                           java.lang.String name,
                           java.lang.String qName,
                           org.xml.sax.Attributes attrs)
                    throws RssParseException
Handles a new image element. Distinguishes between an image that occurs within a channel and one that does not.

Parameters:
uri -
name -
qName -
attrs -
RssParseException

handleSyndication

protected void handleSyndication(churchillobjects.rss4j.model.IUsesSyndication synobj,
                                 java.lang.String name,
                                 java.lang.String value)
                          throws RssParseException
Handle items that appear to be under syndication (qualified names sstart with "sy:"). The syndication namespace must be present or an RssParseException will be thrown.

Parameters:
name -
value -
RssParseException

handleDublinCore

protected void handleDublinCore(churchillobjects.rss4j.model.IUsesDublinCore dcobj,
                                java.lang.String name,
                                java.lang.String value)
                         throws RssParseException
Handle items that appear to be under dublin core (qualified names sstart with "dc:"). The dublin core namespace must be present or an RssParseException will be thrown.

Parameters:
dcobj - The element that uses dublin core.
name -
value -
RssParseException

getAttributeUnqualified

protected java.lang.String getAttributeUnqualified(java.lang.String element,
                                                   java.lang.String attName,
                                                   java.lang.String prefix,
                                                   org.xml.sax.Attributes attrs)
                                            throws RssParseException
Obtains the named attribute, whether qualified or not. If the fully qualified attribute is not found but the unqualified is, then a warning is added to the document. If it is not found at all, then an RssParseException is thrown since this does not adhere to the 1.0 standard.

Parameters:
element -
attName -
prefix -
attrs -
Returns:
RssParseException

checkDublinCore

protected void checkDublinCore()
                        throws RssParseException
Validates that this document has specified Dublin Core in its header by examining the namespaces. If it is there, then the method returns normally. Otherwise, throws an RssParseException which halts processing.

RssParseException

checkSyndication

protected void checkSyndication()
                         throws RssParseException
Validates that this document has specified Syndication in its header by examining the namespaces. If it is there, then the method returns normally. Otherwise, throws an RssParseException which halts processing.

RssParseException

checkForLeftovers

private void checkForLeftovers()
                        throws RssParseException
Looks for any leftover items, images or textinputs from within channels that have not been 'matched' to items, images and textinputs outside the channels. If any are found, then a RssParseException is thrown with its resource attribute.

RssParseException

Copyright (c) 2000-2002 ChurchillObjects.com