bbc.rd.tvanytime.xml
Class SAXXMLParser

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by bbc.rd.tvanytime.xml.SAXXMLParser
All Implemented Interfaces:
MetadataSearch, XMLParser, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class SAXXMLParser
extends org.xml.sax.helpers.DefaultHandler
implements MetadataSearch, XMLParser

SAXXMLParser: Implementation of XMLParser Interface using SAX. Uses state machine to track current position in document. All TVAnytime objects that are parsed from files are added to one of the four tables (ProgramInformation, ProgamLocation, GroupInformation, SegmentInformation).

Error handling:

Version:
1.0
Author:
Tristan Ferne, BBC Research & Development, April 2002

Field Summary
static int BASIC
          Basic profile for XML parsing.
static int STANDARD
          Standard profile for XML parsing.
 
Constructor Summary
SAXXMLParser()
          Constructor creates SAX parser.
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endDocument()
          Called when parsing of document ends.
 void endElement(java.lang.String uri, java.lang.String name, java.lang.String qName)
          Called during parsing when end of element found.
 void error(org.xml.sax.SAXParseException e)
           
 java.lang.String filterPrefix(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          The appropriate way to use the element (and attribute) local and qualified names is to receive the prefix mapping trough the startPrefixMapping() method of the contentHandler and process the names as described as by D.
 ContentReferencingTable getContentReferencingTable()
          Get ContentReferencingTable used by this parser.
 java.util.Vector getGroupInformation(ContentReference crid)
          Unsupported method - always throws exception.
 GroupInformationTable getGroupInformationTable()
          Get GroupInformationTable used by this parser.
 int getParseProfile()
          Gets the XML parsing profile.
 java.util.Vector getProgramInformation(ContentReference crid)
          Get program information for the specified CRID.
 ProgramInformationTable getProgramInformationTable()
          Get ProgramInformationTable used by this parser.
 java.util.Vector getProgramLocation(ContentReference crid)
          Resolves CRID using ProgramLocation table.
 ProgramLocationTable getProgramLocationTable()
          Get ProgramLocationTable used by this parser.
 Result getResult(ContentReference crid)
          Get content referencing result for the specified CRID.
 java.util.Vector getSegmentInformation(ContentReference crid)
          Unsupported method - always throws exception.
 SegmentInformationTable getSegmentInformationTable()
          Get SegmentInformationTable used by this parser.
 ServiceInformationTable getServiceInformationTable()
          Get ServiceInformationTable used by this parser.
 void parse(java.io.File f)
          Parse the content of the file specified as TVAnytime XML.
 void parse(org.xml.sax.InputSource is)
          Parse the content of the given InputSource as TVAnytime XML.
 void parse(java.io.InputStream is)
          Parse the content of the given InputStream as TVAnytime XML.
 void parse(java.lang.String uri)
          Parse the content described by the given Universal Resource Identifier (URI).
 void setDocumentLocator(org.xml.sax.Locator locator)
          Indicates where the parser is in the document.
 void setParseProfile(int parseProfile)
          Sets the XML parsing profile.
 void setValidating(boolean validating)
          Sets whether the parser should validate the XML - SAXXMLParser does not support validation and will always throw an exception.
 void startDocument()
          Called when parsing of document starts.
 void startElement(java.lang.String uri, java.lang.String name, java.lang.String _qName, org.xml.sax.Attributes atts)
          Called during parsing when start of element found.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASIC

public static final int BASIC
Basic profile for XML parsing. Parses only the elements and attributes that are mandatory/required.

See Also:
Constant Field Values

STANDARD

public static final int STANDARD
Standard profile for XML parsing. Parses all the elements and attributes.

See Also:
Constant Field Values
Constructor Detail

SAXXMLParser

public SAXXMLParser()
             throws TVAnytimeException
Constructor creates SAX parser.

Throws:
TVAnytimeException
Method Detail

startDocument

public void startDocument()
Called when parsing of document starts.

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

endDocument

public void endDocument()
Called when parsing of document ends.

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

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
Called during parsing when start of element found. Implements state machine.

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

endElement

public void endElement(java.lang.String uri,
                       java.lang.String name,
                       java.lang.String qName)
Called during parsing when end of element found.

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

characters

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

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXParseException
Specified by:
error in interface org.xml.sax.ErrorHandler
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXParseException

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Indicates where the parser is in the document.

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

parse

public void parse(org.xml.sax.InputSource is)
           throws java.io.IOException,
                  TVAnytimeException,
                  NonFatalXMLException
Parse the content of the given InputSource as TVAnytime XML.

Specified by:
parse in interface XMLParser
Parameters:
is - The InputSource containing the content to be parsed.
Throws:
java.io.IOException - If any IO errors occur.
TVAnytimeException - If the underlying parser throws an error while parsing.
NonFatalXMLException - If the underlying parser throws a non-fatal error while parsing.

parse

public void parse(java.io.File f)
           throws java.io.IOException,
                  TVAnytimeException,
                  NonFatalXMLException
Parse the content of the file specified as TVAnytime XML.

Specified by:
parse in interface XMLParser
Parameters:
f - File containing the TVAnytime XML.
Throws:
java.io.IOException - If any IO errors occur.
TVAnytimeException - If the underlying parser throws an error while parsing.
NonFatalXMLException - If the underlying parser throws a non-fatal error while parsing.

parse

public void parse(java.io.InputStream is)
           throws java.io.IOException,
                  TVAnytimeException
Parse the content of the given InputStream as TVAnytime XML.

Specified by:
parse in interface XMLParser
Parameters:
is - The InputStream containing the content to be parsed.
Throws:
java.io.IOException - If any IO errors occur.
TVAnytimeException - If the underlying parser throws an error while parsing.

parse

public void parse(java.lang.String uri)
           throws java.io.IOException,
                  TVAnytimeException
Parse the content described by the given Universal Resource Identifier (URI).

Specified by:
parse in interface XMLParser
Parameters:
uri - The location of the content to be parsed.
Throws:
java.io.IOException - If any IO errors occur.
TVAnytimeException - If the underlying parser throws an error while parsing.

getProgramInformationTable

public ProgramInformationTable getProgramInformationTable()
Get ProgramInformationTable used by this parser.

Returns:
ProgramInformationTable used by this parser.

getSegmentInformationTable

public SegmentInformationTable getSegmentInformationTable()
Get SegmentInformationTable used by this parser.

Returns:
SegmentInformationTable used by this parser.

getGroupInformationTable

public GroupInformationTable getGroupInformationTable()
Get GroupInformationTable used by this parser.

Returns:
GroupInformationTable used by this parser.

getProgramLocationTable

public ProgramLocationTable getProgramLocationTable()
Get ProgramLocationTable used by this parser.

Returns:
ProgramLocationTable used by this parser.

getContentReferencingTable

public ContentReferencingTable getContentReferencingTable()
Get ContentReferencingTable used by this parser.

Returns:
ContentReferencingTable used by this parser.

getServiceInformationTable

public ServiceInformationTable getServiceInformationTable()
Get ServiceInformationTable used by this parser.

Returns:
ServiceInformationTable used by this parser.

setParseProfile

public void setParseProfile(int parseProfile)
Sets the XML parsing profile.

Parameters:
parseProfile - The XML parsing profile (SAXXMLParser.BASIC or SAXXMLParser.STANDARD).

getParseProfile

public int getParseProfile()
Gets the XML parsing profile.

Returns:
The XML parsing profile (SAXXMLParser.BASIC or SAXXMLParser.STANDARD).

setValidating

public void setValidating(boolean validating)
                   throws TVAnytimeException
Sets whether the parser should validate the XML - SAXXMLParser does not support validation and will always throw an exception.

Specified by:
setValidating in interface XMLParser
Parameters:
validating - Whether the parser should validate.
Throws:
TVAnytimeException - if couldn't set property.

getProgramLocation

public java.util.Vector getProgramLocation(ContentReference crid)
                                    throws SearchInterfaceNotSupportedException
Resolves CRID using ProgramLocation table.

Specified by:
getProgramLocation in interface MetadataSearch
Parameters:
crid - the CRID of the ProgramLocation object to be searched for.
Returns:
Vector containing ProgramLocation objects. Empty if none found.
Throws:
SearchInterfaceNotSupportedException - If the implementation doesn't support this function.

getProgramInformation

public java.util.Vector getProgramInformation(ContentReference crid)
                                       throws SearchInterfaceNotSupportedException
Get program information for the specified CRID.

Specified by:
getProgramInformation in interface MetadataSearch
Parameters:
crid - the CRID of the ProgramInformation object to be searched for.
Returns:
Vector containing ProgramInformation objects. Empty if none found.
Throws:
SearchInterfaceNotSupportedException - If the implementation doesn't support this function.

getResult

public Result getResult(ContentReference crid)
                 throws SearchInterfaceNotSupportedException
Get content referencing result for the specified CRID.

Parameters:
crid - the CRID of the ContentReferencing object to be searched for.
Returns:
Result object.
Throws:
SearchInterfaceNotSupportedException - If the implementation doesn't support this function.

getSegmentInformation

public java.util.Vector getSegmentInformation(ContentReference crid)
                                       throws SearchInterfaceNotSupportedException
Unsupported method - always throws exception.

Specified by:
getSegmentInformation in interface MetadataSearch
Parameters:
crid - the CRID of the SegmentInformation object to be searched for.
Returns:
Vector containing SegmentInformation objects. Empty if none found.
Throws:
SearchInterfaceNotSupportedException - If the implementation doesn't support this function.

getGroupInformation

public java.util.Vector getGroupInformation(ContentReference crid)
                                     throws SearchInterfaceNotSupportedException
Unsupported method - always throws exception.

Specified by:
getGroupInformation in interface MetadataSearch
Parameters:
crid - the CRID of the GroupInformation object to be searched for.
Returns:
Vector containing GroupInformation objects. Empty if none found.
Throws:
SearchInterfaceNotSupportedException - If the implementation doesn't support this function.

filterPrefix

public java.lang.String filterPrefix(java.lang.String uri,
                                     java.lang.String localName,
                                     java.lang.String qName)
The appropriate way to use the element (and attribute) local and qualified names is to receive the prefix mapping trough the startPrefixMapping() method of the contentHandler and process the names as described as by D. Megginson: " Code using element names would normally match first for a null URI, and if it's null then use qName otherwise use localName.".

Parameters:
uri - URI for namespace
localName - Element local name
qName - Element qualified name
Returns:
Name to use