public class XMLReaderUtils
extends java.lang.Object
OfflineContentHandler to guard against
XML External Entity attacks.| Modifier and Type | Field and Description |
|---|---|
private static org.xml.sax.EntityResolver |
IGNORING_SAX_ENTITY_RESOLVER |
private static javax.xml.stream.XMLResolver |
IGNORING_STAX_ENTITY_RESOLVER |
private static java.util.logging.Logger |
LOG |
| Constructor and Description |
|---|
XMLReaderUtils() |
| Modifier and Type | Method and Description |
|---|---|
static javax.xml.parsers.DocumentBuilder |
getDocumentBuilder()
Returns the DOM builder specified in this parsing context.
|
static javax.xml.parsers.DocumentBuilderFactory |
getDocumentBuilderFactory()
Returns the DOM builder factory specified in this parsing context.
|
static javax.xml.parsers.SAXParser |
getSAXParser()
Returns the SAX parser specified in this parsing context.
|
static javax.xml.parsers.SAXParserFactory |
getSAXParserFactory()
Returns the SAX parser factory specified in this parsing context.
|
static javax.xml.transform.Transformer |
getTransformer()
Returns a new transformer
The transformer instance is configured to to use
secure XML processing. |
static javax.xml.stream.XMLInputFactory |
getXMLInputFactory()
Returns the StAX input factory specified in this parsing context.
|
static org.xml.sax.XMLReader |
getXMLReader()
Returns the XMLReader specified in this parsing context.
|
private static void |
trySetSAXFeature(javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory,
java.lang.String feature,
boolean enabled) |
private static void |
tryToSetStaxProperty(javax.xml.stream.XMLInputFactory factory,
java.lang.String key,
boolean value) |
private static final java.util.logging.Logger LOG
private static final org.xml.sax.EntityResolver IGNORING_SAX_ENTITY_RESOLVER
private static final javax.xml.stream.XMLResolver IGNORING_STAX_ENTITY_RESOLVER
public static org.xml.sax.XMLReader getXMLReader()
throws TikaException
TikaExceptiongetSAXParser()public static javax.xml.parsers.SAXParser getSAXParser()
throws TikaException
Make sure to wrap your handler in the OfflineContentHandler to
prevent XML External Entity attacks
TikaException - if a SAX parser could not be createdgetSAXParserFactory()public static javax.xml.parsers.SAXParserFactory getSAXParserFactory()
secure XML processing.
Make sure to wrap your handler in the OfflineContentHandler to
prevent XML External Entity attacks
public static javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()
public static javax.xml.parsers.DocumentBuilder getDocumentBuilder()
throws TikaException
IGNORING_SAX_ENTITY_RESOLVER,
and it sets the ErrorHandler to null.TikaExceptionpublic static javax.xml.stream.XMLInputFactory getXMLInputFactory()
IGNORING_STAX_ENTITY_RESOLVER.private static void trySetSAXFeature(javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory,
java.lang.String feature,
boolean enabled)
private static void tryToSetStaxProperty(javax.xml.stream.XMLInputFactory factory,
java.lang.String key,
boolean value)
public static javax.xml.transform.Transformer getTransformer()
throws TikaException
secure XML processing.TikaException - when the transformer can not be created