Author: jukka
Date: Sun Sep 27 18:51:33 2009
New Revision: 819372
URL: http://svn.apache.org/viewvc?rev=819372&view=rev
Log:
TIKA-269: Ease of use -facade for Tika
Support the Tika.detect() contract that allows a full URI or path as the
resource name.
Modified:
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypes.java
Modified:
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypes.java
URL:
http://svn.apache.org/viewvc/lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypes.java?rev=819372&r1=819371&r2=819372&view=diff
==============================================================================
---
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypes.java
(original)
+++
lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MimeTypes.java
Sun Sep 27 18:51:33 2009
@@ -21,6 +21,8 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
@@ -520,9 +522,27 @@
// Get type based on resourceName hint (if available)
String resourceName = metadata.get(Metadata.RESOURCE_NAME_KEY);
if (resourceName != null) {
- MimeType hint = getMimeType(resourceName);
- if (hint.isDescendantOf(type)) {
- type = hint;
+ String name = null;
+
+ // Deal with a URI or a path name in as the resource name
+ try {
+ URI uri = new URI(resourceName);
+ String path = uri.getPath();
+ if (path != null) {
+ int slash = path.lastIndexOf('/');
+ if (slash + 1 < path.length()) {
+ name = path.substring(slash + 1);
+ }
+ }
+ } catch (URISyntaxException e) {
+ name = resourceName;
+ }
+
+ if (name != null) {
+ MimeType hint = getMimeType(name);
+ if (hint.isDescendantOf(type)) {
+ type = hint;
+ }
}
}