KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > mimetype > MimeTypeService


1 package org.apache.turbine.services.mimetype;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.File JavaDoc;
20 import java.util.Locale JavaDoc;
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,v 1.4.2.2 2004/05/20 03:06:50 seade Exp $
34  */

35 public interface MimeTypeService extends Service
36 {
37     /**
38      * The name of the service.
39      */

40     String JavaDoc 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 JavaDoc 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 JavaDoc getContentType(File JavaDoc 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 JavaDoc getContentType(String JavaDoc 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 JavaDoc getContentType(String JavaDoc ext,
75                           String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc ext,
101                                 String JavaDoc 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 JavaDoc getDefaultExtension(String JavaDoc 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 JavaDoc 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 JavaDoc key,
128                     String JavaDoc 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 JavaDoc getCharSet(Locale JavaDoc 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 JavaDoc getCharSet(Locale JavaDoc locale,
157                       String JavaDoc 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 JavaDoc getCharSet(String JavaDoc 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 JavaDoc getCharSet(String JavaDoc key,
175                       String JavaDoc def);
176 }
177
Popular Tags