Package org.eclipse.rdf4j.rio.rdfxml
Class SAXFilter
- java.lang.Object
-
- org.eclipse.rdf4j.rio.rdfxml.SAXFilter
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler
class SAXFilter extends java.lang.Object implements org.xml.sax.ContentHandler
A filter on SAX events to make life easier on the RDF parser itself. This filter does things like combining a call to startElement() that is directly followed by a call to endElement() to a single call to emptyElement().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
SAXFilter.ElementInfo
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuilder
charBuf
StringBuilder used to collect text during parsing.private SAXFilter.ElementInfo
deferredElement
Variable used to defer reporting of start tags.private ParsedIRI
documentURI
The document's URI.private java.util.Stack<SAXFilter.ElementInfo>
elInfoStack
Stack of ElementInfo objects.private boolean
inRDFContext
Flag indicating whether we're currently parsing RDF elements.private org.xml.sax.Locator
locator
A Locator indicating a position in the text that is currently being parsed by the SAX parser.private java.util.Map<java.lang.String,java.lang.String>
newNamespaceMappings
New namespace mappings that have been reported for the next start tag by the SAX parser, but that are not yet assigned to an ElementInfo object.private boolean
parseLiteralMode
Flag indicating whether we're currently parsing an XML literal.private boolean
parseStandAloneDocuments
Flag indicating whether the parser parses stand-alone RDF documents.private int
rdfContextStackHeight
The number of elements on the stack that are in the RDF context.private RDFXMLParser
rdfParser
The RDF parser to supply the filtered SAX events to.private java.util.List<java.lang.String>
unknownPrefixesInXMLLiteral
The prefixes that were used in an XML literal, but that were not defined in it (but rather in the XML literal's context).private java.util.List<java.lang.String>
xmlLiteralPrefixes
The prefixes that are defined in the XML literal itself (this in contrast to the namespaces from the XML literal's context).private int
xmlLiteralStackHeight
The number of elements on the stack that are part of an XML literal.
-
Constructor Summary
Constructors Constructor Description SAXFilter(RDFXMLParser rdfParser)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
appendAttribute(java.lang.StringBuilder sb, java.lang.String name, java.lang.String value)
private void
appendEndTag(java.lang.String qName)
Appends an end tag to charBuf.private void
appendNamespaceDecl(java.lang.StringBuilder sb, java.lang.String prefix, java.lang.String namespace)
private void
appendStartTag(java.lang.String qName, org.xml.sax.Attributes attributes)
Appends a start tag to charBuf.void
characters(char[] ch, int start, int length)
private void
checkAndCopyAttributes(org.xml.sax.Attributes attributes, SAXFilter.ElementInfo elInfo)
void
clear()
private ParsedIRI
createBaseURI(java.lang.String uriString)
void
endDocument()
void
endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
void
endPrefixMapping(java.lang.String prefix)
org.xml.sax.Locator
getLocator()
boolean
getParseStandAloneDocuments()
void
ignorableWhitespace(char[] ch, int start, int length)
private void
insertUsedContextPrefixes()
Inserts prefix mappings from an XML Literal's context for all prefixes that are used in the XML Literal and that are not defined in the XML Literal itself.private SAXFilter.ElementInfo
peekStack()
void
processingInstruction(java.lang.String target, java.lang.String data)
private void
reportDeferredStartElement()
void
setDocumentLocator(org.xml.sax.Locator loc)
void
setDocumentURI(java.lang.String documentURI)
void
setParseLiteralMode()
void
setParseStandAloneDocuments(boolean standAloneDocs)
void
skippedEntity(java.lang.String name)
void
startDocument()
void
startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
void
startPrefixMapping(java.lang.String prefix, java.lang.String uri)
-
-
-
Field Detail
-
rdfParser
private final RDFXMLParser rdfParser
The RDF parser to supply the filtered SAX events to.
-
locator
private org.xml.sax.Locator locator
A Locator indicating a position in the text that is currently being parsed by the SAX parser.
-
elInfoStack
private final java.util.Stack<SAXFilter.ElementInfo> elInfoStack
Stack of ElementInfo objects.
-
charBuf
private final java.lang.StringBuilder charBuf
StringBuilder used to collect text during parsing.
-
documentURI
private ParsedIRI documentURI
The document's URI.
-
parseStandAloneDocuments
private boolean parseStandAloneDocuments
Flag indicating whether the parser parses stand-alone RDF documents. In stand-alone documents, the rdf:RDF element is optional if it contains just one element.
-
deferredElement
private SAXFilter.ElementInfo deferredElement
Variable used to defer reporting of start tags. Reporting start tags is deferred to be able to combine a start tag and an immediately following end tag to a single call to emptyElement().
-
newNamespaceMappings
private final java.util.Map<java.lang.String,java.lang.String> newNamespaceMappings
New namespace mappings that have been reported for the next start tag by the SAX parser, but that are not yet assigned to an ElementInfo object.
-
inRDFContext
private boolean inRDFContext
Flag indicating whether we're currently parsing RDF elements.
-
rdfContextStackHeight
private int rdfContextStackHeight
The number of elements on the stack that are in the RDF context.
-
parseLiteralMode
private boolean parseLiteralMode
Flag indicating whether we're currently parsing an XML literal.
-
xmlLiteralStackHeight
private int xmlLiteralStackHeight
The number of elements on the stack that are part of an XML literal.
-
xmlLiteralPrefixes
private final java.util.List<java.lang.String> xmlLiteralPrefixes
The prefixes that are defined in the XML literal itself (this in contrast to the namespaces from the XML literal's context).
-
unknownPrefixesInXMLLiteral
private final java.util.List<java.lang.String> unknownPrefixesInXMLLiteral
The prefixes that were used in an XML literal, but that were not defined in it (but rather in the XML literal's context).
-
-
Constructor Detail
-
SAXFilter
public SAXFilter(RDFXMLParser rdfParser)
-
-
Method Detail
-
getLocator
public org.xml.sax.Locator getLocator()
-
clear
public void clear()
-
setDocumentURI
public void setDocumentURI(java.lang.String documentURI)
-
setParseStandAloneDocuments
public void setParseStandAloneDocuments(boolean standAloneDocs)
-
getParseStandAloneDocuments
public boolean getParseStandAloneDocuments()
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator loc)
- Specified by:
setDocumentLocator
in interfaceorg.xml.sax.ContentHandler
-
startDocument
public void startDocument() throws org.xml.sax.SAXException
- Specified by:
startDocument
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXException
- Specified by:
endDocument
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException
- Specified by:
startPrefixMapping
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix)
- Specified by:
endPrefixMapping
in interfaceorg.xml.sax.ContentHandler
-
startElement
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
- Specified by:
startElement
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
reportDeferredStartElement
private void reportDeferredStartElement() throws RDFParseException, RDFHandlerException
- Throws:
RDFParseException
RDFHandlerException
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
- Specified by:
endElement
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
- Specified by:
characters
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length)
- Specified by:
ignorableWhitespace
in interfaceorg.xml.sax.ContentHandler
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data)
- Specified by:
processingInstruction
in interfaceorg.xml.sax.ContentHandler
-
skippedEntity
public void skippedEntity(java.lang.String name)
- Specified by:
skippedEntity
in interfaceorg.xml.sax.ContentHandler
-
checkAndCopyAttributes
private void checkAndCopyAttributes(org.xml.sax.Attributes attributes, SAXFilter.ElementInfo elInfo) throws org.xml.sax.SAXException, RDFParseException
- Throws:
org.xml.sax.SAXException
RDFParseException
-
setParseLiteralMode
public void setParseLiteralMode()
-
createBaseURI
private ParsedIRI createBaseURI(java.lang.String uriString)
-
appendStartTag
private void appendStartTag(java.lang.String qName, org.xml.sax.Attributes attributes)
Appends a start tag to charBuf. This method is used during the parsing of an XML Literal.
-
appendEndTag
private void appendEndTag(java.lang.String qName)
Appends an end tag to charBuf. This method is used during the parsing of an XML Literal.
-
insertUsedContextPrefixes
private void insertUsedContextPrefixes()
Inserts prefix mappings from an XML Literal's context for all prefixes that are used in the XML Literal and that are not defined in the XML Literal itself.
-
appendNamespaceDecl
private void appendNamespaceDecl(java.lang.StringBuilder sb, java.lang.String prefix, java.lang.String namespace)
-
appendAttribute
private void appendAttribute(java.lang.StringBuilder sb, java.lang.String name, java.lang.String value)
-
peekStack
private SAXFilter.ElementInfo peekStack()
-
-