Search in sources :

Example 6 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project tika by apache.

the class ParseContext method getSAXParserFactory.

/**
     * Returns 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 use
     * {@link XMLConstants#FEATURE_SECURE_PROCESSING secure XML processing}.
     *
     * @since Apache Tika 0.8
     * @return SAX parser factory
     */
public SAXParserFactory getSAXParserFactory() {
    SAXParserFactory factory = get(SAXParserFactory.class);
    if (factory == null) {
        factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(false);
        try {
            factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        } catch (ParserConfigurationException e) {
        } catch (SAXNotSupportedException e) {
        } catch (SAXNotRecognizedException e) {
        // TIKA-271: Some XML parsers do not support the
        // secure-processing feature, even though it's required by
        // JAXP in Java 5. Ignoring the exception is fine here, as
        // deployments without this feature are inherently vulnerable
        // to XML denial-of-service attacks.
        }
    }
    return factory;
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 7 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project pentaho-platform by pentaho.

the class ExportManifest method fromXml.

public static ExportManifest fromXml(ByteArrayInputStream input) throws JAXBException {
    SAXParserFactory secureSAXParserFactory;
    try {
        secureSAXParserFactory = XMLParserFactoryProducer.createSecureSAXParserFactory();
    } catch (SAXNotSupportedException | SAXNotRecognizedException | ParserConfigurationException ex) {
        throw new JAXBException(ex);
    }
    XMLReader xmlReader;
    try {
        xmlReader = secureSAXParserFactory.newSAXParser().getXMLReader();
        xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
    } catch (SAXException | ParserConfigurationException ex) {
        throw new JAXBException(ex);
    }
    Source xmlSource = new SAXSource(xmlReader, new InputSource(input));
    JAXBContext jc = JAXBContext.newInstance("org.pentaho.platform.plugin.services.importexport.exportManifest.bindings");
    Unmarshaller u = jc.createUnmarshaller();
    try {
        JAXBElement<ExportManifestDto> o = (JAXBElement) (u.unmarshal(xmlSource));
        ExportManifestDto exportManifestDto = o.getValue();
        ExportManifest exportManifest = new ExportManifest(exportManifestDto);
        return exportManifest;
    } catch (Exception e) {
        System.out.println(e.toString());
        return null;
    }
}
Also used : InputSource(org.xml.sax.InputSource) JAXBException(javax.xml.bind.JAXBException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) JAXBException(javax.xml.bind.JAXBException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXSource(javax.xml.transform.sax.SAXSource) ExportManifestDto(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestDto) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Unmarshaller(javax.xml.bind.Unmarshaller) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 8 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project pentaho-platform by pentaho.

the class MimeTypeListFactory method fromXml.

private ImportHandlerMimeTypeDefinitionsDto fromXml(FileInputStream input) throws JAXBException {
    SAXParserFactory secureSAXParserFactory;
    try {
        secureSAXParserFactory = XMLParserFactoryProducer.createSecureSAXParserFactory();
    } catch (SAXNotSupportedException | SAXNotRecognizedException | ParserConfigurationException ex) {
        throw new JAXBException(ex);
    }
    XMLReader xmlReader;
    try {
        xmlReader = secureSAXParserFactory.newSAXParser().getXMLReader();
        xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
    } catch (SAXException | ParserConfigurationException ex) {
        throw new JAXBException(ex);
    }
    Source xmlSource = new SAXSource(xmlReader, new InputSource(input));
    JAXBContext jc = JAXBContext.newInstance("org.pentaho.platform.plugin.services.importer.mimeType.bindings");
    Unmarshaller u = jc.createUnmarshaller();
    JAXBElement<ImportHandlerMimeTypeDefinitionsDto> o = (JAXBElement) (u.unmarshal(xmlSource));
    ImportHandlerMimeTypeDefinitionsDto mimeTypeDefinitions = o.getValue();
    return mimeTypeDefinitions;
}
Also used : InputSource(org.xml.sax.InputSource) JAXBException(javax.xml.bind.JAXBException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) JAXBContext(javax.xml.bind.JAXBContext) ImportHandlerMimeTypeDefinitionsDto(org.pentaho.platform.plugin.services.importer.mimeType.bindings.ImportHandlerMimeTypeDefinitionsDto) JAXBElement(javax.xml.bind.JAXBElement) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) SAXException(org.xml.sax.SAXException) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXSource(javax.xml.transform.sax.SAXSource) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Unmarshaller(javax.xml.bind.Unmarshaller) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 9 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project fabric8 by jboss-fuse.

the class XmlNamespaceFinder method createParser.

protected final SAXParser createParser(SAXParserFactory parserFactory) throws ParserConfigurationException, SAXException {
    parserFactory.setNamespaceAware(true);
    final SAXParser parser = parserFactory.newSAXParser();
    final XMLReader reader = parser.getXMLReader();
    // disable DTD validation (bug 63625)
    try {
        // be sure validation is "off" or the feature to ignore DTD's will not apply
        // $NON-NLS-1$
        reader.setFeature("http://xml.org/sax/features/validation", false);
        // $NON-NLS-1$
        reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    } catch (SAXNotRecognizedException e) {
    // not a big deal if the parser does not recognize the features
    } catch (SAXNotSupportedException e) {
    // not a big deal if the parser does not support the features
    }
    return parser;
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) XMLReader(org.xml.sax.XMLReader)

Example 10 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project liferay-ide by liferay.

the class StructuresHandler method createParser.

private final SAXParser createParser(SAXParserFactory parserFactory) throws ParserConfigurationException, SAXException, SAXNotRecognizedException, SAXNotSupportedException {
    // Initialize the parser.
    final SAXParser parser = parserFactory.newSAXParser();
    final XMLReader reader = parser.getXMLReader();
    // disable DTD validation
    try {
        // be sure validation is "off" or the feature to ignore DTD's will not apply
        // $NON-NLS-1$
        reader.setFeature("http://xml.org/sax/features/validation", false);
        // $NON-NLS-1$
        reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    } catch (SAXNotRecognizedException e) {
    // not a big deal if the parser does not recognize the features
    } catch (SAXNotSupportedException e) {
    // not a big deal if the parser does not support the features
    }
    return parser;
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) XMLReader(org.xml.sax.XMLReader)

Aggregations

SAXNotSupportedException (org.xml.sax.SAXNotSupportedException)33 SAXNotRecognizedException (org.xml.sax.SAXNotRecognizedException)25 XMLReader (org.xml.sax.XMLReader)16 SAXException (org.xml.sax.SAXException)13 SAXParser (javax.xml.parsers.SAXParser)9 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 SAXParserFactory (javax.xml.parsers.SAXParserFactory)8 InputSource (org.xml.sax.InputSource)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 SAXSource (javax.xml.transform.sax.SAXSource)4 BufferedInputStream (java.io.BufferedInputStream)3 Reader (java.io.Reader)2 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 Source (javax.xml.transform.Source)2 Transformer (javax.xml.transform.Transformer)2 DOMSource (javax.xml.transform.dom.DOMSource)2