Search in sources :

Example 1 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project che by eclipse.

the class RefactoringSessionReader method createParser.

/**
	 * Creates a new parser from the specified factory.
	 *
	 * @param factory
	 *            the parser factoring to use
	 * @return the created parser
	 * @throws ParserConfigurationException
	 *             if no parser is available with the given configuration
	 * @throws SAXException
	 *             if an error occurs while creating the parser
	 */
private SAXParser createParser(final SAXParserFactory factory) throws ParserConfigurationException, SAXException {
    final SAXParser parser = factory.newSAXParser();
    final XMLReader reader = parser.getXMLReader();
    try {
        //$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 exception) {
    // Do nothing
    } catch (SAXNotSupportedException exception) {
    // Do nothing
    }
    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 2 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project zm-mailbox by Zimbra.

the class W3cDomUtil method getDom4jSAXParserWhichUsesSecureProcessing.

public static SAXParser getDom4jSAXParserWhichUsesSecureProcessing() throws XmlParseException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setXIncludeAware(false);
    factory.setValidating(false);
    try {
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    } catch (SAXNotRecognizedException | SAXNotSupportedException | ParserConfigurationException ex) {
        ZimbraLog.misc.error("Problem setting up SAXParser which supports secure XML processing", ex);
        throw XmlParseException.PARSE_ERROR();
    }
    try {
        return factory.newSAXParser();
    } catch (ParserConfigurationException | SAXException e) {
        ZimbraLog.misc.error("Problem setting up SAXParser", e);
        throw XmlParseException.PARSE_ERROR();
    }
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 3 with SAXNotSupportedException

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

the class AbstractModelBuilder method parse.

private BeansModel parse(List<URL> osgiBeansDescriptorURLs, List<URL> beanDescriptorURLs) {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    factory.setNamespaceAware(true);
    if (osgiBeansDescriptorURLs.isEmpty()) {
        throw new IllegalArgumentException("Missing osgi-beans descriptors");
    }
    SAXParser parser;
    try {
        parser = factory.newSAXParser();
    } catch (ParserConfigurationException | SAXException e) {
        return Throw.exception(e);
    }
    OSGiBeansHandler handler = getHandler(beanDescriptorURLs);
    for (URL osgiBeansDescriptorURL : osgiBeansDescriptorURLs) {
        try (InputStream inputStream = osgiBeansDescriptorURL.openStream()) {
            InputSource source = new InputSource(inputStream);
            if (source.getByteStream().available() == 0) {
                throw new IllegalArgumentException("Specified osgi-beans descriptor is empty: " + osgiBeansDescriptorURL);
            }
            try {
                parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
                parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", loadXsds());
            } catch (IllegalArgumentException | SAXNotRecognizedException | SAXNotSupportedException e) {
            // No op, we just don't validate the XML
            }
            parser.parse(source, handler);
        } catch (IOException | SAXException e) {
            return Throw.exception(e);
        }
    }
    return handler.createBeansModel();
}
Also used : InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) IOException(java.io.IOException) URL(java.net.URL) SAXException(org.xml.sax.SAXException) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 4 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project robovm by robovm.

the class SAXNotSupportedExceptionTest method testSAXNotSupportedException.

public void testSAXNotSupportedException() {
    SAXNotSupportedException e = new SAXNotSupportedException();
    assertNull(e.getMessage());
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException)

Example 5 with SAXNotSupportedException

use of org.xml.sax.SAXNotSupportedException in project robovm by robovm.

the class ExpatReader method parse.

public void parse(InputSource input) throws IOException, SAXException {
    if (processNamespacePrefixes && processNamespaces) {
        /*
             * Expat has XML_SetReturnNSTriplet, but that still doesn't
             * include xmlns attributes like this feature requires. We may
             * have to implement namespace processing ourselves if we want
             * this (not too difficult). We obviously "support" namespace
             * prefixes if namespaces are disabled.
             */
        throw new SAXNotSupportedException("The 'namespace-prefix' " + "feature is not supported while the 'namespaces' " + "feature is enabled.");
    }
    // Try the character stream.
    Reader reader = input.getCharacterStream();
    if (reader != null) {
        try {
            parse(reader, input.getPublicId(), input.getSystemId());
        } finally {
            IoUtils.closeQuietly(reader);
        }
        return;
    }
    // Try the byte stream.
    InputStream in = input.getByteStream();
    String encoding = input.getEncoding();
    if (in != null) {
        try {
            parse(in, encoding, input.getPublicId(), input.getSystemId());
        } finally {
            IoUtils.closeQuietly(in);
        }
        return;
    }
    String systemId = input.getSystemId();
    if (systemId == null) {
        throw new SAXException("No input specified.");
    }
    // Try the system id.
    in = ExpatParser.openUrl(systemId);
    try {
        parse(in, encoding, input.getPublicId(), systemId);
    } finally {
        IoUtils.closeQuietly(in);
    }
}
Also used : SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) InputStream(java.io.InputStream) Reader(java.io.Reader) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

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