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();
}
}
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);
}
}
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;
}
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;
}
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");
}
Aggregations