Package org.eclipse.rdf4j.rio.rdfxml
Class SAXFilter
java.lang.Object
org.eclipse.rdf4j.rio.rdfxml.SAXFilter
- All Implemented Interfaces:
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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringBuilder
StringBuilder used to collect text during parsing.private SAXFilter.ElementInfo
Variable used to defer reporting of start tags.private ParsedIRI
The document's URI.private final Stack
<SAXFilter.ElementInfo> Stack of ElementInfo objects.private boolean
Flag indicating whether we're currently parsing RDF elements.private Locator
A Locator indicating a position in the text that is currently being parsed by the SAX parser.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
Flag indicating whether we're currently parsing an XML literal.private boolean
Flag indicating whether the parser parses stand-alone RDF documents.private int
The number of elements on the stack that are in the RDF context.private final RDFXMLParser
The RDF parser to supply the filtered SAX events to.The prefixes that were used in an XML literal, but that were not defined in it (but rather in the XML literal's context).The prefixes that are defined in the XML literal itself (this in contrast to the namespaces from the XML literal's context).private int
The number of elements on the stack that are part of an XML literal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
appendAttribute
(StringBuilder sb, String name, String value) private void
appendEndTag
(String qName) Appends an end tag to charBuf.private void
appendNamespaceDecl
(StringBuilder sb, String prefix, String namespace) private void
appendStartTag
(String qName, Attributes attributes) Appends a start tag to charBuf.void
characters
(char[] ch, int start, int length) private void
checkAndCopyAttributes
(Attributes attributes, SAXFilter.ElementInfo elInfo) void
clear()
private ParsedIRI
createBaseURI
(String uriString) void
void
endElement
(String namespaceURI, String localName, String qName) void
endPrefixMapping
(String prefix) boolean
void
ignorableWhitespace
(char[] ch, int start, int length) private void
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
void
processingInstruction
(String target, String data) private void
void
void
setDocumentURI
(String documentURI) void
void
setParseStandAloneDocuments
(boolean standAloneDocs) void
skippedEntity
(String name) void
void
startElement
(String namespaceURI, String localName, String qName, Attributes attributes) void
startPrefixMapping
(String prefix, String uri)
-
Field Details
-
rdfParser
The RDF parser to supply the filtered SAX events to. -
locator
A Locator indicating a position in the text that is currently being parsed by the SAX parser. -
elInfoStack
Stack of ElementInfo objects. -
charBuf
StringBuilder used to collect text during parsing. -
documentURI
The document's URI. -
parseStandAloneDocuments
private boolean parseStandAloneDocumentsFlag 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
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
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 inRDFContextFlag indicating whether we're currently parsing RDF elements. -
rdfContextStackHeight
private int rdfContextStackHeightThe number of elements on the stack that are in the RDF context. -
parseLiteralMode
private boolean parseLiteralModeFlag indicating whether we're currently parsing an XML literal. -
xmlLiteralStackHeight
private int xmlLiteralStackHeightThe number of elements on the stack that are part of an XML literal. -
xmlLiteralPrefixes
The prefixes that are defined in the XML literal itself (this in contrast to the namespaces from the XML literal's context). -
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 Details
-
SAXFilter
-
-
Method Details
-
getLocator
-
clear
public void clear() -
setDocumentURI
-
setParseStandAloneDocuments
public void setParseStandAloneDocuments(boolean standAloneDocs) -
getParseStandAloneDocuments
public boolean getParseStandAloneDocuments() -
setDocumentLocator
- Specified by:
setDocumentLocator
in interfaceContentHandler
-
startDocument
- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
-
endDocument
- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
-
startPrefixMapping
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
endPrefixMapping
- Specified by:
endPrefixMapping
in interfaceContentHandler
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Throws:
SAXException
-
reportDeferredStartElement
- Throws:
RDFParseException
RDFHandlerException
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Throws:
SAXException
-
characters
- Specified by:
characters
in interfaceContentHandler
- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) - Specified by:
ignorableWhitespace
in interfaceContentHandler
-
processingInstruction
- Specified by:
processingInstruction
in interfaceContentHandler
-
skippedEntity
- Specified by:
skippedEntity
in interfaceContentHandler
-
checkAndCopyAttributes
private void checkAndCopyAttributes(Attributes attributes, SAXFilter.ElementInfo elInfo) throws SAXException, RDFParseException - Throws:
SAXException
RDFParseException
-
setParseLiteralMode
public void setParseLiteralMode() -
createBaseURI
-
appendStartTag
Appends a start tag to charBuf. This method is used during the parsing of an XML Literal. -
appendEndTag
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
-
appendAttribute
-
peekStack
-