org.jrdf.parser.rdfxml
Class RdfXmlParser

java.lang.Object
  extended byorg.jrdf.parser.rdfxml.RdfXmlParser
All Implemented Interfaces:
Parser

public class RdfXmlParser
extends Object
implements Parser

A parser for XML-serialized RDF. This parser operates directly on the SAX events generated by a SAX-enabled XML parser. The XML parser should be compliant with SAX2. You should specify which SAX parser should be used by setting the org.xml.sax.driver property. This parser is not thread-safe, therefore it's public methods are synchronized.

To parse a document using this parser:

Example code:
 Graph jrdfGraph = new GraphImpl();
 Parser parser = new RdfXmlParser(jrdfGraph);
 parser.setStatementHandler(myStatementHandler);
 parser.setParseErrorListener(myParseErrorListener);
 parser.setVerifyData(true);
 parser.stopAtFirstError(false);

 // Parse the data from inputStream, resolving any
 // relative URIs against http://foo/bar:
 parser.parse(inputStream, "http://foo/bar");
 


Field Summary
 
Fields inherited from interface org.jrdf.parser.Parser
DT_IGNORE, DT_NORMALIZE, DT_VERIFY
 
Constructor Summary
RdfXmlParser(GraphElementFactory graphElementFactory)
          Creates a new RdfXmlParser that will use the supplied GraphElementFactory to create objects for resources, bNodes and literals.
RdfXmlParser(GraphElementFactory valueFactory, ParserBlankNodeFactory parserBlankNodeFactory)
          Creates a new RdfXmlParser that will use the supplied GraphElementFactory to create objects for resources, bNodes and literals.
 
Method Summary
 boolean getParseStandAloneDocuments()
          Returns whether the parser is currently in a mode to parse stand-alone RDF documents.
 void parse(InputStream in, String baseURI)
          Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.
 void parse(Reader reader, String baseURI)
          Parses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.
 void setDatatypeHandling(int datatypeHandling)
          Sets the datatype handling mode.
 void setNamespaceListener(NamespaceListener nl)
          Sets the NamespaceListener that will be notified of any namespace declarations that the parser finds during parsing.
 void setParseErrorListener(ParseErrorListener el)
          Sets the ParseErrorListener that will be notified of any errors that this parser finds during parsing.
 void setParseLocationListener(ParseLocationListener ll)
          Sets the ParseLocationListener that will be notified of the parser's progress during the parse process.
 void setParseStandAloneDocuments(boolean standAloneDocs)
          Sets the parser in a mode to parse stand-alone RDF documents.
 void setPreserveBNodeIds(boolean preserveBNodeIds)
          Set whether the parser should preserve bnode identifiers specified in the source (default is false).
 void setStatementHandler(StatementHandler sh)
          Sets the StatementHandler that will be notified of statements that are parsed by this parser.
 void setStopAtFirstError(boolean stopAtFirstError)
          Sets whether the parser should stop immediately if it finds an error in the data (default value is true).
 void setVerifyData(boolean verifyData)
          Sets whether the parser should verify the data it parses (default value is true).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RdfXmlParser

public RdfXmlParser(GraphElementFactory graphElementFactory)
             throws GraphException
Creates a new RdfXmlParser that will use the supplied GraphElementFactory to create objects for resources, bNodes and literals.

Parameters:
graphElementFactory - A GraphElementFactory.

RdfXmlParser

public RdfXmlParser(GraphElementFactory valueFactory,
                    ParserBlankNodeFactory parserBlankNodeFactory)
             throws GraphException
Creates a new RdfXmlParser that will use the supplied GraphElementFactory to create objects for resources, bNodes and literals.

Parameters:
valueFactory - A GraphElementFactory.
parserBlankNodeFactory - A ParserBlankNodeFactory.
Method Detail

setStatementHandler

public void setStatementHandler(StatementHandler sh)
Description copied from interface: Parser
Sets the StatementHandler that will be notified of statements that are parsed by this parser.

Specified by:
setStatementHandler in interface Parser
Parameters:
sh - the StatementHandler.

setParseErrorListener

public void setParseErrorListener(ParseErrorListener el)
Description copied from interface: Parser
Sets the ParseErrorListener that will be notified of any errors that this parser finds during parsing.

Specified by:
setParseErrorListener in interface Parser
Parameters:
el - the error listener.

setParseLocationListener

public void setParseLocationListener(ParseLocationListener ll)
Description copied from interface: Parser
Sets the ParseLocationListener that will be notified of the parser's progress during the parse process.

Specified by:
setParseLocationListener in interface Parser
Parameters:
ll - the parser location listener.

setNamespaceListener

public void setNamespaceListener(NamespaceListener nl)
Description copied from interface: Parser
Sets the NamespaceListener that will be notified of any namespace declarations that the parser finds during parsing.

Specified by:
setNamespaceListener in interface Parser
Parameters:
nl - the namespace listener.

setVerifyData

public void setVerifyData(boolean verifyData)
Description copied from interface: Parser
Sets whether the parser should verify the data it parses (default value is true).

Specified by:
setVerifyData in interface Parser
Parameters:
verifyData - true to verify the data parsed in.

setPreserveBNodeIds

public void setPreserveBNodeIds(boolean preserveBNodeIds)
Description copied from interface: Parser
Set whether the parser should preserve bnode identifiers specified in the source (default is false).

Specified by:
setPreserveBNodeIds in interface Parser
Parameters:
preserveBNodeIds - true to presever blank node identifier.

setStopAtFirstError

public void setStopAtFirstError(boolean stopAtFirstError)
Description copied from interface: Parser
Sets whether the parser should stop immediately if it finds an error in the data (default value is true).

Specified by:
setStopAtFirstError in interface Parser
Parameters:
stopAtFirstError - true if an error should stop parsing.

setDatatypeHandling

public void setDatatypeHandling(int datatypeHandling)
Description copied from interface: Parser
Sets the datatype handling mode. There are three modes for handling datatyped literals: ignore, verify and normalize. If set to ignore, no special action will be taken to handle datatyped literals. If set to verify (the default value), any literals with known (XML Schema built-in) datatypes are checked to see if their values are valid. If set to normalize, the literal values are not only checked, but also normalized to their canonical representation. The default value is verify.

Specified by:
setDatatypeHandling in interface Parser
Parameters:
datatypeHandling - One of the constants DT_IGNORE, DT_VERIFY or DT_NORMALIZE.
See Also:
Parser.DT_IGNORE, Parser.DT_VERIFY, Parser.DT_NORMALIZE

setParseStandAloneDocuments

public void setParseStandAloneDocuments(boolean standAloneDocs)
Sets the parser in a mode to parse stand-alone RDF documents. In stand-alone RDF documents, the enclosing rdf:RDF root element is optional if this root element contains just one element (e.g. rdf:Description.


getParseStandAloneDocuments

public boolean getParseStandAloneDocuments()
Returns whether the parser is currently in a mode to parse stand-alone RDF documents.

See Also:
setParseStandAloneDocuments(boolean)

parse

public void parse(InputStream in,
                  String baseURI)
           throws IOException,
                  ParseException,
                  StatementHandlerException
Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.

Specified by:
parse in interface Parser
Parameters:
in - The InputStream from which to read the data.
baseURI - The URI associated with the data in the InputStream.
Throws:
IOException - If an I/O error occurred while data was read from the InputStream.
ParseException - If the parser has found an unrecoverable parse error.
StatementHandlerException - If the configured statement handler encountered an unrecoverable error.
IllegalArgumentException - If the supplied input stream or base URI is null.

parse

public void parse(Reader reader,
                  String baseURI)
           throws IOException,
                  ParseException,
                  StatementHandlerException
Parses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.

Specified by:
parse in interface Parser
Parameters:
reader - The Reader from which to read the data.
baseURI - The URI associated with the data in the InputStream.
Throws:
IOException - If an I/O error occurred while data was read from the InputStream.
ParseException - If the parser has found an unrecoverable parse error.
StatementHandlerException - If the configured statement handler has encountered an unrecoverable error.
IllegalArgumentException - If the supplied reader or base URI is null.