Package org.restlet.ext.rdf.internal.xml
Class ContentReader
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.restlet.ext.rdf.internal.xml.ContentReader
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler
class ContentReader extends org.xml.sax.helpers.DefaultHandlerContent reader part.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContentReader.State
-
Field Summary
Fields Modifier and Type Field Description private ScopedProperty<Reference>baseThe value of the "base" URI.private static intblankNodeIdIncrement used to identify inner blank nodes.private java.lang.StringBuilderbuilderContainer for string content.private booleanconsumingContentIndicates if the string content must be consumed.private java.lang.StringcurrentDataTypeCurrent data type.private java.lang.ObjectcurrentObjectCurrent object.private ReferencecurrentPredicateCurrent predicate.private GraphHandlergraphHandlerThe graph handler to call when a link is detected.private ScopedProperty<Language>languageCurrent language.private intnodeDepthUsed to get the content of XMl literal.private java.util.Map<java.lang.String,java.lang.String>prefixesThe list of known prefixes.private booleanrdfDefaultNamespaceTrue ifRdfRepresentation#RDF_SYNTAXis the default namespace.private ReferencereifiedRefUsed when a statement must be reified.private java.util.List<ContentReader.State>statesHeap of states.private java.util.List<Reference>subjectsHeap of subjects.
-
Constructor Summary
Constructors Constructor Description ContentReader(Representation representation, GraphHandler graphHandler)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)private booleancheckRdfQName(java.lang.String localName, java.lang.String qName)Returns true if the given qualified name is in the RDF namespace and is equal to the given local name.voidendDocument()voidendElement(java.lang.String uri, java.lang.String localName, java.lang.String name)voidendPrefixMapping(java.lang.String prefix)private ContentReader.StategetCurrentState()Returns the state at the top of the heap.private ReferencegetCurrentSubject()Returns the subject at the top of the heap.private LiteralgetLiteral(java.lang.String value, java.lang.String datatype, Language language)Returns a Literal object according to the given parameters.private voidlink()A new statement has been detected with the current subject, predicate and object.private voidlink(Reference subject, Reference predicate, Reference object)Creates a statement and reify it, if necessary.private voidlink(Reference subject, Reference predicate, Literal object)Creates a statement and reify it, if necessary.private static java.lang.StringnewBlankNodeId()Returns the identifier of a new blank node.private ReferenceparseNode(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attributes)Returns the RDF URI of the given node represented by its namespace uri, local name, name, and attributes.private ContentReader.StatepopState()Returns the state at the top of the heap and removes it from the heap.private ReferencepopSubject()Returns the subject at the top of the heap and removes it from the heap.private voidpushState(ContentReader.State state)Adds a new state at the top of the heap.private voidpushSubject(Reference subject)Adds a new subject at the top of the heap.private Referenceresolve(java.lang.String value, boolean fragment)Returns the absolute reference for a given value.private Referenceresolve(java.lang.String uri, java.lang.String qName)Returns the absolute reference of a parsed element according to its URI, qualified name.voidstartDocument()voidstartElement(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attributes)voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)
-
-
-
Field Detail
-
blankNodeId
private static int blankNodeId
Increment used to identify inner blank nodes.
-
base
private ScopedProperty<Reference> base
The value of the "base" URI.
-
builder
private java.lang.StringBuilder builder
Container for string content.
-
consumingContent
private boolean consumingContent
Indicates if the string content must be consumed.
-
currentDataType
private java.lang.String currentDataType
Current data type.
-
currentObject
private java.lang.Object currentObject
Current object.
-
currentPredicate
private Reference currentPredicate
Current predicate.
-
graphHandler
private GraphHandler graphHandler
The graph handler to call when a link is detected.
-
language
private ScopedProperty<Language> language
Current language.
-
nodeDepth
private int nodeDepth
Used to get the content of XMl literal.
-
prefixes
private java.util.Map<java.lang.String,java.lang.String> prefixes
The list of known prefixes.
-
rdfDefaultNamespace
private boolean rdfDefaultNamespace
True ifRdfRepresentation#RDF_SYNTAXis the default namespace.
-
reifiedRef
private Reference reifiedRef
Used when a statement must be reified.
-
states
private java.util.List<ContentReader.State> states
Heap of states.
-
subjects
private java.util.List<Reference> subjects
Heap of subjects.
-
-
Constructor Detail
-
ContentReader
public ContentReader(Representation representation, GraphHandler graphHandler)
Constructor.- Parameters:
graphHandler- The graph handler to call when a link is detected.representation- The input representation.
-
-
Method Detail
-
newBlankNodeId
private static java.lang.String newBlankNodeId()
Returns the identifier of a new blank node.- Returns:
- The identifier of a new blank node.
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
checkRdfQName
private boolean checkRdfQName(java.lang.String localName, java.lang.String qName)Returns true if the given qualified name is in the RDF namespace and is equal to the given local name.- Parameters:
localName- The local name to compare to.qName- The qualified name
-
endDocument
public void endDocument() throws org.xml.sax.SAXException- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
endDocumentin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String name) throws org.xml.sax.SAXException- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
endElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
endPrefixMappingin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
getCurrentState
private ContentReader.State getCurrentState()
Returns the state at the top of the heap.- Returns:
- The state at the top of the heap.
-
getCurrentSubject
private Reference getCurrentSubject()
Returns the subject at the top of the heap.- Returns:
- The subject at the top of the heap.
-
getLiteral
private Literal getLiteral(java.lang.String value, java.lang.String datatype, Language language)
Returns a Literal object according to the given parameters.- Parameters:
value- The value of the literal.datatype- The datatype of the literal.language- The language of the literal.- Returns:
- A Literal object
-
link
private void link()
A new statement has been detected with the current subject, predicate and object.
-
link
private void link(Reference subject, Reference predicate, Literal object)
Creates a statement and reify it, if necessary.- Parameters:
subject- The subject of the statement.predicate- The predicate of the statement.object- The object of the statement.
-
link
private void link(Reference subject, Reference predicate, Reference object)
Creates a statement and reify it, if necessary.- Parameters:
subject- The subject of the statement.predicate- The predicate of the statement.object- The object of the statement.
-
parseNode
private Reference parseNode(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attributes)
Returns the RDF URI of the given node represented by its namespace uri, local name, name, and attributes. It also generates the available statements, thanks to some shortcuts provided by the RDF XML syntax.- Parameters:
uri-localName-name-attributes-- Returns:
- The RDF URI of the given node.
-
popState
private ContentReader.State popState()
Returns the state at the top of the heap and removes it from the heap.- Returns:
- The state at the top of the heap.
-
popSubject
private Reference popSubject()
Returns the subject at the top of the heap and removes it from the heap.- Returns:
- The subject at the top of the heap.
-
pushState
private void pushState(ContentReader.State state)
Adds a new state at the top of the heap.- Parameters:
state- The state to add.
-
pushSubject
private void pushSubject(Reference subject)
Adds a new subject at the top of the heap.- Parameters:
subject- The subject to add.
-
resolve
private Reference resolve(java.lang.String value, boolean fragment)
Returns the absolute reference for a given value. If this value is not an absolute URI, then the base URI is used.- Parameters:
value- The value.fragment- True if the value is a fragment to add to the base reference.- Returns:
- Returns the absolute reference for a given value.
-
resolve
private Reference resolve(java.lang.String uri, java.lang.String qName)
Returns the absolute reference of a parsed element according to its URI, qualified name. In case the base URI is null or empty, then an attempt is made to look for the mapped URI according to the qName.- Parameters:
uri- The base URI.qName- The qualified name of the parsed element.- Returns:
- Returns the absolute reference of a parsed element.
-
startDocument
public void startDocument() throws org.xml.sax.SAXException- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
startDocumentin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
startElement
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
startPrefixMappingin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
-