Package org.apache.tika.utils
Class XMLReaderUtils
java.lang.Object
org.apache.tika.utils.XMLReaderUtils
- All Implemented Interfaces:
- Serializable
Utility functions for reading XML.
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intstatic final intDefault size for the pool of SAX Parsers and the pool of DOM builders
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic DocumentbuildDOM(InputStream is) Builds a Document with a DocumentBuilder from the poolstatic DocumentbuildDOM(InputStream is, ParseContext context) This checks context for a user specifiedDocumentBuilder.static DocumentbuildDOM(Reader reader, ParseContext context) This checks context for a user specifiedDocumentBuilder.static DocumentBuilds a Document with a DocumentBuilder from the poolstatic DocumentBuilds a Document with a DocumentBuilder from the poolstatic StringgetAttrValue(String localName, Attributes atts) static DocumentBuilderReturns the DOM builder specified in this parsing context.static DocumentBuilderFactoryReturns the DOM builder factory specified in this parsing context.static intstatic intstatic SAXParserReturns the SAX parser specified in this parsing context.static SAXParserFactoryReturns the SAX parser factory specified in this parsing context.static TransformerReturns a new transformerstatic XMLInputFactoryReturns the StAX input factory specified in this parsing context.static XMLReaderReturns the XMLReader specified in this parsing context.static voidparseSAX(InputStream is, ContentHandler contentHandler, ParseContext context) This checks context for a user specifiedSAXParser.static voidparseSAX(Reader reader, ContentHandler contentHandler, ParseContext context) This checks context for a user specifiedSAXParser.static voidsetMaxEntityExpansions(int maxEntityExpansions) Set the maximum number of entity expansions allowable in SAX/DOM/StAX parsing.static voidsetPoolSize(int poolSize) Set the pool size for cached XML parsers.
- 
Field Details- 
DEFAULT_POOL_SIZEpublic static final int DEFAULT_POOL_SIZEDefault size for the pool of SAX Parsers and the pool of DOM builders- See Also:
 
- 
DEFAULT_MAX_ENTITY_EXPANSIONSpublic static final int DEFAULT_MAX_ENTITY_EXPANSIONS- See Also:
 
 
- 
- 
Constructor Details- 
XMLReaderUtilspublic XMLReaderUtils()
 
- 
- 
Method Details- 
getXMLReaderReturns the XMLReader specified in this parsing context. If a reader is not explicitly specified, then one is created using the specified or the default SAX parser.- Returns:
- XMLReader
- Throws:
- TikaException
- Since:
- Apache Tika 1.13
- See Also:
 
- 
getSAXParserReturns the SAX parser specified in this parsing context. If a parser is not explicitly specified, then one is created using the specified or the default SAX parser factory.If you call reset() on the parser, make sure to replace the SecurityManager which will be cleared by xerces2 on reset(). - Returns:
- SAX parser
- Throws:
- TikaException- if a SAX parser could not be created
- Since:
- Apache Tika 0.8
- See Also:
 
- 
getSAXParserFactoryReturns the SAX parser factory specified in this parsing context. If a factory is not explicitly specified, then a default factory instance is created and returned. The default factory instance is configured to be namespace-aware, not validating, and to usesecure XML processing.- Returns:
- SAX parser factory
- Since:
- Apache Tika 0.8
 
- 
getDocumentBuilderFactoryReturns the DOM builder factory specified in this parsing context. If a factory is not explicitly specified, then a default factory instance is created and returned. The default factory instance is configured to be namespace-aware and to apply reasonable security features.- Returns:
- DOM parser factory
- Since:
- Apache Tika 1.13
 
- 
getDocumentBuilderReturns the DOM builder specified in this parsing context. If a builder is not explicitly specified, then a builder instance is created and returned. The builder instance is configured to apply anIGNORING_SAX_ENTITY_RESOLVER, and it sets the ErrorHandler tonull.- Returns:
- DOM Builder
- Throws:
- TikaException
- Since:
- Apache Tika 1.13
 
- 
getXMLInputFactoryReturns the StAX input factory specified in this parsing context. If a factory is not explicitly specified, then a default factory instance is created and returned. The default factory instance is configured to be namespace-aware and to apply reasonable security using theIGNORING_STAX_ENTITY_RESOLVER.- Returns:
- StAX input factory
- Since:
- Apache Tika 1.13
 
- 
getTransformerReturns a new transformerThe transformer instance is configured to to use secure XML processing.- Returns:
- Transformer
- Throws:
- TikaException- when the transformer can not be created
- Since:
- Apache Tika 1.17
 
- 
buildDOMpublic static Document buildDOM(InputStream is, ParseContext context) throws TikaException, IOException, SAXException This checks context for a user specifiedDocumentBuilder. If one is not found, this reuses a DocumentBuilder from the pool.- Parameters:
- is- InputStream to parse
- context- context to use
- Returns:
- a document
- Throws:
- TikaException
- IOException
- SAXException
- Since:
- Apache Tika 1.19
 
- 
buildDOMpublic static Document buildDOM(Reader reader, ParseContext context) throws TikaException, IOException, SAXException This checks context for a user specifiedDocumentBuilder. If one is not found, this reuses a DocumentBuilder from the pool.- Parameters:
- reader- reader (character stream) to parse
- context- context to use
- Returns:
- a document
- Throws:
- TikaException
- IOException
- SAXException
- Since:
- Apache Tika 2.5
 
- 
buildDOMBuilds a Document with a DocumentBuilder from the pool- Parameters:
- path- path to parse
- Returns:
- a document
- Throws:
- TikaException
- IOException
- SAXException
- Since:
- Apache Tika 1.19.1
 
- 
buildDOMBuilds a Document with a DocumentBuilder from the pool- Parameters:
- uriString- uriString to process
- Returns:
- a document
- Throws:
- TikaException
- IOException
- SAXException
- Since:
- Apache Tika 1.19.1
 
- 
buildDOMBuilds a Document with a DocumentBuilder from the pool- Returns:
- a document
- Throws:
- TikaException
- IOException
- SAXException
- Since:
- Apache Tika 1.19.1
 
- 
parseSAXpublic static void parseSAX(InputStream is, ContentHandler contentHandler, ParseContext context) throws TikaException, IOException, SAXException This checks context for a user specifiedSAXParser. If one is not found, this reuses a SAXParser from the pool.- Parameters:
- is- InputStream to parse
- contentHandler- handler to use; this wraps a- OfflineContentHandlerto the content handler as an extra layer of defense against external entity vulnerabilities
- context- context to use
- Throws:
- TikaException
- IOException
- SAXException
- Since:
- Apache Tika 1.19
 
- 
parseSAXpublic static void parseSAX(Reader reader, ContentHandler contentHandler, ParseContext context) throws TikaException, IOException, SAXException This checks context for a user specifiedSAXParser. If one is not found, this reuses a SAXParser from the pool.- Parameters:
- reader- reader (character stream) to parse
- contentHandler- handler to use; this wraps a- OfflineContentHandlerto the content handler as an extra layer of defense against external entity vulnerabilities
- context- context to use
- Throws:
- TikaException
- IOException
- SAXException
- Since:
- Apache Tika 2.5
 
- 
getPoolSizepublic static int getPoolSize()
- 
setPoolSizeSet the pool size for cached XML parsers. This has a side effect of locking the pool, and rebuilding the pool from scratch with the most recent settings, such asMAX_ENTITY_EXPANSIONS- Parameters:
- poolSize-
- Throws:
- TikaException
- Since:
- Apache Tika 1.19
 
- 
getMaxEntityExpansionspublic static int getMaxEntityExpansions()
- 
setMaxEntityExpansionspublic static void setMaxEntityExpansions(int maxEntityExpansions) Set the maximum number of entity expansions allowable in SAX/DOM/StAX parsing. NOTE:A value less than or equal to zero indicates no limit. This will override the system propertyJAXP_ENTITY_EXPANSION_LIMIT_KEYand theDEFAULT_MAX_ENTITY_EXPANSIONSvalue for allowable entity expansionsNOTE: To trigger a rebuild of the pool of parsers with this setting, the client must call setPoolSize(int)to rebuild the SAX and DOM parsers with this setting.- Parameters:
- maxEntityExpansions- -- maximum number of allowable entity expansions
- Since:
- Apache Tika 1.19
 
- 
getAttrValue- Parameters:
- localName-
- atts-
- Returns:
- attribute value with that local name or nullif not found
 
 
-