+ To speed up MIME type recognition it is added an extra parameter
+ to method FileUtil.getMIMEType(FileObject, String...).
+ Parameter contains one or more MIME types
+ which we are only interested in. It means only
+ MIMEResolver
+ instances which supply at lease one of these MIME types are queried.
+ That's why MIMEResolver
+ abstract class was extended by method
+ getMIMETypes().
+ It has to return a String[]
array of
+ MIME types which can be resolved by this resolver.
+
"jar"
, "zip"
, etc.
* @return the MIME type for the extension, or null
if the extension is unrecognized
- * @deprecated use {@link #getMIMEType(FileObject) getMIMEType(FileObject)} as MIME cannot
+ * @deprecated use {@link #getMIMEType(FileObject, String[]) getMIMEType(FileObject)} as MIME cannot
* be generally detected by file object extension.
*/
@Deprecated
@@ -1111,13 +1111,14 @@
}
/** Resolves MIME type. Registered resolvers are invoked and used to achieve this goal.
- * Resolvers must subclass MIMEResolver. If resolvers don`t recognize MIME type then
+ * Resolvers must subclass MIMEResolver. If resolvers don't recognize MIME type then
* MIME type is obtained for a well-known extension.
* @param fo whose MIME type should be recognized
+ * @param withinMIMETypes an array of MIME types which only should be considered
* @return the MIME type for the FileObject, or null
if the FileObject is unrecognized
*/
- public static String getMIMEType(FileObject fo) {
- String retVal = MIMESupport.findMIMEType(fo, null);
+ public static String getMIMEType(FileObject fo, String... withinMIMETypes) {
+ String retVal = MIMESupport.findMIMEType(fo, null, withinMIMETypes);
if (retVal == null) {
retVal = getMIMEType(fo.getExt());
@@ -1125,7 +1126,7 @@
return retVal;
}
-
+
/** Finds mime type by calling getMIMEType, but
* instead of returning null it fallbacks to default type
* either text/plain or content/unknown (even for folders)
diff --git a/openide.filesystems/src/org/openide/filesystems/MIMEResolver.java b/openide.filesystems/src/org/openide/filesystems/MIMEResolver.java
--- a/openide.filesystems/src/org/openide/filesystems/MIMEResolver.java
+++ b/openide.filesystems/src/org/openide/filesystems/MIMEResolver.java
@@ -64,4 +64,10 @@
* @return recognized MIME type or null if not recognized
*/
public abstract String findMIMEType(FileObject fo);
+
+ /** Returns an array of MIME types which can be resolved by this resolver.
+ * It has to return not empty String array.
+ * @return an array of MIME types which can be resolved by this resolver.
+ */
+ public abstract String[] getMIMETypes();
}
diff --git a/openide.filesystems/src/org/openide/filesystems/MIMESupport.java b/openide.filesystems/src/org/openide/filesystems/MIMESupport.java
--- a/openide.filesystems/src/org/openide/filesystems/MIMESupport.java
+++ b/openide.filesystems/src/org/openide/filesystems/MIMESupport.java
@@ -97,8 +97,9 @@
/** Asks all registered subclasses of MIMEResolver to resolve FileObject passed as parameter.
* @param fo is FileObject, whose MIME should be resolved
* @param def the default value to return or null
+ * @param withinMIMETypes an array of MIME types which only should be considered
* @return MIME type or null if not resolved*/
- static String findMIMEType(FileObject fo, String def) {
+ static String findMIMEType(FileObject fo, String def, String... withinMIMETypes) {
if (!fo.isValid() || fo.isFolder()) {
return null;
}
@@ -121,7 +122,7 @@
lastCfo = EMPTY;
}
- return cfo.getMIMEType(def);
+ return cfo.getMIMEType(def, withinMIMETypes);
} finally {
synchronized (lock) {
lastFo = new WeakReference