1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.util;
17
18 import java.util.Enumeration;
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.ResourceBundle;
22
23 /***
24 * @author someda
25 */
26 public class MimeMappings {
27
28 public static final String DEFAULT_CONTENTTYPE = "application/octet-stream";
29
30 private static final String MIME_PATH = "mime";
31 private static ResourceBundle mimeResource;
32
33 private static final Map EXTENSION_MAP;
34
35 static{
36 mimeResource = ResourceBundle.getBundle(MIME_PATH);
37 EXTENSION_MAP = new HashMap();
38
39 Enumeration keys = mimeResource.getKeys();
40 while(keys.hasMoreElements()){
41 String extension = (String)keys.nextElement();
42 String contentType = mimeResource.getString(extension);
43
44 if(EXTENSION_MAP.get(contentType) == null){
45 EXTENSION_MAP.put(contentType,extension);
46 }
47 }
48 }
49
50 public static final String EXTENSION_HTML = "html";
51 public static final String EXTENSION_XWIKI = "wiki";
52 public static final String EXTENSION_XLS = "xls";
53 public static final String EXTENSION_CSV = "csv";
54 public static final String EXTENSION_TGWAR = "tgwar";
55 public static final String EXTENSION_ZIP = "zip";
56 public static final String EXTENSION_TXT = "txt";
57
58 public static final String CONTENTTYPE_HTML = getContentType(EXTENSION_HTML);
59 public static final String CONTENTTYPE_XWIKI = getContentType(EXTENSION_XWIKI);
60 public static final String CONTENTTYPE_XLS = getContentType(EXTENSION_XLS);
61 public static final String CONTENTTYPE_CSV = getContentType(EXTENSION_CSV);
62 public static final String CONTENTTYPE_TXT = getContentType(EXTENSION_TXT);
63
64
65
66 public static String getContentType(String extension){
67 String contentType = (String) mimeResource.getString(extension);
68 if(contentType == null || "".equals(contentType)){
69 contentType = DEFAULT_CONTENTTYPE;
70 }
71 return contentType;
72 }
73
74 public static String getExtension(String contentType){
75 return (String)EXTENSION_MAP.get(contentType);
76 }
77
78 }