private void processOutput(ContentHandler handler, Metadata metadata, String output) throws SAXException, IOException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); InputStream stream = new ByteArrayInputStream(output.getBytes(UTF_8)); try (Reader reader = new InputStreamReader(stream, UTF_8)) { xhtml.startDocument(); xhtml.startElement("p"); char[] buffer = new char[1024]; for (int n = reader.read(buffer); n != -1; n = reader.read(buffer)) { xhtml.characters(buffer, 0, n); } xhtml.endElement("p"); } finally { xhtml.endDocument(); } }
private void parseTableData(String value) throws SAXException { if (currentColumn == 0) { xhtml.startElement("tr"); } xhtml.element("td", value); if (currentColumn.equals(numberOfColumns)) { xhtml.endElement("tr"); } }
@Override protected void writeLineSeparator() throws IOException { try { xhtml.newline(); } catch (SAXException e) { throw new IOException( "Unable to write a newline character", e); } }
private void writeKeyword(String keyword) throws SAXException { xhtml.startElement("span", "class", "java-keyword"); xhtml.characters(keyword); xhtml.endElement("span"); }
public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws SAXException { XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); xhtml.endDocument(); } }
@Override public void startBookmark(String id, String name) { //skip bookmarks within hyperlinks if (name != null && ! wroteHyperlinkStart) { try { xhtml.startElement("a", "name", name); xhtml.endElement("a"); } catch (SAXException e) { } } }
new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); xhtml.element("h1", title); xhtml.element("p", description); xhtml.startElement("ul"); for (Object e : feed.getEntries()) { SyndEntry entry = (SyndEntry) e; String link = entry.getLink(); if (link != null) { xhtml.startElement("li"); xhtml.startElement("a", "href", link); xhtml.characters(stripTags(entry.getTitleEx())); xhtml.endElement("a"); SyndContent content = entry.getDescription(); if (content != null) { xhtml.newline(); xhtml.characters(stripTags(content)); xhtml.endElement("li"); xhtml.endElement("ul"); xhtml.endDocument(); } catch (FeedException e) { throw new TikaException("RSS parse error", e);
public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { stream.read(); metadata.set(Metadata.CONTENT_TYPE, "text/plain"); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); char[] ch = "Hello, World!".toCharArray(); xhtml.characters(ch, 0, ch.length); xhtml.endDocument(); }
/** * Test that the conversion to an {@link OutputStream} doesn't leave * characters unflushed in an internal buffer. * * @see <a href="https://issues.apache.org/jira/browse/TIKA-179">TIKA-179</a> */ @Test public void testOutputStream() throws Exception { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); XHTMLContentHandler xhtml = new XHTMLContentHandler( new BodyContentHandler(buffer), new Metadata()); xhtml.startDocument(); xhtml.element("p", "Test text"); xhtml.endDocument(); assertEquals("Test text\n", buffer.toString(UTF_8.name())); }
public void visitEnd() { try { xhtml.characters("}\n"); xhtml.endElement("pre"); xhtml.endDocument(); } catch (SAXException e) { throw new RuntimeException(e); } }
public XHTMLClassVisitor(ContentHandler handler, Metadata metadata) { super(Opcodes.ASM5); this.xhtml = new XHTMLContentHandler(handler, metadata); this.metadata = metadata; }
@Override public void characters(char[] ch, int start, int length) throws SAXException { if (inParsableText && inSlide && length != 0) { xhtml.characters(ch, start, length); } }
private void extractDocumentArea(WPPrefixArea prefixArea, WPInputStream in, XHTMLContentHandler xhtml) throws SAXException, IOException { // Move to offset (for some reason skip() did not work). for (int i = 0; i < prefixArea.getDocAreaPointer(); i++) { in.readWPByte(); } xhtml.startDocument(); getDocumentAreaExtractor(prefixArea).extract(in, xhtml); xhtml.endDocument(); }
@Override public void endTableCell() { try { xhtml.endElement("td"); } catch (SAXException e) { } pWithinCell = 0; tableCellDepth--; }
@Override public void hyperlinkStart(String link) { try { if (link != null) { xhtml.startElement("a", "href", link); wroteHyperlinkStart = true; } } catch (SAXException e) { } }
@Override public void startMessage() throws MimeException { try { handler.startDocument(); } catch (SAXException e) { throw new MimeException(e); } }
if (scriptAtts.getLength() > 0) { startElementWithSafeAttributes("script", scriptAtts); xhtml.endElement("script"); String safe = mapper.mapSafeElement(name); if (safe != null) { xhtml.endElement(safe); } else if (XHTMLContentHandler.ENDLINE.contains( name.toLowerCase(Locale.ENGLISH))) { xhtml.newline();
@Override public void endMessage() throws MimeException { try { handler.endDocument(); } catch (SAXException e) { throw new MimeException(e); } }
lazyStartHead(); super.startElement(XHTML, "meta", "meta", attributes); super.endElement(XHTML, "meta", "meta"); newline(); newline(); newline();