Package com.itextpdf.kernel.utils
Class XmlProcessorCreator
java.lang.Object
com.itextpdf.kernel.utils.XmlProcessorCreator
Utility class for creating XML processors.
-
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentBuildercreateSafeDocumentBuilder(boolean namespaceAware, boolean ignoringComments) CreatesDocumentBuilderinstance.static TransformerCreatesTransformerinstance.static XMLReadercreateSafeXMLReader(boolean namespaceAware, boolean validating) CreatesXMLReaderinstance.static voidsetXmlParserFactory(IXmlParserFactory factory) Specifies anIXmlParserFactoryimplementation that will be used to create the xml parsers in theXmlProcessorCreator.
-
Method Details
-
setXmlParserFactory
Specifies anIXmlParserFactoryimplementation that will be used to create the xml parsers in theXmlProcessorCreator. PassDefaultSafeXmlParserFactoryto use default safe factory that should prevent XML attacks like XML bombs and XXE attacks. This will definitely throw an exception if the XXE object is present in the XML. Also it is configured to throw an exception even in case of any DTD in XML file, but this option depends on the parser implementation on your system, it may not work if your parser implementation does not support the corresponding functionality. In this case declare your ownIXmlParserFactoryimplementation and pass it to this method.- Parameters:
-
factory- factory to be used to create xml parsers. If the passed factory isnull, theDefaultSafeXmlParserFactorywill be used.
-
createSafeDocumentBuilder
public static DocumentBuilder createSafeDocumentBuilder(boolean namespaceAware, boolean ignoringComments) CreatesDocumentBuilderinstance. The default implementation is configured to prevent possible XML attacks (seeDefaultSafeXmlParserFactory). But you can usesetXmlParserFactory(com.itextpdf.kernel.utils.IXmlParserFactory)to set your specific factory for creating xml parsers.- Parameters:
-
namespaceAware- specifies whether the parser should be namespace aware -
ignoringComments- specifies whether the parser should ignore comments - Returns:
-
safe
DocumentBuilderinstance
-
createSafeXMLReader
CreatesXMLReaderinstance. The default implementation is configured to prevent possible XML attacks (seeDefaultSafeXmlParserFactory). But you can usesetXmlParserFactory(com.itextpdf.kernel.utils.IXmlParserFactory)to set your specific factory for creating xml parsers.- Parameters:
-
namespaceAware- specifies whether the parser should be namespace aware -
validating- specifies whether the parser should validate documents as they are parsed - Returns:
-
safe
XMLReaderinstance
-
createSafeTransformer
CreatesTransformerinstance. The default implementation is configured to prevent possible XML attacks (seeDefaultSafeXmlParserFactory). But you can usesetXmlParserFactory(com.itextpdf.kernel.utils.IXmlParserFactory)to set your specific factory for creating xml parsers.- Returns:
-
safe
Transformerinstance
-