Package org.eclipse.rdf4j.rio.rdfjson
Class RDFJSONParser
- java.lang.Object
-
- org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
-
- org.eclipse.rdf4j.rio.rdfjson.RDFJSONParser
-
- All Implemented Interfaces:
RDFParser
public class RDFJSONParser extends AbstractRDFParser
RDFParser
implementation for the RDF/JSON format
-
-
Field Summary
Fields Modifier and Type Field Description private RDFFormat
actualFormat
-
Fields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
rdfHandler, valueFactory
-
-
Constructor Summary
Constructors Constructor Description RDFJSONParser()
Creates a parser usingRDFFormat.RDFJSON
to identify the parser.RDFJSONParser(RDFFormat actualFormat)
Creates a parser using the given RDFFormat to self identify.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private com.fasterxml.jackson.core.JsonFactory
configureNewJsonFactory()
Get an instance of JsonFactory configured using the settings fromAbstractRDFParser.getParserConfig()
.protected Literal
createLiteral(java.lang.String label, java.lang.String language, IRI datatype, com.fasterxml.jackson.core.JsonLocation currentLocation)
Creates a literal, using the current value, language, and datatype, and additionally using the givenJsonLocation
to provide information about the line and column numbers in the event of a warning, error or exception being generated by the creation of the literal.RDFFormat
getRDFFormat()
Gets the RDF format that this parser can parse.java.util.Collection<RioSetting<?>>
getSupportedSettings()
void
parse(java.io.InputStream inputStream, java.lang.String baseUri)
Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.void
parse(java.io.Reader reader, java.lang.String baseUri)
Parses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.private void
rdfJsonToHandlerInternal(RDFHandler handler, ValueFactory vf, com.fasterxml.jackson.core.JsonParser jp)
protected void
reportError(java.lang.String msg, com.fasterxml.jackson.core.JsonLocation location, RioSetting<java.lang.Boolean> setting)
protected void
reportError(java.lang.String msg, java.lang.Exception e, com.fasterxml.jackson.core.JsonLocation location, RioSetting<java.lang.Boolean> setting)
protected void
reportFatalError(java.lang.String msg, com.fasterxml.jackson.core.JsonLocation location)
protected void
reportFatalError(java.lang.String msg, java.lang.Exception e, com.fasterxml.jackson.core.JsonLocation location)
-
Methods inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
clear, clearBNodeIDMap, createBNode, createBNode, createLiteral, createLiteral, createNode, createNode, createStatement, createStatement, createURI, getNamespace, getParseErrorListener, getParseLocationListener, getParserConfig, getRDFHandler, initializeNamespaceTableFromConfiguration, preserveBNodeIDs, reportError, reportError, reportError, reportError, reportError, reportFatalError, reportFatalError, reportFatalError, reportFatalError, reportFatalError, reportLocation, reportWarning, reportWarning, resolveURI, set, setBaseURI, setBaseURI, setNamespace, setParseErrorListener, setParseLocationListener, setParserConfig, setPreserveBNodeIDs, setRDFHandler, setValueFactory
-
-
-
-
Field Detail
-
actualFormat
private final RDFFormat actualFormat
-
-
Constructor Detail
-
RDFJSONParser
public RDFJSONParser()
Creates a parser usingRDFFormat.RDFJSON
to identify the parser.
-
RDFJSONParser
public RDFJSONParser(RDFFormat actualFormat)
Creates a parser using the given RDFFormat to self identify.- Parameters:
actualFormat
-
-
-
Method Detail
-
getRDFFormat
public RDFFormat getRDFFormat()
Description copied from interface:RDFParser
Gets the RDF format that this parser can parse.
-
parse
public void parse(java.io.InputStream inputStream, java.lang.String baseUri) throws java.io.IOException, RDFParseException, RDFHandlerException
Description copied from interface:RDFParser
Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.- Parameters:
inputStream
- The InputStream from which to read the data.baseUri
- The URI associated with the data in the InputStream. May benull
. Parsers for syntax formats that do not support relative URIs will ignore this argument.Note that if the data contains an embedded base URI, that embedded base URI will overrule the value supplied here (see RFC 3986 section 5.1 for details).
- Throws:
java.io.IOException
- If an I/O error occurred while data was read from the InputStream.RDFParseException
- If the parser has found an unrecoverable parse error.RDFHandlerException
- If the configured statement handler has encountered an unrecoverable error.
-
createLiteral
protected Literal createLiteral(java.lang.String label, java.lang.String language, IRI datatype, com.fasterxml.jackson.core.JsonLocation currentLocation) throws RDFParseException
Creates a literal, using the current value, language, and datatype, and additionally using the givenJsonLocation
to provide information about the line and column numbers in the event of a warning, error or exception being generated by the creation of the literal.- Parameters:
label
- the literal's lexical labellanguage
- the literal's language tag. Can be null.datatype
- the literal's datatype. Can be null.currentLocation
- the current JsonLocation. May not be null.- Returns:
- the created
Literal
object. - Throws:
RDFParseException
-
reportError
protected void reportError(java.lang.String msg, java.lang.Exception e, com.fasterxml.jackson.core.JsonLocation location, RioSetting<java.lang.Boolean> setting) throws RDFParseException
- Throws:
RDFParseException
-
reportError
protected void reportError(java.lang.String msg, com.fasterxml.jackson.core.JsonLocation location, RioSetting<java.lang.Boolean> setting) throws RDFParseException
- Throws:
RDFParseException
-
reportFatalError
protected void reportFatalError(java.lang.String msg, java.lang.Exception e, com.fasterxml.jackson.core.JsonLocation location) throws RDFParseException
- Throws:
RDFParseException
-
reportFatalError
protected void reportFatalError(java.lang.String msg, com.fasterxml.jackson.core.JsonLocation location) throws RDFParseException
- Throws:
RDFParseException
-
parse
public void parse(java.io.Reader reader, java.lang.String baseUri) throws java.io.IOException, RDFParseException, RDFHandlerException
Description copied from interface:RDFParser
Parses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.- Parameters:
reader
- The Reader from which to read the data.baseUri
- The URI associated with the data in the InputStream. May benull
. Parsers for syntax formats that do not support relative URIs will ignore this argument.Note that if the data contains an embedded base URI, that embedded base URI will overrule the value supplied here (see RFC 3986 section 5.1 for details).
- Throws:
java.io.IOException
- If an I/O error occurred while data was read from the InputStream.RDFParseException
- If the parser has found an unrecoverable parse error.RDFHandlerException
- If the configured statement handler has encountered an unrecoverable error.
-
rdfJsonToHandlerInternal
private void rdfJsonToHandlerInternal(RDFHandler handler, ValueFactory vf, com.fasterxml.jackson.core.JsonParser jp) throws java.io.IOException, com.fasterxml.jackson.core.JsonParseException, RDFParseException, RDFHandlerException
- Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException
RDFParseException
RDFHandlerException
-
getSupportedSettings
public java.util.Collection<RioSetting<?>> getSupportedSettings()
- Specified by:
getSupportedSettings
in interfaceRDFParser
- Overrides:
getSupportedSettings
in classAbstractRDFParser
- Returns:
- A collection of
RioSetting
s that are supported by this RDFParser.
-
configureNewJsonFactory
private com.fasterxml.jackson.core.JsonFactory configureNewJsonFactory()
Get an instance of JsonFactory configured using the settings fromAbstractRDFParser.getParserConfig()
.- Returns:
- A newly configured JsonFactory based on the currently enabled settings
-
-