org.openrdf.rio.turtle
Class TurtleParser

java.lang.Object
  extended byorg.openrdf.rio.turtle.TurtleParser
All Implemented Interfaces:
Parser

public class TurtleParser
extends Object
implements Parser

Parser for Turtle files. A specification of Turtle can be found in this document. This parser is not thread-safe, therefore its public methods are synchronized.

This implementation is based on the 2006/01/02 version of the Turtle specification, with slight deviations:


Field Summary
 
Fields inherited from interface org.openrdf.rio.Parser
DT_IGNORE, DT_NORMALIZE, DT_VERIFY
 
Constructor Summary
TurtleParser()
          Creates a new TurtleParser that will use a ValueFactoryImpl to create object for resources, bNodes and literals.
TurtleParser(ValueFactory valueFactory)
          Creates a new TurtleParser that will use the supplied ValueFactory to create objects for resources, bNodes and literals.
 
Method Summary
 void parse(InputStream in, String baseURI)
          Implementation of the parse(InputStream, String) method defined in the Parser interface.
 void parse(Reader reader, String baseURI)
          Implementation of the parse(Reader, String) method defined in the Parser interface.
 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 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 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TurtleParser

public TurtleParser()
Creates a new TurtleParser that will use a ValueFactoryImpl to create object for resources, bNodes and literals.

See Also:
ValueFactoryImpl

TurtleParser

public TurtleParser(ValueFactory valueFactory)
Creates a new TurtleParser that will use the supplied ValueFactory to create objects for resources, bNodes and literals.

Parameters:
valueFactory - A ValueFactory.
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

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

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

setParseLocationListener

public void setParseLocationListener(ParseLocationListener el)
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

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

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

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

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

parse

public void parse(InputStream in,
                  String baseURI)
           throws IOException,
                  ParseException,
                  StatementHandlerException
Implementation of the parse(InputStream, String) method defined in the Parser interface.

Specified by:
parse in interface Parser
Parameters:
in - The InputStream from which to read the data. The InputStream is supposed to contain UTF-8 encoded Unicode characters, as per the Turtle specification.
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.
StatementHandler - If the configured statement handler encountered an unrecoverable error.
IllegalArgumentException - If the supplied input stream or base URI is null.
StatementHandlerException - If the configured statement handler has encountered an unrecoverable error.

parse

public void parse(Reader reader,
                  String baseURI)
           throws IOException,
                  ParseException,
                  StatementHandlerException
Implementation of the parse(Reader, String) method defined in the Parser interface.

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 Reader.
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.
StatementHandler - If the configured statement handler encountered an unrecoverable error.
IllegalArgumentException - If the supplied reader or base URI is null.
StatementHandlerException - If the configured statement handler has encountered an unrecoverable error.


Copyright © 2002-2006 Aduna BV, GNU LGPL License applies.