1 package org.apache.turbine.services.mimetype;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Locale;
24
25 import org.apache.turbine.services.Service;
26 import org.apache.turbine.services.mimetype.util.MimeType;
27
28 /***
29 * The MimeType Service maintains mappings between MIME types and
30 * the corresponding file name extensions, and between locales and
31 * character encodings. The mappings are typically defined in
32 * properties or files located in user's home directory, Java home
33 * directory or the current class jar depending on the implementation.
34 *
35 * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
36 * @version $Id: MimeTypeService.java 534527 2007-05-02 16:10:59Z tv $
37 */
38 public interface MimeTypeService extends Service
39 {
40 /***
41 * The name of the service.
42 */
43 String SERVICE_NAME = "MimeTypeService";
44
45 /***
46 * Sets a MIME content type mapping to extensions to the map.
47 * The extension is specified by a MIME type name followed
48 * by a list of file name extensions separated by a whitespace.
49 *
50 * @param spec a MIME type extension specification to add.
51 */
52 void setContentType(String spec);
53
54 /***
55 * Gets the MIME content type for a file as a string.
56 *
57 * @param file the file.
58 * @return the MIME type string.
59 */
60 String getContentType(File file);
61
62 /***
63 * Gets the MIME content type for a named file as a string.
64 *
65 * @param name the name of the file.
66 * @return the MIME type string.
67 */
68 String getContentType(String name);
69
70 /***
71 * Gets the MIME content type for a file name extension as a string.
72 *
73 * @param ext the file name extension.
74 * @param def the default type if none is found.
75 * @return the MIME type string.
76 */
77 String getContentType(String ext,
78 String def);
79
80 /***
81 * Gets the MIME content type for a file.
82 *
83 * @param file the file.
84 * @return the MIME type.
85 */
86 MimeType getMimeContentType(File file);
87
88 /***
89 * Gets the MIME content type for a named file.
90 *
91 * @param name the name of the file.
92 * @return the MIME type.
93 */
94 MimeType getMimeContentType(String name);
95
96 /***
97 * Gets the MIME content type for a file name extension.
98 *
99 * @param ext the file name extension.
100 * @param def the default type if none is found.
101 * @return the MIME type.
102 */
103 MimeType getMimeContentType(String ext,
104 String def);
105
106 /***
107 * Gets the default file name extension for a MIME type.
108 * Note that the mappers are called in the reverse order.
109 *
110 * @param type the MIME type as a string.
111 * @return the file name extension or null.
112 */
113 String getDefaultExtension(String type);
114
115 /***
116 * Gets the default file name extension for a MIME type.
117 * Note that the mappers are called in the reverse order.
118 *
119 * @param mime the MIME type.
120 * @return the file name extension or null.
121 */
122 String getDefaultExtension(MimeType mime);
123
124 /***
125 * Sets a locale-charset mapping.
126 *
127 * @param key the key for the charset.
128 * @param charset the corresponding charset.
129 */
130 void setCharSet(String key,
131 String charset);
132
133 /***
134 * Gets the charset for a locale. First a locale specific charset
135 * is searched for, then a country specific one and lastly a language
136 * specific one. If none is found, the default charset is returned.
137 *
138 * @param locale the locale.
139 * @return the charset.
140 */
141 String getCharSet(Locale locale);
142
143 /***
144 * Gets the charset for a locale with a variant. The search
145 * is performed in the following order:
146 * "lang"_"country"_"variant"="charset",
147 * _"counry"_"variant"="charset",
148 * "lang"__"variant"="charset",
149 * __"variant"="charset",
150 * "lang"_"country"="charset",
151 * _"country"="charset",
152 * "lang"="charset".
153 * If nothing of the above is found, the default charset is returned.
154 *
155 * @param locale the locale.
156 * @param variant a variant field.
157 * @return the charset.
158 */
159 String getCharSet(Locale locale,
160 String variant);
161
162 /***
163 * Gets the charset for a specified key.
164 *
165 * @param key the key for the charset.
166 * @return the found charset or the default one.
167 */
168 String getCharSet(String key);
169
170 /***
171 * Gets the charset for a specified key.
172 *
173 * @param key the key for the charset.
174 * @param def the default charset if none is found.
175 * @return the found charset or the given default.
176 */
177 String getCharSet(String key,
178 String def);
179 }