Search in sources :

Example 86 with SAXParser

use of javax.xml.parsers.SAXParser in project tomee by apache.

the class ScanUtil method read.

public static ScanHandler read(final URL scanXml) throws IOException {
    try {
        final SAXParser parser = Saxs.factory().newSAXParser();
        final ScanHandler handler = new ScanHandler();
        parser.parse(new BufferedInputStream(scanXml.openStream()), handler);
        return handler;
    } catch (final Exception e) {
        throw new IOException("can't parse " + scanXml.toExternalForm());
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException)

Example 87 with SAXParser

use of javax.xml.parsers.SAXParser in project tomee by apache.

the class QuickServerXmlParser method parse.

public static QuickServerXmlParser parse(final File serverXml) {
    final QuickServerXmlParser handler = new QuickServerXmlParser();
    try {
        final SAXParser parser = FACTORY.newSAXParser();
        parser.parse(serverXml, handler);
    } catch (final Exception e) {
    // no-op: using defaults
    }
    return handler;
}
Also used : SAXParser(javax.xml.parsers.SAXParser) SAXException(org.xml.sax.SAXException)

Example 88 with SAXParser

use of javax.xml.parsers.SAXParser in project tomee by apache.

the class QuickServerXmlParser method parse.

public static QuickServerXmlParser parse(final String serverXmlContents) {
    final QuickServerXmlParser handler = new QuickServerXmlParser();
    try {
        final SAXParser parser = FACTORY.newSAXParser();
        parser.parse(new ByteArrayInputStream(serverXmlContents.getBytes()), handler);
    } catch (final Exception e) {
    // no-op: using defaults
    }
    return handler;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) SAXException(org.xml.sax.SAXException)

Example 89 with SAXParser

use of javax.xml.parsers.SAXParser in project tomee by apache.

the class ReadDescriptors method isEmpty.

private static boolean isEmpty(final InputStream is, final String rootElement) throws IOException, ParserConfigurationException, SAXException {
    final LengthInputStream in = new LengthInputStream(is);
    final InputSource inputSource = new InputSource(in);
    final SAXParser parser;
    final Thread thread = Thread.currentThread();
    final ClassLoader original = thread.getContextClassLoader();
    thread.setContextClassLoader(Saxs.class.getClassLoader());
    try {
        parser = Saxs.namespaceAwareFactory().newSAXParser();
    } finally {
        thread.setContextClassLoader(original);
    }
    try {
        parser.parse(inputSource, new DefaultHandler() {

            public void startElement(final String uri, final String localName, final String qName, final Attributes att) throws SAXException {
                if (!localName.equals(rootElement)) {
                    throw new SAXException(localName);
                }
            }

            public InputSource resolveEntity(final String publicId, final String systemId) throws IOException, SAXException {
                return new InputSource(new ByteArrayInputStream(new byte[0]));
            }
        });
        return true;
    } catch (final SAXException e) {
        return in.getLength() == 0;
    }
}
Also used : LengthInputStream(org.apache.openejb.util.LengthInputStream) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) Attributes(org.xml.sax.Attributes) SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) Saxs(org.apache.openejb.util.Saxs) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException)

Example 90 with SAXParser

use of javax.xml.parsers.SAXParser in project tomee by apache.

the class QuickServerXmlParser method parse.

public static QuickServerXmlParser parse(final File serverXml, final boolean defaults) {
    final QuickServerXmlParser handler = new QuickServerXmlParser(defaults);
    try {
        final SAXParser parser = FACTORY.newSAXParser();
        parser.parse(serverXml, handler);
    } catch (final Exception e) {
    // no-op: using defaults
    }
    return handler;
}
Also used : SAXParser(javax.xml.parsers.SAXParser) SAXException(org.xml.sax.SAXException)

Aggregations

SAXParser (javax.xml.parsers.SAXParser)235 SAXParserFactory (javax.xml.parsers.SAXParserFactory)142 SAXException (org.xml.sax.SAXException)112 InputSource (org.xml.sax.InputSource)95 IOException (java.io.IOException)80 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)71 DefaultHandler (org.xml.sax.helpers.DefaultHandler)37 XMLReader (org.xml.sax.XMLReader)36 File (java.io.File)35 ByteArrayInputStream (java.io.ByteArrayInputStream)28 StringReader (java.io.StringReader)27 InputStream (java.io.InputStream)24 Attributes (org.xml.sax.Attributes)22 SAXSource (javax.xml.transform.sax.SAXSource)17 SAXParseException (org.xml.sax.SAXParseException)17 ArrayList (java.util.ArrayList)13 JAXBContext (javax.xml.bind.JAXBContext)12 Unmarshaller (javax.xml.bind.Unmarshaller)12 FileNotFoundException (java.io.FileNotFoundException)10 ValidationEvent (javax.xml.bind.ValidationEvent)9