use of org.apache.tika.sax.XHTMLContentHandler in project jackrabbit by apache.
the class BlockingParser method parse.
@Override
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws SAXException {
waitIfBlocked();
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
xhtml.element("p", "The quick brown fox jumped over the lazy dog.");
xhtml.endDocument();
}
use of org.apache.tika.sax.XHTMLContentHandler in project jackrabbit-oak by apache.
the class HtmlRepresentation method render.
public void render(Tree tree, HttpServletResponse response) throws IOException {
try {
XHTMLContentHandler xhtml = startResponse(response, tree.getPath());
xhtml.startDocument();
xhtml.startElement("dl");
for (PropertyState property : tree.getProperties()) {
xhtml.element("dt", property.getName());
if (property.isArray()) {
xhtml.startElement("dd");
xhtml.startElement("ol");
for (String value : property.getValue(STRINGS)) {
xhtml.element("li", value);
}
xhtml.endElement("ol");
xhtml.endElement("dd");
} else {
xhtml.element("dd", property.getValue(STRING));
}
}
for (Tree child : tree.getChildren()) {
String name = child.getName();
xhtml.element("dt", name);
xhtml.startElement("dd");
xhtml.startElement("a", "href", response.encodeRedirectURL(URLEncoder.encode(name, Charsets.UTF_8.name()) + "/"));
xhtml.characters(child.getPath());
xhtml.endElement("a");
xhtml.endElement("dd");
}
xhtml.endElement("dl");
xhtml.endDocument();
} catch (SAXException e) {
throw new IOException(e);
}
}
use of org.apache.tika.sax.XHTMLContentHandler in project jackrabbit-oak by apache.
the class HtmlRepresentation method startResponse.
private XHTMLContentHandler startResponse(HttpServletResponse response, String title) throws IOException {
try {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
TransformerHandler handler = factory.newTransformerHandler();
Transformer transformer = handler.getTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "html");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
handler.setResult(new StreamResult(response.getOutputStream()));
Metadata metadata = new Metadata();
metadata.set(Metadata.TITLE, title);
return new XHTMLContentHandler(handler, metadata);
} catch (TransformerConfigurationException e) {
throw new IOException(e);
}
}
use of org.apache.tika.sax.XHTMLContentHandler in project tika by apache.
the class DummyParser method parse.
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
for (Entry<String, String> m : this.metadata.entrySet()) {
metadata.add(m.getKey(), m.getValue());
}
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
if (xmlText != null) {
xhtml.characters(xmlText.toCharArray(), 0, xmlText.length());
}
xhtml.endDocument();
}
use of org.apache.tika.sax.XHTMLContentHandler in project tika by apache.
the class MockParser method parse.
@Override
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
Document doc = null;
try {
DocumentBuilder docBuilder = context.getDocumentBuilder();
doc = docBuilder.parse(stream);
} catch (SAXException e) {
//to distinguish between SAX on read vs SAX while writing
throw new IOExceptionWithCause(e);
}
Node root = doc.getDocumentElement();
NodeList actions = root.getChildNodes();
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
for (int i = 0; i < actions.getLength(); i++) {
executeAction(actions.item(i), metadata, context, xhtml);
}
xhtml.endDocument();
}
Aggregations