use of org.apache.tika.mime.MediaType in project tika by apache.
the class MediaTypeExample method main.
public static void main(String[] args) throws Exception {
MediaTypeRegistry registry = MediaTypeRegistry.getDefaultRegistry();
MediaType type = MediaType.parse("image/svg+xml");
while (type != null) {
System.out.println(type);
type = registry.getSupertype(type);
}
}
use of org.apache.tika.mime.MediaType in project tika by apache.
the class MediaTypeExample method listAllTypes.
public static void listAllTypes() {
MediaTypeRegistry registry = MediaTypeRegistry.getDefaultRegistry();
for (MediaType type : registry.getTypes()) {
Set<MediaType> aliases = registry.getAliases(type);
System.out.println(type + ", also known as " + aliases);
}
}
use of org.apache.tika.mime.MediaType in project tika by apache.
the class SourceCodeParserTest method testSupportTypes.
@Test
public void testSupportTypes() throws Exception {
Set<MediaType> supportedTypes = sourceCodeParser.getSupportedTypes(new ParseContext());
assertTrue(supportedTypes.contains(new MediaType("text", "x-java-source")));
assertTrue(supportedTypes.contains(new MediaType("text", "x-groovy")));
assertTrue(supportedTypes.contains(new MediaType("text", "x-c++src")));
assertFalse(sourceCodeParser.getSupportedTypes(new ParseContext()).contains(new MediaType("text", "html")));
}
use of org.apache.tika.mime.MediaType in project tika by apache.
the class ForkParserIntegrationTest method testParserHandlingOfNonSerializable.
/**
* If we supply a non serializable object on the ParseContext,
* check we get a helpful exception back
*/
@Test
public void testParserHandlingOfNonSerializable() throws Exception {
ForkParser parser = new ForkParser(ForkParserIntegrationTest.class.getClassLoader(), tika.getParser());
ParseContext context = new ParseContext();
context.set(Detector.class, new Detector() {
public MediaType detect(InputStream input, Metadata metadata) {
return MediaType.OCTET_STREAM;
}
});
try {
ContentHandler output = new BodyContentHandler();
InputStream stream = ForkParserIntegrationTest.class.getResourceAsStream("/test-documents/testTXT.txt");
parser.parse(stream, output, new Metadata(), context);
fail("Should have blown up with a non serializable ParseContext");
} catch (TikaException e) {
// Check the right details
assertNotNull(e.getCause());
assertEquals(NotSerializableException.class, e.getCause().getClass());
assertEquals("Unable to serialize ParseContext to pass to the Forked Parser", e.getMessage());
} finally {
parser.close();
}
}
use of org.apache.tika.mime.MediaType in project tika by apache.
the class TikaParsers method parserAsHTML.
private void parserAsHTML(ParserDetails p, boolean withMimeTypes, StringBuffer html, int level) {
html.append("<h");
html.append(level);
html.append(">");
html.append(p.shortName);
html.append("</h");
html.append(level);
html.append(">");
html.append("<p>Class: ");
html.append(p.className);
html.append("</p>");
if (p.isDecorated) {
html.append("<p>Decorated Parser");
if (p.decoratedBy != null)
html.append(" - ").append(p.decoratedBy);
html.append("</p>");
}
if (p.isComposite) {
html.append("<p>Composite Parser</p>");
html.append("<div style=\"margin-left: 1em\">\n");
for (Parser cp : p.childParsers) {
parserAsHTML(new ParserDetails(cp), withMimeTypes, html, level + 1);
}
html.append("</div>\n");
} else if (withMimeTypes) {
html.append("<p>Mime Types:");
html.append("<ul>");
for (MediaType mt : p.supportedTypes) {
html.append("<li>");
html.append(mt.toString());
html.append("</li>");
}
html.append("</ul>");
html.append("</p>");
}
html.append("\n");
}
Aggregations