Search in sources :

Example 81 with SAXParser

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

the class FelixJettySourceReferenceFinder method findSourceReferences.

@Override
public List<SourceReference> findSourceReferences(Bundle bundle) throws SourceReferenceException {
    // so infer them from the X-Jetty-Version header
    if (!bundle.getSymbolicName().equals("org.apache.felix.http.jetty")) {
        return Collections.emptyList();
    }
    final Object jettyVersion = bundle.getHeaders().get("X-Jetty-Version");
    if (!(jettyVersion instanceof String)) {
        log.warn("Could not retrieve Jetty version from bundle '{}' because header 'X-Jetty-Version' is not set!", bundle);
        return Collections.emptyList();
    }
    Enumeration<URL> entries = bundle.findEntries("META-INF/maven", "pom.xml", true);
    if (entries != null && entries.hasMoreElements()) {
        URL entry = entries.nextElement();
        InputStream pom = null;
        try {
            pom = entry.openStream();
            try {
                SAXParserFactory parserFactory = SAXParserFactory.newInstance();
                SAXParser parser = parserFactory.newSAXParser();
                PomHandler handler = new PomHandler((String) jettyVersion);
                parser.parse(new InputSource(pom), handler);
                return handler.getReferences();
            } catch (SAXException e) {
                throw new SourceReferenceException(e);
            } catch (ParserConfigurationException e) {
                throw new SourceReferenceException(e);
            } finally {
                IOUtils.closeQuietly(pom);
            }
        } catch (IOException e) {
            throw new SourceReferenceException(e);
        } finally {
            IOUtils.closeQuietly(pom);
        }
    } else {
        log.warn("Could not find a pom.xml in bundle '{}'!", bundle);
        return Collections.emptyList();
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL) SAXException(org.xml.sax.SAXException) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 82 with SAXParser

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

the class JaxbOpenejb method unmarshal.

public static <T> T unmarshal(final Class<T> type, final InputStream in, final boolean filter) throws ParserConfigurationException, SAXException, JAXBException {
    final InputSource inputSource = new InputSource(in);
    final SAXParser parser = Saxs.namespaceAwareFactory().newSAXParser();
    final JAXBContext ctx = getContext(type);
    final Unmarshaller unmarshaller = ctx.createUnmarshaller();
    unmarshaller.setEventHandler(new ValidationEventHandler() {

        public boolean handleEvent(final ValidationEvent validationEvent) {
            System.out.println(validationEvent);
            return false;
        }
    });
    final SAXSource source;
    if (filter) {
        final NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
        xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
        source = new SAXSource(xmlFilter, inputSource);
    } else {
        source = new SAXSource(inputSource);
    }
    currentPublicId.set(new TreeSet<String>());
    try {
        return unmarshaller.unmarshal(source, type).getValue();
    } finally {
        currentPublicId.set(null);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ValidationEventHandler(javax.xml.bind.ValidationEventHandler) SAXSource(javax.xml.transform.sax.SAXSource) ValidationEvent(javax.xml.bind.ValidationEvent) SAXParser(javax.xml.parsers.SAXParser) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 83 with SAXParser

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

the class JaxbOpenejb method parseServicesJar.

public static ServicesJar parseServicesJar(final InputStream in) throws ParserConfigurationException, SAXException, IOException {
    final InputSource inputSource = new InputSource(in);
    final SAXParser parser = Saxs.namespaceAwareFactory().newSAXParser();
    final ServicesJar servicesJar1 = new ServicesJar();
    parser.parse(inputSource, new OpenEJBHandler(servicesJar1));
    final ServicesJar servicesJar = servicesJar1;
    return servicesJar;
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser)

Example 84 with SAXParser

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

the class SaxOpenejb method parse.

public static Openejb parse(final InputSource source) throws SAXException, ParserConfigurationException, IOException {
    final SAXParser parser = Saxs.factory().newSAXParser();
    final SaxOpenejb sax = new SaxOpenejb();
    parser.parse(source, sax);
    return sax.openejb;
}
Also used : SAXParser(javax.xml.parsers.SAXParser)

Example 85 with SAXParser

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

the class TesseractOCRParser method extractHOCROutput.

private void extractHOCROutput(InputStream is, ParseContext parseContext, XHTMLContentHandler xhtml) throws TikaException, IOException, SAXException {
    if (parseContext == null) {
        parseContext = new ParseContext();
    }
    SAXParser parser = parseContext.getSAXParser();
    xhtml.startElement("div", "class", "ocr");
    parser.parse(is, new OfflineContentHandler(new HOCRPassThroughHandler(xhtml)));
    xhtml.endElement("div");
}
Also used : OfflineContentHandler(org.apache.tika.sax.OfflineContentHandler) ParseContext(org.apache.tika.parser.ParseContext) SAXParser(javax.xml.parsers.SAXParser)

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