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