blob: fe7836d37dd5b1b9768b20189b3b913d03066257 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package de.danoeh.antennapod.syndication.util;
import org.apache.commons.io.FilenameUtils;
import android.webkit.MimeTypeMap;
/** Utility class for handling MIME-Types of enclosures */
public class SyndTypeUtils {
private final static String VALID_MIMETYPE = "audio/.*" + "|" + "video/.*"
+ "|" + "application/ogg";
private SyndTypeUtils() {
}
public static boolean enclosureTypeValid(String type) {
if (type == null) {
return false;
} else {
return type.matches(VALID_MIMETYPE);
}
}
/**
* Should be used if mime-type of enclosure tag is not supported. This
* method will check if the mime-type of the file extension is supported. If
* the type is not supported, this method will return null.
*/
public static String getValidMimeTypeFromUrl(String url) {
if (url != null) {
String extension = FilenameUtils.getExtension(url);
if (extension != null) {
String type = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension);
if (type != null && enclosureTypeValid(type)) {
return type;
}
}
}
return null;
}
}
|