01: package org.claros.intouch.webmail.controllers;
02:
03: import java.io.File;
04: import java.io.FileInputStream;
05: import java.util.Locale;
06: import java.util.Properties;
07:
08: import org.claros.commons.configuration.Paths;
09:
10: public class IconController {
11: private static Properties prop = new Properties();
12: private static String defaultIcon = "binary.png";
13: private static Locale loc = new Locale("en", "US");
14:
15: static {
16: try {
17: FileInputStream is = new FileInputStream(new File(Paths
18: .getCfgFolder()
19: + "/mime.properties"));
20: prop.load(is);
21: is.close();
22: } catch (Exception e) {
23: e.printStackTrace();
24: }
25:
26: }
27:
28: /**
29: *
30: * @param mime
31: * @return
32: */
33: public static String findIcon(String mime) {
34: if (mime == null) {
35: return defaultIcon;
36: }
37: mime = mime.toLowerCase(loc).trim();
38: if (mime.indexOf(";") > 0) {
39: mime = mime.substring(0, mime.indexOf(";"));
40: }
41: if (mime.indexOf(" ") > 0) {
42: mime = mime.substring(0, mime.indexOf(" "));
43: }
44:
45: String ico = prop.getProperty(mime);
46: if (ico == null) {
47: if (mime.indexOf("/") > 0) {
48: String mimeType = mime.substring(0, mime.indexOf("/"));
49: ico = prop.getProperty(mimeType + "/*", defaultIcon);
50: }
51: }
52: return ico;
53: }
54: }
|