Search in sources :

Example 6 with SAXNotRecognizedException

use of org.xml.sax.SAXNotRecognizedException in project Payara by payara.

the class GenericParser method newSAXParser.

/**
 * Create a <code>SAXParser</code> configured to support XML Scheman and DTD
 * @param properties parser specific properties/features
 * @return an XML Schema/DTD enabled <code>SAXParser</code>
 */
public static SAXParser newSAXParser(Properties properties) throws ParserConfigurationException, SAXException, SAXNotRecognizedException {
    SAXParserFactory factory = (SAXParserFactory) properties.get("SAXParserFactory");
    SAXParser parser = factory.newSAXParser();
    String schemaLocation = (String) properties.get("schemaLocation");
    String schemaLanguage = (String) properties.get("schemaLanguage");
    try {
        if (schemaLocation != null) {
            parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
            parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
        }
    } catch (SAXNotRecognizedException e) {
        if (log.isLoggable(Level.INFO)) {
            log.log(Level.INFO, parser.getClass().getName() + ": " + e.getMessage() + " not supported.");
        }
    }
    return parser;
}
Also used : SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 7 with SAXNotRecognizedException

use of org.xml.sax.SAXNotRecognizedException in project Payara by payara.

the class DeploymentDescriptorFile method getSAXParser.

/**
 * @return a SAX Parser to read an XML file (containing
 * Deployment Descriptors) into DOL descriptors
 *
 * @param validating true if the parser should excercise DTD validation
 */
public SAXParser getSAXParser(boolean validating) {
    // always use system SAXParser to parse DDs, see IT 8229
    ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        // set the namespace awareness
        spf.setNamespaceAware(true);
        // turn validation on for deployment descriptor XML files
        spf.setValidating(validating);
        if (!validating) {
            spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        }
        // with crimson
        if (spf.getClass().getName().indexOf("xerces") != -1) {
            spf.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
        } else {
            DOLUtils.getDefaultLogger().log(Level.WARNING, "modify your java command line to include the -Djava.endorsed.dirs option");
        }
        try {
            if (!validating) {
                // if we are not validating, let's not load the DTD
                if (getDeploymentDescriptorPath().indexOf(DescriptorConstants.WLS) != -1) {
                    // and let's only turn it off for weblogic*.xml for now
                    spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
                }
            }
            // Validation part 2a: set the schema language if necessary
            spf.setFeature("http://apache.org/xml/features/validation/schema", validating);
            SAXParser sp = spf.newSAXParser();
            // put the default schema for this deployment file type
            String path = getDefaultSchemaSource();
            if (path != null) {
                sp.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", path);
            }
            // Set Xerces feature to allow dynamic validation. This prevents
            // SAX errors from being reported when no schemaLocation attr
            // is seen for a DTD based (J2EE1.3) XML descriptor.
            sp.getXMLReader().setFeature("http://apache.org/xml/features/validation/dynamic", validating);
            return sp;
        } catch (SAXNotRecognizedException x) {
            // This can happen if the parser does not support JAXP 1.2
            DOLUtils.getDefaultLogger().log(Level.SEVERE, "INFO: JAXP SAXParser property not recognized: " + SaxParserHandler.JAXP_SCHEMA_LANGUAGE);
            DOLUtils.getDefaultLogger().log(Level.SEVERE, "Check to see if parser conforms to JAXP 1.2 spec.");
        }
    } catch (Exception e) {
        DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError", new Object[] { e.getMessage() });
        DOLUtils.getDefaultLogger().log(Level.WARNING, "Error occurred", e);
    } finally {
        Thread.currentThread().setContextClassLoader(currentLoader);
    }
    return null;
}
Also used : SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 8 with SAXNotRecognizedException

use of org.xml.sax.SAXNotRecognizedException in project iosched by google.

the class SVGParser method parse.

static SVG parse(InputSource data, SVGHandler handler) throws SVGParseException {
    try {
        final Picture picture = new Picture();
        handler.setPicture(picture);
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        xr.setContentHandler(handler);
        xr.setFeature("http://xml.org/sax/features/validation", false);
        if (DISALLOW_DOCTYPE_DECL) {
            try {
                xr.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            } catch (SAXNotRecognizedException e) {
                DISALLOW_DOCTYPE_DECL = false;
            }
        }
        xr.parse(data);
        SVG result = new SVG(picture, handler.bounds);
        // Skip bounds if it was an empty pic
        if (!Float.isInfinite(handler.limits.top)) {
            result.setLimits(handler.limits);
        }
        return result;
    } catch (Exception e) {
        Log.e(TAG, "Failed to parse SVG.", e);
        throw new SVGParseException(e);
    }
}
Also used : Picture(android.graphics.Picture) SAXParser(javax.xml.parsers.SAXParser) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) XMLReader(org.xml.sax.XMLReader) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) SAXException(org.xml.sax.SAXException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 9 with SAXNotRecognizedException

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

the class SAXParserTest method testSetGetProperty.

public void testSetGetProperty() {
    // Ordinary case
    String validName = "http://xml.org/sax/properties/lexical-handler";
    LexicalHandler validValue = new MockHandler(new MethodLogger());
    try {
        SAXParser parser = spf.newSAXParser();
        parser.setProperty(validName, validValue);
        assertEquals(validValue, parser.getProperty(validName));
        parser.setProperty(validName, null);
        assertEquals(null, parser.getProperty(validName));
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    // Unsupported property
    try {
        SAXParser parser = spf.newSAXParser();
        parser.setProperty("foo", "bar");
        fail("SAXNotRecognizedException expected");
    } catch (SAXNotRecognizedException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    try {
        SAXParser parser = spf.newSAXParser();
        parser.getProperty("foo");
        fail("SAXNotRecognizedException expected");
    } catch (SAXNotRecognizedException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    // No name case
    try {
        SAXParser parser = spf.newSAXParser();
        parser.setProperty(null, "bar");
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    try {
        SAXParser parser = spf.newSAXParser();
        parser.getProperty(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
}
Also used : LexicalHandler(org.xml.sax.ext.LexicalHandler) SAXParser(javax.xml.parsers.SAXParser) MockHandler(tests.api.org.xml.sax.support.MockHandler) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) MethodLogger(tests.api.org.xml.sax.support.MethodLogger) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 10 with SAXNotRecognizedException

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

the class SAXNotRecognizedExceptionTest method testSAXNotRecognizedException.

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

Aggregations

SAXNotRecognizedException (org.xml.sax.SAXNotRecognizedException)16 SAXException (org.xml.sax.SAXException)10 SAXParser (javax.xml.parsers.SAXParser)9 SAXParserFactory (javax.xml.parsers.SAXParserFactory)9 SAXNotSupportedException (org.xml.sax.SAXNotSupportedException)8 IOException (java.io.IOException)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 XMLReader (org.xml.sax.XMLReader)5 InputSource (org.xml.sax.InputSource)4 SAXParseException (org.xml.sax.SAXParseException)3 InputStream (java.io.InputStream)2 DOMSource (javax.xml.transform.dom.DOMSource)2 SAXSource (javax.xml.transform.sax.SAXSource)2 StreamSource (javax.xml.transform.stream.StreamSource)2 DTMException (org.apache.xml.dtm.DTMException)2 DOM2DTM (org.apache.xml.dtm.ref.dom2dtm.DOM2DTM)2 SAX2DTM (org.apache.xml.dtm.ref.sax2dtm.SAX2DTM)2 SAX2RTFDTM (org.apache.xml.dtm.ref.sax2dtm.SAX2RTFDTM)2 XMLStringFactory (org.apache.xml.utils.XMLStringFactory)2 Picture (android.graphics.Picture)1