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 StringBuilderStringBuilder used to collect text during parsing.private SAXFilter.ElementInfoVariable used to defer reporting of start tags.private ParsedIRIThe document's URI.private final Stack<SAXFilter.ElementInfo> Stack of ElementInfo objects.private booleanFlag indicating whether we're currently parsing RDF elements.private LocatorA 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 booleanFlag indicating whether we're currently parsing an XML literal.private booleanFlag indicating whether the parser parses stand-alone RDF documents.private intThe number of elements on the stack that are in the RDF context.private final RDFXMLParserThe 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 intThe number of elements on the stack that are part of an XML literal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendAttribute(StringBuilder sb, String name, String value) private voidappendEndTag(String qName) Appends an end tag to charBuf.private voidappendNamespaceDecl(StringBuilder sb, String prefix, String namespace) private voidappendStartTag(String qName, Attributes attributes) Appends a start tag to charBuf.voidcharacters(char[] ch, int start, int length) private voidcheckAndCopyAttributes(Attributes attributes, SAXFilter.ElementInfo elInfo) voidclear()private ParsedIRIcreateBaseURI(String uriString) voidvoidendElement(String namespaceURI, String localName, String qName) voidendPrefixMapping(String prefix) booleanvoidignorableWhitespace(char[] ch, int start, int length) private voidInserts 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.ElementInfovoidprocessingInstruction(String target, String data) private voidvoidvoidsetDocumentURI(String documentURI) voidvoidsetParseStandAloneDocuments(boolean standAloneDocs) voidskippedEntity(String name) voidvoidstartElement(String namespaceURI, String localName, String qName, Attributes attributes) voidstartPrefixMapping(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
-
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
-
unknownPrefixesInXMLLiteral
-
-
Constructor Details
-
SAXFilter
-
-
Method Details
-
getLocator
-
clear
public void clear() -
setDocumentURI
-
setParseStandAloneDocuments
public void setParseStandAloneDocuments(boolean standAloneDocs) -
getParseStandAloneDocuments
public boolean getParseStandAloneDocuments() -
setDocumentLocator
- Specified by:
setDocumentLocatorin interfaceContentHandler
-
startDocument
- Specified by:
startDocumentin interfaceContentHandler- Throws:
SAXException
-
endDocument
- Specified by:
endDocumentin interfaceContentHandler- Throws:
SAXException
-
startPrefixMapping
- Specified by:
startPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
endPrefixMapping
- Specified by:
endPrefixMappingin interfaceContentHandler
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException - Specified by:
startElementin interfaceContentHandler- Throws:
SAXException
-
reportDeferredStartElement
- Throws:
RDFParseExceptionRDFHandlerException
-
endElement
- Specified by:
endElementin interfaceContentHandler- Throws:
SAXException
-
characters
- Specified by:
charactersin interfaceContentHandler- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) - Specified by:
ignorableWhitespacein interfaceContentHandler
-
processingInstruction
- Specified by:
processingInstructionin interfaceContentHandler
-
skippedEntity
- Specified by:
skippedEntityin interfaceContentHandler
-
checkAndCopyAttributes
private void checkAndCopyAttributes(Attributes attributes, SAXFilter.ElementInfo elInfo) throws SAXException, RDFParseException - Throws:
SAXExceptionRDFParseException
-
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
-