1:
30:
31: package ;
32:
33: import ;
34:
35:
40: public class DefaultMimeRegistry implements MimeRegistry
41: {
42: public DefaultMimeRegistry()
43: {
44: }
45:
46: public String getMimeType(final ContentItem item)
47: {
48: final String name = item.getName();
49: if (name == null)
50: {
51: return "application/octet-stream";
52: }
53: if (StringUtils.endsWithIgnoreCase(name, ".png"))
54: {
55: return "image/png";
56: }
57: if (StringUtils.endsWithIgnoreCase(name, ".jpg"))
58: {
59: return "image/jpeg";
60: }
61: if (StringUtils.endsWithIgnoreCase(name, ".jpeg"))
62: {
63: return "image/jpeg";
64: }
65: if (StringUtils.endsWithIgnoreCase(name, ".gif"))
66: {
67: return "image/gif";
68: }
69: if (StringUtils.endsWithIgnoreCase(name, ".pdf"))
70: {
71: return "application/pdf";
72: }
73: if (StringUtils.endsWithIgnoreCase(name, ".txt"))
74: {
75: return "text/plain";
76: }
77: if (StringUtils.endsWithIgnoreCase(name, ".html"))
78: {
79: return "text/html";
80: }
81: if (StringUtils.endsWithIgnoreCase(name, ".htm"))
82: {
83: return "text/html";
84: }
85: if (StringUtils.endsWithIgnoreCase(name, ".css"))
86: {
87: return "text/css";
88: }
89: return "application/octet-stream";
90: }
91:
92: public String getSuffix(final String mimeType)
93: {
94:
95: if ("image/png".equals(mimeType))
96: {
97: return "png";
98: }
99: if ("image/jpeg".equals(mimeType))
100: {
101: return "jpg";
102: }
103: if ("image/jpg".equals(mimeType))
104: {
105: return "jpg";
106: }
107: if ("image/gif".equals(mimeType))
108: {
109: return "gif";
110: }
111: if ("text/html".equals(mimeType))
112: {
113: return "html";
114: }
115: if ("text/plain".equals(mimeType))
116: {
117: return "txt";
118: }
119: if ("text/css".equals(mimeType))
120: {
121: return "css";
122: }
123: if ("application/pdf".equals(mimeType))
124: {
125: return "pdf";
126: }
127: return "dat";
128: }
129: }