2009-05-21 05:56:25 -04:00
|
|
|
|
|
|
|
package net.sourceforge.filebot;
|
|
|
|
|
|
|
|
|
|
|
|
import static java.util.Collections.*;
|
|
|
|
|
2009-08-10 07:46:24 -04:00
|
|
|
import java.io.FileFilter;
|
2009-05-21 05:56:25 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
import javax.xml.bind.annotation.XmlAttribute;
|
|
|
|
import javax.xml.bind.annotation.XmlElement;
|
|
|
|
import javax.xml.bind.annotation.XmlRootElement;
|
|
|
|
|
|
|
|
import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
|
|
|
|
|
|
|
|
|
|
|
|
@XmlRootElement(name = "media-types")
|
|
|
|
public class MediaTypes {
|
|
|
|
|
|
|
|
@XmlElement(name = "type")
|
|
|
|
private Type[] types;
|
|
|
|
|
2009-06-13 05:53:48 -04:00
|
|
|
|
2009-05-21 05:56:25 -04:00
|
|
|
private static class Type {
|
2009-06-13 05:53:48 -04:00
|
|
|
|
2009-05-21 05:56:25 -04:00
|
|
|
@XmlAttribute(name = "name")
|
|
|
|
private String name;
|
|
|
|
|
|
|
|
@XmlElement(name = "extension")
|
|
|
|
private String[] extensions;
|
|
|
|
}
|
|
|
|
|
2009-06-13 05:53:48 -04:00
|
|
|
|
2009-08-10 07:46:24 -04:00
|
|
|
private static final MediaTypes defaultInstance = unmarshal();
|
2009-05-21 05:56:25 -04:00
|
|
|
|
2009-06-13 05:53:48 -04:00
|
|
|
|
2009-07-10 14:47:56 -04:00
|
|
|
private static MediaTypes unmarshal() {
|
|
|
|
try {
|
|
|
|
Unmarshaller unmarshaller = JAXBContext.newInstance(MediaTypes.class).createUnmarshaller();
|
|
|
|
return (MediaTypes) unmarshaller.unmarshal(MediaTypes.class.getResource("media.types"));
|
|
|
|
} catch (JAXBException e) {
|
|
|
|
throw new RuntimeException(e);
|
2009-05-21 05:56:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-10 07:46:24 -04:00
|
|
|
public List<String> getExtensionList(String name) {
|
2009-06-27 12:02:31 -04:00
|
|
|
List<String> list = new ArrayList<String>();
|
2009-05-21 05:56:25 -04:00
|
|
|
|
2009-08-10 07:46:24 -04:00
|
|
|
for (Type type : defaultInstance.types) {
|
2009-05-24 09:25:49 -04:00
|
|
|
if (type.name.startsWith(name)) {
|
2009-06-27 12:02:31 -04:00
|
|
|
addAll(list, type.extensions);
|
2009-05-21 05:56:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-27 12:02:31 -04:00
|
|
|
return list;
|
2009-05-21 05:56:25 -04:00
|
|
|
}
|
|
|
|
|
2009-08-10 07:46:24 -04:00
|
|
|
|
|
|
|
public FileFilter getFilter(String name) {
|
|
|
|
return new ExtensionFileFilter(getExtensionList(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static MediaTypes getDefault() {
|
|
|
|
return defaultInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static ExtensionFileFilter getDefaultFilter(String name) {
|
|
|
|
return new ExtensionFileFilter(getDefault().getExtensionList(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// some convenience filters
|
|
|
|
public static final ExtensionFileFilter AUDIO_FILES = MediaTypes.getDefaultFilter("audio");
|
|
|
|
public static final ExtensionFileFilter VIDEO_FILES = MediaTypes.getDefaultFilter("video");
|
|
|
|
public static final ExtensionFileFilter SUBTITLE_FILES = MediaTypes.getDefaultFilter("subtitle");
|
2009-05-21 05:56:25 -04:00
|
|
|
}
|