+ To speed up MIME type recognition it is added an extra parameter + to method FileUtil.getMIMEType(FileObject, String...). + We can supply one or more MIME types which we are only interested in. + Module writers have to override + MIMEResolver.getMIMETypes(). +
+"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
@@ -1114,10 +1114,17 @@
* 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. Only resolvers whose
+ * {@link MIMEResolver#getMIMETypes} contain one or more of the requested
+ * MIME types will be asked if they recognize the file. It is possible for
+ * the resulting MIME type to not be a member of this list.
* @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) {
+ if(withinMIMETypes == null) {
+ throw new IllegalArgumentException("MIME types parameter cannot be null"); //NOI18N
+ }
+ String retVal = MIMESupport.findMIMEType(fo, null, withinMIMETypes);
if (retVal == null) {
retVal = getMIMEType(fo.getExt());
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
@@ -57,6 +57,20 @@
* @author rmatous
*/
public abstract class MIMEResolver {
+
+ private String[] resolvableMIMETypes = null;
+
+ /** Creates a new MIMEResolver.
+ * @param mimeTypes an array of MIME types which can be resolved by this resolver.
+ */
+ public MIMEResolver(String... mimeTypes) {
+ resolvableMIMETypes = mimeTypes;
+ }
+
+ /** Creates a new MIMEResolver. */
+ public MIMEResolver() {
+ }
+
/**
* Resolves FileObject and returns recognized MIME type
* @param fo is FileObject which should be resolved (This FileObject is not
@@ -64,4 +78,11 @@
* @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.
+ * @return a non-empty array of MIME types
+ */
+ String[] getMIMETypes() {
+ return resolvableMIMETypes;
+ }
}
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