I want to use APache Tika\'s MediaType class to compare mediaTypes.
I first use Tika to detect the MediaType. Then I want to start an action according to the MediaTy
What you'll need to do is walk the types hierarchy, until you either find what you want, or run out of things to check. That can be done with recursion, or could be done with a loop
The key method you need is MediaTypeRegistry.getSupertype(MediaType)
Your code would want to be something like:
// Define your media type constants here
MediaType FOO = MediaType.parse("application/foo");
// Work out the file's type
MediaType type = detector.detect(stream, metadata);
// Is it one we want in the tree?
while (type != null && !type.equals(MediaType.OCTET_STREAM)) {
if (type.equals(MediaType.Application_XML)) {
doThingForXML();
} else if (type.equals(MediaType.APPLICATION_ZIP)) {
doThingForZip();
} else if (type.equals(FOO)) {
doThingForFoo();
} else {
// Check parent
type = registry.getSuperType(type);
}
}