use of org.xml.sax.XMLReader in project bnd by bndtools.
the class TestSAXFilters method testSelectionFilter.
public void testSelectionFilter() throws Exception {
ByteArrayOutputStream output = new ByteArrayOutputStream();
ElementSelectionFilter filter = new ElementSelectionFilter() {
@Override
protected boolean select(int depth, String uri, String localName, String qName, Attributes attribs) {
return !"e".equals(qName);
}
};
XMLReader reader = SAXUtil.buildPipeline(new StreamResult(output), filter);
reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE4.getBytes())));
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root c=\"3\"><a><b><c><d/></c></b></a></root>", output.toString());
}
use of org.xml.sax.XMLReader in project bnd by bndtools.
the class TestSAXFilters method testDontRepeatProcessingInstruction.
public void testDontRepeatProcessingInstruction() throws Exception {
ByteArrayOutputStream output = new ByteArrayOutputStream();
MergeContentFilter merger = new MergeContentFilter();
XMLReader reader = SAXUtil.buildPipeline(new StreamResult(output), merger);
reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE5.getBytes())));
reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE5.getBytes())));
merger.closeRootAndDocument();
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type='text/xsl' href='http://www2.osgi.org/www/obr2html.xsl'?><root><a/><a/></root>";
assertEquals(expected, stripLineBreaks(output.toString()));
}
use of org.xml.sax.XMLReader in project tika by apache.
the class XWPFEventBasedWordExtractor method handlePart.
private void handlePart(PackagePart packagePart, XWPFListManager xwpfListManager, StringBuilder buffer) throws IOException, SAXException {
Map<String, String> hyperlinks = loadHyperlinkRelationships(packagePart);
try (InputStream stream = packagePart.getInputStream()) {
XMLReader reader = SAXHelper.newXMLReader();
reader.setContentHandler(new OOXMLWordAndPowerPointTextHandler(new XWPFToTextContentHandler(buffer), hyperlinks));
reader.parse(new InputSource(new CloseShieldInputStream(stream)));
} catch (ParserConfigurationException e) {
LOG.warn("Can't configure XMLReader", e);
}
}
use of org.xml.sax.XMLReader in project sling by apache.
the class SlingTransformer method createTransformerHandler.
private TransformerHandler createTransformerHandler() throws Exception {
SAXTransformerFactory transformerFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
TemplatesHandler templatesHandler = transformerFactory.newTemplatesHandler();
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(templatesHandler);
InputSource inputSource = new InputSource(getXsltSource());
xmlReader.parse(inputSource);
// Create transformer handler
final TransformerHandler handler = transformerFactory.newTransformerHandler(templatesHandler.getTemplates());
return handler;
}
use of org.xml.sax.XMLReader in project sling by apache.
the class XplBuilder method build.
public Step build(Reader xplReader) throws Exception {
XMLReader xMLReader = XMLReaderFactory.createXMLReader();
XplHandler xplHandler = new XplHandler();
xMLReader.setContentHandler(xplHandler);
InputSource inputSource = new InputSource(xplReader);
xMLReader.parse(inputSource);
return xplHandler.getRootStep();
}
Aggregations