* expose file media.types entry as {mediaType} binding

This commit is contained in:
Reinhard Pointner 2013-12-22 08:33:19 +00:00
parent 1525623ccd
commit 30d3134f81
3 changed files with 36 additions and 26 deletions

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot; package net.sourceforge.filebot;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.sourceforge.tuned.XPathUtilities.*; import static net.sourceforge.tuned.XPathUtilities.*;
@ -18,12 +16,10 @@ import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
public class MediaTypes { public class MediaTypes {
private static final MediaTypes defaultInstance = parseDefault(); private static final MediaTypes defaultInstance = parseDefault();
private static MediaTypes parseDefault() { private static MediaTypes parseDefault() {
try { try {
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(MediaTypes.class.getResourceAsStream("media.types")); Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(MediaTypes.class.getResourceAsStream("media.types"));
@ -47,12 +43,10 @@ public class MediaTypes {
private Map<String, List<String>> types; private Map<String, List<String>> types;
private Map<String, ExtensionFileFilter> filters = synchronizedMap(new HashMap<String, ExtensionFileFilter>()); private Map<String, ExtensionFileFilter> filters = synchronizedMap(new HashMap<String, ExtensionFileFilter>());
public MediaTypes(Map<String, List<String>> types) { public MediaTypes(Map<String, List<String>> types) {
this.types = types; this.types = types;
} }
public List<String> getExtensionList(String name) { public List<String> getExtensionList(String name) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
@ -65,7 +59,6 @@ public class MediaTypes {
return list; return list;
} }
public ExtensionFileFilter getFilter(String name) { public ExtensionFileFilter getFilter(String name) {
ExtensionFileFilter filter = filters.get(name); ExtensionFileFilter filter = filters.get(name);
@ -77,11 +70,22 @@ public class MediaTypes {
return filter; return filter;
} }
public static MediaTypes getDefault() { public static MediaTypes getDefault() {
return defaultInstance; return defaultInstance;
} }
public Map<String, List<String>> getTypes() {
return types;
}
public String getMediaType(String extension) {
for (Entry<String, List<String>> it : getTypes().entrySet()) {
if (it.getValue().contains(extension)) {
return it.getKey();
}
}
return null;
}
public static ExtensionFileFilter getDefaultFilter(String name) { public static ExtensionFileFilter getDefaultFilter(String name) {
return defaultInstance.getFilter(name); return defaultInstance.getFilter(name);

View File

@ -27,6 +27,7 @@ import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import net.sourceforge.filebot.Cache; import net.sourceforge.filebot.Cache;
import net.sourceforge.filebot.MediaTypes;
import net.sourceforge.filebot.WebServices; import net.sourceforge.filebot.WebServices;
import net.sourceforge.filebot.hash.HashType; import net.sourceforge.filebot.hash.HashType;
import net.sourceforge.filebot.media.MetaAttributes; import net.sourceforge.filebot.media.MetaAttributes;
@ -626,6 +627,11 @@ public class MediaBindingBean {
return null; return null;
} }
@Define("mediaType")
public List<String> getMediaType() throws Exception {
return asList(MediaTypes.getDefault().getMediaType(getExtension()).split("/")); // format engine does not allow / in binding value
}
@Define("file") @Define("file")
public File getMediaFile() { public File getMediaFile() {
return mediaFile; return mediaFile;

View File

@ -225,7 +225,7 @@ public class FormatDialog extends JDialog {
// initialize window properties // initialize window properties
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setSize(620, 445); setSize(650, 450);
// initialize data // initialize data
setState(initMode, lockOnBinding != null ? lockOnBinding : restoreSample(initMode), lockOnBinding != null); setState(initMode, lockOnBinding != null ? lockOnBinding : restoreSample(initMode), lockOnBinding != null);