org.openrdf.rio.helpers
Class RDFParserBase

java.lang.Object
  extended by org.openrdf.rio.helpers.RDFParserBase
All Implemented Interfaces:
RDFParser
Direct Known Subclasses:
NTriplesParser, RDFXMLParser, TriXParser, TurtleParser

public abstract class RDFParserBase
extends Object
implements RDFParser

Base class for RDFParsers offering common functionality for RDF parsers.

Author:
Arjohn Kampman

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.openrdf.rio.RDFParser
RDFParser.DatatypeHandling
 
Field Summary
protected  RDFHandler rdfHandler
          The RDFHandler that will handle the parsed RDF.
 
Constructor Summary
RDFParserBase()
          Creates a new RDFParserBase that will use a ValueFactoryImpl to create RDF model objects.
RDFParserBase(ValueFactory valueFactory)
          Creates a new TurtleParser that will use the supplied ValueFactory to create RDF model objects.
 
Method Summary
protected  void clear()
          Clears any information that has been collected while parsing.
protected  void clearBNodeIDMap()
          Clears the map that keeps track of blank nodes that have been parsed.
protected  BNode createBNode()
          Creates a new BNode object.
protected  BNode createBNode(String nodeID)
          Creates a BNode object for the specified identifier.
protected  Literal createLiteral(String label, String lang, URI datatype)
          Creates a Literal object with the supplied parameters.
protected  Statement createStatement(Resource subj, URI pred, Value obj)
          Creates a new Statement object with the supplied components.
protected  Statement createStatement(Resource subj, URI pred, Value obj, Resource context)
          Creates a new Statement object with the supplied components.
protected  URI createURI(String uri)
          Creates a URI object for the specified URI-string.
 RDFParser.DatatypeHandling datatypeHandling()
           
protected  String getNamespace(String prefix)
          Gets the namespace that is associated with the specified prefix, if any.
 ParseErrorListener getParseErrorListener()
           
 ParseLocationListener getParseLocationListener()
           
 RDFHandler getRDFHandler()
           
 boolean preserveBNodeIDs()
           
protected  void reportError(String msg)
          Reports an error to the registered ParseErrorListener, if any.
protected  void reportError(String msg, int lineNo, int columnNo)
          Reports an error with associated line- and column number to the registered ParseErrorListener, if any.
protected  void reportFatalError(Exception e)
          Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards.
protected  void reportFatalError(Exception e, int lineNo, int columnNo)
          Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException wrapped the supplied exception afterwards.
protected  void reportFatalError(String msg)
          Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards.
protected  void reportFatalError(String msg, int lineNo, int columnNo)
          Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException afterwards.
protected  void reportLocation(int lineNo, int columnNo)
          Reports the specified line- and column number to the registered ParseLocationListener, if any.
protected  void reportWarning(String msg)
          Reports a warning to the registered ParseErrorListener, if any.
protected  void reportWarning(String msg, int lineNo, int columnNo)
          Reports a warning with associated line- and column number to the registered ParseErrorListener, if any.
protected  URI resolveURI(String uriSpec)
          Resolves a URI-string against the base URI and creates a URI object for it.
protected  void setBaseURI(ParsedURI baseURI)
          Sets the base URI for resolving relative URIs.
protected  void setBaseURI(String uriSpec)
          Parses and normalizes the supplied URI-string and sets it as the base URI for resolving relative URIs.
 void setDatatypeHandling(RDFParser.DatatypeHandling datatypeHandling)
          Sets the datatype handling mode.
protected  void setNamespace(String prefix, String namespace)
          Associates the specified prefix to the specified namespace.
 void setParseErrorListener(ParseErrorListener el)
          Sets the ParseErrorListener that will be notified of any errors that this parser finds during parsing.
 void setParseLocationListener(ParseLocationListener el)
          Sets the ParseLocationListener that will be notified of the parser's progress during the parse process.
 void setPreserveBNodeIDs(boolean preserveBNodeIDs)
          Set whether the parser should preserve bnode identifiers specified in the source (default is false).
 void setRDFHandler(RDFHandler handler)
          Sets the RDFHandler that will handle the parsed RDF data.
 void setStopAtFirstError(boolean stopAtFirstError)
          Sets whether the parser should stop immediately if it finds an error in the data (default value is true).
 void setValueFactory(ValueFactory valueFactory)
          Sets the ValueFactory that the parser will use to create Value objects for the parsed RDF data.
 void setVerifyData(boolean verifyData)
          Sets whether the parser should verify the data it parses (default value is true).
 boolean stopAtFirstError()
           
 boolean verifyData()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.openrdf.rio.RDFParser
getRDFFormat, parse, parse
 

Field Detail

rdfHandler

protected RDFHandler rdfHandler
The RDFHandler that will handle the parsed RDF.

Constructor Detail

RDFParserBase

public RDFParserBase()
Creates a new RDFParserBase that will use a ValueFactoryImpl to create RDF model objects.


RDFParserBase

public RDFParserBase(ValueFactory valueFactory)
Creates a new TurtleParser that will use the supplied ValueFactory to create RDF model objects.

Parameters:
valueFactory - A ValueFactory.
Method Detail

setValueFactory

public void setValueFactory(ValueFactory valueFactory)
Description copied from interface: RDFParser
Sets the ValueFactory that the parser will use to create Value objects for the parsed RDF data.

Specified by:
setValueFactory in interface RDFParser
Parameters:
valueFactory - The value factory that the parser should use.

setRDFHandler

public void setRDFHandler(RDFHandler handler)
Description copied from interface: RDFParser
Sets the RDFHandler that will handle the parsed RDF data.

Specified by:
setRDFHandler in interface RDFParser

getRDFHandler

public RDFHandler getRDFHandler()

setParseErrorListener

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

Specified by:
setParseErrorListener in interface RDFParser

getParseErrorListener

public ParseErrorListener getParseErrorListener()

setParseLocationListener

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

Specified by:
setParseLocationListener in interface RDFParser

getParseLocationListener

public ParseLocationListener getParseLocationListener()

setVerifyData

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

Specified by:
setVerifyData in interface RDFParser

verifyData

public boolean verifyData()

setPreserveBNodeIDs

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

Specified by:
setPreserveBNodeIDs in interface RDFParser

preserveBNodeIDs

public boolean preserveBNodeIDs()

setStopAtFirstError

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

Specified by:
setStopAtFirstError in interface RDFParser

stopAtFirstError

public boolean stopAtFirstError()

setDatatypeHandling

public void setDatatypeHandling(RDFParser.DatatypeHandling datatypeHandling)
Description copied from interface: RDFParser
Sets the datatype handling mode. There are three modes for handling datatyped literals: ignore, verifyand normalize. If set to ignore, no special action will be taken to handle datatyped literals. If set to verify, 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 RDFParser
Parameters:
datatypeHandling - A datatype handling option.

datatypeHandling

public RDFParser.DatatypeHandling datatypeHandling()

setBaseURI

protected void setBaseURI(String uriSpec)
Parses and normalizes the supplied URI-string and sets it as the base URI for resolving relative URIs.


setBaseURI

protected void setBaseURI(ParsedURI baseURI)
Sets the base URI for resolving relative URIs.


setNamespace

protected void setNamespace(String prefix,
                            String namespace)
Associates the specified prefix to the specified namespace.


getNamespace

protected String getNamespace(String prefix)
Gets the namespace that is associated with the specified prefix, if any.


clear

protected void clear()
Clears any information that has been collected while parsing. This method must be called by subclasses when finishing the parse process.


clearBNodeIDMap

protected void clearBNodeIDMap()
Clears the map that keeps track of blank nodes that have been parsed. Normally, this map is clear when the document has been parsed completely, but subclasses can clear the map at other moments too, for example when a bnode scope ends.


resolveURI

protected URI resolveURI(String uriSpec)
                  throws RDFParseException
Resolves a URI-string against the base URI and creates a URI object for it.

Throws:
RDFParseException

createURI

protected URI createURI(String uri)
                 throws RDFParseException
Creates a URI object for the specified URI-string.

Throws:
RDFParseException

createBNode

protected BNode createBNode()
                     throws RDFParseException
Creates a new BNode object.

Throws:
RDFParseException

createBNode

protected BNode createBNode(String nodeID)
                     throws RDFParseException
Creates a BNode object for the specified identifier.

Throws:
RDFParseException

createLiteral

protected Literal createLiteral(String label,
                                String lang,
                                URI datatype)
                         throws RDFParseException
Creates a Literal object with the supplied parameters.

Throws:
RDFParseException

createStatement

protected Statement createStatement(Resource subj,
                                    URI pred,
                                    Value obj)
                             throws RDFParseException
Creates a new Statement object with the supplied components.

Throws:
RDFParseException

createStatement

protected Statement createStatement(Resource subj,
                                    URI pred,
                                    Value obj,
                                    Resource context)
                             throws RDFParseException
Creates a new Statement object with the supplied components.

Throws:
RDFParseException

reportLocation

protected void reportLocation(int lineNo,
                              int columnNo)
Reports the specified line- and column number to the registered ParseLocationListener, if any.


reportWarning

protected void reportWarning(String msg)
Reports a warning to the registered ParseErrorListener, if any. This method simply calls reportWarning(String,int,int) supplying -1 for the line- and column number.


reportWarning

protected void reportWarning(String msg,
                             int lineNo,
                             int columnNo)
Reports a warning with associated line- and column number to the registered ParseErrorListener, if any.


reportError

protected void reportError(String msg)
                    throws RDFParseException
Reports an error to the registered ParseErrorListener, if any. This method simply calls reportError(String,int,int) supplying -1 for the line- and column number. This method throws a ParseException when 'stop-at-first-error' has been set to true.

Throws:
RDFParseException
See Also:
setStopAtFirstError(boolean)

reportError

protected void reportError(String msg,
                           int lineNo,
                           int columnNo)
                    throws RDFParseException
Reports an error with associated line- and column number to the registered ParseErrorListener, if any. This method throws a ParseException when 'stop-at-first-error' has been set to true.

Throws:
RDFParseException
See Also:
setStopAtFirstError(boolean)

reportFatalError

protected void reportFatalError(String msg)
                         throws RDFParseException
Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards. This method simply calls reportFatalError(String,int,int) supplying -1 for the line- and column number.

Throws:
RDFParseException

reportFatalError

protected void reportFatalError(String msg,
                                int lineNo,
                                int columnNo)
                         throws RDFParseException
Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException afterwards.

Throws:
RDFParseException

reportFatalError

protected void reportFatalError(Exception e)
                         throws RDFParseException
Reports a fatal error to the registered ParseErrorListener, if any, and throws a ParseException afterwards. An exception is made for the case where the supplied exception is a RDFParseException; in that case the supplied exception is not wrapped in another ParseException and the error message is not reported to the ParseErrorListener, assuming that it has already been reported when the original ParseException was thrown.

This method simply calls reportFatalError(Exception,int,int) supplying -1 for the line- and column number.

Throws:
RDFParseException

reportFatalError

protected void reportFatalError(Exception e,
                                int lineNo,
                                int columnNo)
                         throws RDFParseException
Reports a fatal error with associated line- and column number to the registered ParseErrorListener, if any, and throws a ParseException wrapped the supplied exception afterwards. An exception is made for the case where the supplied exception is a RDFParseException; in that case the supplied exception is not wrapped in another ParseException and the error message is not reported to the ParseErrorListener, assuming that it has already been reported when the original ParseException was thrown.

Throws:
RDFParseException


Copyright © 2001-2008 Aduna. All Rights Reserved.