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.ContentHandlerA 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 classSAXFilter.ElementInfo
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuildercharBufStringBuilder used to collect text during parsing.private SAXFilter.ElementInfodeferredElementVariable used to defer reporting of start tags.private ParsedIRIdocumentURIThe document's URI.private java.util.Stack<SAXFilter.ElementInfo>elInfoStackStack of ElementInfo objects.private booleaninRDFContextFlag indicating whether we're currently parsing RDF elements.private org.xml.sax.LocatorlocatorA 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>newNamespaceMappingsNew 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 booleanparseLiteralModeFlag indicating whether we're currently parsing an XML literal.private booleanparseStandAloneDocumentsFlag indicating whether the parser parses stand-alone RDF documents.private intrdfContextStackHeightThe number of elements on the stack that are in the RDF context.private RDFXMLParserrdfParserThe RDF parser to supply the filtered SAX events to.private java.util.List<java.lang.String>unknownPrefixesInXMLLiteralThe 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>xmlLiteralPrefixesThe prefixes that are defined in the XML literal itself (this in contrast to the namespaces from the XML literal's context).private intxmlLiteralStackHeightThe 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 voidappendAttribute(java.lang.StringBuilder sb, java.lang.String name, java.lang.String value)private voidappendEndTag(java.lang.String qName)Appends an end tag to charBuf.private voidappendNamespaceDecl(java.lang.StringBuilder sb, java.lang.String prefix, java.lang.String namespace)private voidappendStartTag(java.lang.String qName, org.xml.sax.Attributes attributes)Appends a start tag to charBuf.voidcharacters(char[] ch, int start, int length)private voidcheckAndCopyAttributes(org.xml.sax.Attributes attributes, SAXFilter.ElementInfo elInfo)voidclear()private ParsedIRIcreateBaseURI(java.lang.String uriString)voidendDocument()voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)voidendPrefixMapping(java.lang.String prefix)org.xml.sax.LocatorgetLocator()booleangetParseStandAloneDocuments()voidignorableWhitespace(char[] ch, int start, int length)private voidinsertUsedContextPrefixes()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.ElementInfopeekStack()voidprocessingInstruction(java.lang.String target, java.lang.String data)private voidreportDeferredStartElement()voidsetDocumentLocator(org.xml.sax.Locator loc)voidsetDocumentURI(java.lang.String documentURI)voidsetParseLiteralMode()voidsetParseStandAloneDocuments(boolean standAloneDocs)voidskippedEntity(java.lang.String name)voidstartDocument()voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)voidstartPrefixMapping(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:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler
-
startDocument
public void startDocument() throws org.xml.sax.SAXException- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXException- Specified by:
endDocumentin 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:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix)
- Specified by:
endPrefixMappingin 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:
startElementin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
reportDeferredStartElement
private void reportDeferredStartElement() throws RDFParseException, RDFHandlerException- Throws:
RDFParseExceptionRDFHandlerException
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException- Specified by:
endElementin 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:
charactersin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length)- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data)- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler
-
skippedEntity
public void skippedEntity(java.lang.String name)
- Specified by:
skippedEntityin 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.SAXExceptionRDFParseException
-
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()
-
-