@Test public void testNoMarkupInToTextHandler() throws Exception { ContentHandler contentHandler = new ToTextContentHandler(); ParseContext parseContext = new ParseContext(); try (TikaInputStream tis = TikaInputStream.get( getResourceAsStream("/test-documents/testJAVA.java"))) { AUTO_DETECT_PARSER.parse(tis, contentHandler, createMetadata("text/x-java-source"), parseContext); } String strContent = contentHandler.toString(); assertContains("public class HelloWorld {", strContent); assertNotContained("background-color", strContent); }
@Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { try (AutoDetectReader reader = new AutoDetectReader( new CloseShieldInputStream(stream), metadata, getEncodingDetector(context))) { Charset charset = reader.getCharset(); String mediaType = metadata.get(Metadata.CONTENT_TYPE); String name = metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY); if (mediaType != null && name != null) { MediaType type = MediaType.parse(mediaType); metadata.set(Metadata.CONTENT_TYPE, type.toString()); metadata.set(Metadata.CONTENT_ENCODING, charset.name()); StringBuilder out = new StringBuilder(); String line; int nbLines = 0; while ((line = reader.readLine()) != null) { out.append(line + System.getProperty("line.separator")); String author = parserAuthor(line); if (author != null) { metadata.add(TikaCoreProperties.CREATOR, author); } nbLines++; } metadata.set("LoC", String.valueOf(nbLines)); Renderer renderer = getRenderer(type.toString()); String codeAsHtml = renderer.highlight(name, out.toString(), charset.name(), false); Schema schema = context.get(Schema.class, HTML_SCHEMA); org.ccil.cowan.tagsoup.Parser parser = new org.ccil.cowan.tagsoup.Parser(); parser.setProperty(org.ccil.cowan.tagsoup.Parser.schemaProperty, schema); parser.setContentHandler(handler); parser.parse(new InputSource(new StringReader(codeAsHtml))); } } }
SourceCodeParser extends AbstractEncodingDetectorParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { try (AutoDetectReader reader = new AutoDetectReader( new CloseShieldInputStream(stream), metadata, getEncodingDetector(context))) { Charset charset = reader.getCharset(); String mediaType = metadata.get(Metadata.CONTENT_TYPE); String name = metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY); if (mediaType != null && name != null) { MediaType type = MediaType.parse(mediaType); metadata.set(Metadata.CONTENT_TYPE, type.toString()); metadata.set(Metadata.CONTENT_ENCODING, charset.name()); StringBuilder out = new StringBuilder(); String line; int nbLines = 0; while ((line = reader.readLine()) != null) { out.append(line + System.getProperty("line.separator")); String author = parserAuthor(line); if (author != null) { metadata.add(TikaCoreProperties.CREATOR, author); } nbLines++; } metadata.set("LoC", String.valueOf(nbLines)); Renderer renderer = getRenderer(type.toString()); String codeAsHtml = renderer.highlight(name, out.toString(), charset.name(), false); Schema schema = context.get(Schema.class, HTML_SCHEMA); org.ccil.cowan.tagsoup.Parser parser = new org.ccil.cowan.tagsoup.Parser(); parser.setProperty(org.ccil.cowan.tagsoup.Parser.schemaProperty, schema); parser.setContentHandler(handler); parser.parse(new InputSource(new StringReader(codeAsHtml))); } } } }
SourceCodeParser extends AbstractEncodingDetectorParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { try (AutoDetectReader reader = new AutoDetectReader( new CloseShieldInputStream(stream), metadata, getEncodingDetector(context))) { Charset charset = reader.getCharset(); String mediaType = metadata.get(Metadata.CONTENT_TYPE); String name = metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY); if (mediaType != null && name != null) { MediaType type = MediaType.parse(mediaType); metadata.set(Metadata.CONTENT_TYPE, type.toString()); metadata.set(Metadata.CONTENT_ENCODING, charset.name()); StringBuilder out = new StringBuilder(); String line; int nbLines = 0; while ((line = reader.readLine()) != null) { out.append(line + System.getProperty("line.separator")); String author = parserAuthor(line); if (author != null) { metadata.add(TikaCoreProperties.CREATOR, author); } nbLines++; } metadata.set("LoC", String.valueOf(nbLines)); Renderer renderer = getRenderer(type.toString()); String codeAsHtml = renderer.highlight(name, out.toString(), charset.name(), false); Schema schema = context.get(Schema.class, HTML_SCHEMA); org.ccil.cowan.tagsoup.Parser parser = new org.ccil.cowan.tagsoup.Parser(); parser.setProperty(org.ccil.cowan.tagsoup.Parser.schemaProperty, schema); parser.setContentHandler(handler); parser.parse(new InputSource(new StringReader(codeAsHtml))); } } } SourceCodeParser();  SourceCodeParser(EncodingDetector encodingDetector); }
SourceCodeParser extends AbstractEncodingDetectorParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { try (AutoDetectReader reader = new AutoDetectReader( new CloseShieldInputStream(stream), metadata, getEncodingDetector(context))) { Charset charset = reader.getCharset(); String mediaType = metadata.get(Metadata.CONTENT_TYPE); String name = metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY); if (mediaType != null && name != null) { MediaType type = MediaType.parse(mediaType); metadata.set(Metadata.CONTENT_TYPE, type.toString()); metadata.set(Metadata.CONTENT_ENCODING, charset.name()); StringBuilder out = new StringBuilder(); String line; int nbLines = 0; while ((line = reader.readLine()) != null) { out.append(line + System.getProperty("line.separator")); String author = parserAuthor(line); if (author != null) { metadata.add(TikaCoreProperties.CREATOR, author); } nbLines++; } metadata.set("LoC", String.valueOf(nbLines)); Renderer renderer = getRenderer(type.toString()); String codeAsHtml = renderer.highlight(name, out.toString(), charset.name(), false); Schema schema = context.get(Schema.class, HTML_SCHEMA); org.ccil.cowan.tagsoup.Parser parser = new org.ccil.cowan.tagsoup.Parser(); parser.setProperty(org.ccil.cowan.tagsoup.Parser.schemaProperty, schema); parser.setContentHandler(handler); parser.parse(new InputSource(new StringReader(codeAsHtml))); } } } SourceCodeParser();  SourceCodeParser(EncodingDetector encodingDetector); @Override Set<MediaType> getSupportedTypes(ParseContext context); @Override void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context); }
SourceCodeParser extends AbstractEncodingDetectorParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { try (AutoDetectReader reader = new AutoDetectReader( new CloseShieldInputStream(stream), metadata, getEncodingDetector(context))) { Charset charset = reader.getCharset(); String mediaType = metadata.get(Metadata.CONTENT_TYPE); String name = metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY); if (mediaType != null && name != null) { MediaType type = MediaType.parse(mediaType); metadata.set(Metadata.CONTENT_TYPE, type.toString()); metadata.set(Metadata.CONTENT_ENCODING, charset.name()); StringBuilder out = new StringBuilder(); String line; int nbLines = 0; while ((line = reader.readLine()) != null) { out.append(line + System.getProperty("line.separator")); String author = parserAuthor(line); if (author != null) { metadata.add(TikaCoreProperties.CREATOR, author); } nbLines++; } metadata.set("LoC", String.valueOf(nbLines)); Renderer renderer = getRenderer(type.toString()); String codeAsHtml = renderer.highlight(name, out.toString(), charset.name(), false); Schema schema = context.get(Schema.class, HTML_SCHEMA); org.ccil.cowan.tagsoup.Parser parser = new org.ccil.cowan.tagsoup.Parser(); parser.setProperty(org.ccil.cowan.tagsoup.Parser.schemaProperty, schema); parser.setContentHandler(handler); parser.parse(new InputSource(new StringReader(codeAsHtml))); } } } SourceCodeParser();  SourceCodeParser(EncodingDetector encodingDetector); @Override Set<MediaType> getSupportedTypes(ParseContext context); @Override void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context);  }