Top Description Inners Fields Constructors Methods
org.apache.poi.util

public final Class XMLHelper

extends Object
Class Inheritance
Annotations
@Internal
Static Imports
javax.xml.XMLConstants.ACCESS_EXTERNAL_DTD, .XMLConstants.ACCESS_EXTERNAL_SCHEMA, .XMLConstants.ACCESS_EXTERNAL_STYLESHEET, .XMLConstants.FEATURE_SECURE_PROCESSING, .XMLConstants.W3C_XML_SCHEMA_NS_URI, javax.xml.stream.XMLInputFactory.IS_NAMESPACE_AWARE, .XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, .XMLInputFactory.IS_VALIDATING, .XMLInputFactory.SUPPORT_DTD, .XMLOutputFactory.IS_REPAIRING_NAMESPACES

Helper methods for working with javax.xml classes.
See Also
OWASP XXE

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static interface
private static interface

Field Summary

Modifier and TypeField and Description
private static final DocumentBuilderFactory
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final String
private static long
private static final Logger
pack-priv static final String
pack-priv static final String
pack-priv static final String
private static final SAXParserFactory
pack-priv static final String[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static DocumentBuilderFactory
getDocumentBuilderFactory()

Creates a new DocumentBuilderFactory, with sensible defaults

public static SAXParserFactory
public static SchemaFactory
public static TransformerFactory
private static Object
private static InputSource
ignoreEntity(String publicId, String systemId)

private static void
logThrowable(Throwable t, String message, String name)

public static DocumentBuilder
newDocumentBuilder()

Creates a new document builder, with sensible defaults

public static Transformer
public static XMLEventFactory
newXMLEventFactory()

Creates a new StAX XMLEventFactory, with sensible defaults

public static XMLInputFactory
newXMLInputFactory()

Creates a new StAX XMLInputFactory, with sensible defaults

public static XMLOutputFactory
newXMLOutputFactory()

Creates a new StAX XMLOutputFactory, with sensible defaults

public static XMLReader
newXMLReader()

Creates a new SAX XMLReader, with sensible defaults

private static boolean
private static boolean
trySet(XMLHelper.SecurityFeature feature, String name, boolean value)

private static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

documentBuilderFactoryback to summary
private static final DocumentBuilderFactory documentBuilderFactory
FEATURE_DISALLOW_DOCTYPE_DECLback to summary
pack-priv static final String FEATURE_DISALLOW_DOCTYPE_DECL
FEATURE_EXTERNAL_ENTITIESback to summary
pack-priv static final String FEATURE_EXTERNAL_ENTITIES
FEATURE_LOAD_DTD_GRAMMARback to summary
pack-priv static final String FEATURE_LOAD_DTD_GRAMMAR
FEATURE_LOAD_EXTERNAL_DTDback to summary
pack-priv static final String FEATURE_LOAD_EXTERNAL_DTD
FEATURE_PARAMETER_ENTITIESback to summary
pack-priv static final String FEATURE_PARAMETER_ENTITIES
lastLogback to summary
private static long lastLog
LOGback to summary
private static final Logger LOG
METHOD_ENTITY_EXPANSION_XERCESback to summary
pack-priv static final String METHOD_ENTITY_EXPANSION_XERCES
PROPERTY_ENTITY_EXPANSION_LIMITback to summary
pack-priv static final String PROPERTY_ENTITY_EXPANSION_LIMIT
PROPERTY_SECURITY_MANAGERback to summary
pack-priv static final String PROPERTY_SECURITY_MANAGER
saxFactoryback to summary
private static final SAXParserFactory saxFactory
SECURITY_MANAGERSback to summary
pack-priv static final String[] SECURITY_MANAGERS

Constructor Detail

XMLHelperback to summary
private XMLHelper()

Method Detail

getDocumentBuilderFactoryback to summary
public static DocumentBuilderFactory getDocumentBuilderFactory()

Creates a new DocumentBuilderFactory, with sensible defaults

Annotations
@SuppressWarnings:squid:S2755
getSaxParserFactoryback to summary
public static SAXParserFactory getSaxParserFactory()
Annotations
@SuppressWarnings:squid:S2755
getSchemaFactoryback to summary
public static SchemaFactory getSchemaFactory()
Annotations
@SuppressWarnings:java:S2755
getTransformerFactoryback to summary
public static TransformerFactory getTransformerFactory()
Annotations
@SuppressWarnings:squid:S4435, java:S2755
getXercesSecurityManagerback to summary
private static Object getXercesSecurityManager()
ignoreEntityback to summary
private static InputSource ignoreEntity(String publicId, String systemId)
logThrowableback to summary
private static void logThrowable(Throwable t, String message, String name)
newDocumentBuilderback to summary
public static DocumentBuilder newDocumentBuilder()

Creates a new document builder, with sensible defaults

Exceptions
IllegalStateException:
If creating the DocumentBuilder fails, e.g. due to ParserConfigurationException.
newTransformerback to summary
public static Transformer newTransformer() throws TransformerConfigurationException
newXMLEventFactoryback to summary
public static XMLEventFactory newXMLEventFactory()

Creates a new StAX XMLEventFactory, with sensible defaults

newXMLInputFactoryback to summary
public static XMLInputFactory newXMLInputFactory()

Creates a new StAX XMLInputFactory, with sensible defaults

Annotations
@SuppressWarnings:squid:S2755
newXMLOutputFactoryback to summary
public static XMLOutputFactory newXMLOutputFactory()

Creates a new StAX XMLOutputFactory, with sensible defaults

newXMLReaderback to summary
public static XMLReader newXMLReader() throws SAXException, ParserConfigurationException

Creates a new SAX XMLReader, with sensible defaults

quietSetback to summary
private static boolean quietSet(XMLHelper.SecurityProperty property, String name, Object value)
trySetback to summary
private static boolean trySet(XMLHelper.SecurityFeature feature, String name, boolean value)
Annotations
@SuppressWarnings:UnusedReturnValue
trySetback to summary
private static boolean trySet(XMLHelper.SecurityProperty property, String name, Object value)
org.apache.poi.util back to summary

private Class XMLHelper.DocHelperErrorHandler

extends Object
implements ErrorHandler
Class Inheritance
All Implemented Interfaces
org.xml.sax.ErrorHandler

Field Summary

Modifier and TypeField and Description
private final boolean

Constructor Summary

AccessConstructor and Description
public
DocHelperErrorHandler(boolean logException)

Method Summary

Modifier and TypeMethod and Description
public void
error(SAXParseException
The error information encapsulated in a SAX parse exception.
exception
)

Implements org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable error.

public void
fatalError(SAXParseException
The error information encapsulated in a SAXParseException.
exception
)

Implements org.xml.sax.ErrorHandler.fatalError.

Receive notification of a non-recoverable, fatal error.

private void
printError(Level type, SAXParseException ex)

Prints the error message.

public void
warning(SAXParseException
The warning information encapsulated in a SAX parse exception.
exception
)

Implements org.xml.sax.ErrorHandler.warning.

Receive notification of a warning.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

logExceptionback to summary
private final boolean logException

Constructor Detail

DocHelperErrorHandlerback to summary
public DocHelperErrorHandler(boolean logException)

Method Detail

errorback to summary
public void error(SAXParseException exception)

Implements org.xml.sax.ErrorHandler.error.

Doc from org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable error.

This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML recommendation does not require it to do so.

Filters may use this method to report other, non-XML errors as well.

Parameters
exception:SAXParseException

The error information encapsulated in a SAX parse exception.

fatalErrorback to summary
public void fatalError(SAXParseException exception) throws SAXException

Implements org.xml.sax.ErrorHandler.fatalError.

Doc from org.xml.sax.ErrorHandler.fatalError.

Receive notification of a non-recoverable, fatal error.

As defined in section 1.2 of the W3C XML 1.0 Recommendation, fatal errors are those that would make it impossible for a parser to continue normal processing. These include violation of a well-formedness constraint, invalid encoding, and forbidden structural errors as described in the W3C XML 1.0 Recommendation.

Parameters
exception:SAXParseException

The error information encapsulated in a SAXParseException.

Exceptions
SAXException:
if the application chooses to discontinue the parsing
printErrorback to summary
private void printError(Level type, SAXParseException ex)

Prints the error message.

warningback to summary
public void warning(SAXParseException exception)

Implements org.xml.sax.ErrorHandler.warning.

Doc from org.xml.sax.ErrorHandler.warning.

Receive notification of a warning.

SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML recommendation. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.

Filters may use this method to report other, non-XML warnings as well.

Parameters
exception:SAXParseException

The warning information encapsulated in a SAX parse exception.

org.apache.poi.util back to summary

private Interface XMLHelper.SecurityFeature

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public void
accept(String name, boolean value)

Method Detail

acceptback to summary
public void accept(String name, boolean value) throws ParserConfigurationException, SAXException, TransformerException
org.apache.poi.util back to summary

private Interface XMLHelper.SecurityProperty

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public void
accept(String name, Object value)

Method Detail

acceptback to summary
public void accept(String name, Object value) throws SAXException