View Javadoc

1   package org.apache.turbine.services.mimetype;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 }