You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ju...@apache.org on 2007/09/13 09:16:55 UTC
svn commit: r575199 -
/incubator/tika/trunk/src/main/java/org/apache/tika/utils/MimeTypesUtils.java
Author: jukka
Date: Thu Sep 13 00:16:54 2007
New Revision: 575199
URL: http://svn.apache.org/viewvc?rev=575199&view=rev
Log:
TIKA-12: Support MIME type detection based on a URL. Patch from Keith Bennett.
Modified:
incubator/tika/trunk/src/main/java/org/apache/tika/utils/MimeTypesUtils.java
Modified: incubator/tika/trunk/src/main/java/org/apache/tika/utils/MimeTypesUtils.java
URL: http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/utils/MimeTypesUtils.java?rev=575199&r1=575198&r2=575199&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/utils/MimeTypesUtils.java (original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/utils/MimeTypesUtils.java Thu Sep 13 00:16:54 2007
@@ -17,17 +17,23 @@
package org.apache.tika.utils;
import java.io.File;
+import java.net.URL;
/**
- * Detect mime type from file
- *
- * @author Rida Benjelloun (ridabenjelloun@apache.org)
+ * Detect the MIME type of a document from file name given as
+ * a String, a File, or a URL.
*/
public class MimeTypesUtils {
- public static String getMimeType(File file) {
+ /**
+ * Returns the MIME type as specified by the ending of the name.
+ *
+ * @param name the resource name, e.g. "filename.pdf"
+ * @return the MIME type, e.g. "application/pdf"
+ */
+ public static String getMimeType(String name) {
// FIXME: See TIKA-8
- String name = file.getName().toLowerCase();
+ name = name.toLowerCase();
if (name.endsWith(".txt")) {
return "text/plain";
} else if (name.endsWith(".pdf")) {
@@ -51,6 +57,27 @@
} else {
return "application/octet-stream";
}
+ }
+
+ /**
+ * Returns the MIME type as specified by the ending of the file's name.
+ *
+ * @param file the file to test, e.g. new File("filename.pdf")
+ * @return the MIME type, e.g. "application/pdf"
+ */
+ public static String getMimeType(File file) {
+ return getMimeType(file.getName());
+ }
+
+
+ /**
+ * Returns the MIME type as specified by the ending of the URL's file name.
+ *
+ * @param url the url to test, e.g. new URL("http://mydomain.com/filename.pdf")
+ * @return the MIME type, e.g. "application/pdf"
+ */
+ public static String getMimeType(URL url) {
+ return getMimeType(url.getPath());
}
}