001: package org.apache.turbine.services.mimetype;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.io.File;
023: import java.util.Locale;
024:
025: import org.apache.turbine.services.Service;
026: import org.apache.turbine.services.mimetype.util.MimeType;
027:
028: /**
029: * The MimeType Service maintains mappings between MIME types and
030: * the corresponding file name extensions, and between locales and
031: * character encodings. The mappings are typically defined in
032: * properties or files located in user's home directory, Java home
033: * directory or the current class jar depending on the implementation.
034: *
035: * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
036: * @version $Id: MimeTypeService.java 534527 2007-05-02 16:10:59Z tv $
037: */
038: public interface MimeTypeService extends Service {
039: /**
040: * The name of the service.
041: */
042: String SERVICE_NAME = "MimeTypeService";
043:
044: /**
045: * Sets a MIME content type mapping to extensions to the map.
046: * The extension is specified by a MIME type name followed
047: * by a list of file name extensions separated by a whitespace.
048: *
049: * @param spec a MIME type extension specification to add.
050: */
051: void setContentType(String spec);
052:
053: /**
054: * Gets the MIME content type for a file as a string.
055: *
056: * @param file the file.
057: * @return the MIME type string.
058: */
059: String getContentType(File file);
060:
061: /**
062: * Gets the MIME content type for a named file as a string.
063: *
064: * @param name the name of the file.
065: * @return the MIME type string.
066: */
067: String getContentType(String name);
068:
069: /**
070: * Gets the MIME content type for a file name extension as a string.
071: *
072: * @param ext the file name extension.
073: * @param def the default type if none is found.
074: * @return the MIME type string.
075: */
076: String getContentType(String ext, String def);
077:
078: /**
079: * Gets the MIME content type for a file.
080: *
081: * @param file the file.
082: * @return the MIME type.
083: */
084: MimeType getMimeContentType(File file);
085:
086: /**
087: * Gets the MIME content type for a named file.
088: *
089: * @param name the name of the file.
090: * @return the MIME type.
091: */
092: MimeType getMimeContentType(String name);
093:
094: /**
095: * Gets the MIME content type for a file name extension.
096: *
097: * @param ext the file name extension.
098: * @param def the default type if none is found.
099: * @return the MIME type.
100: */
101: MimeType getMimeContentType(String ext, 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, String charset);
128:
129: /**
130: * Gets the charset for a locale. First a locale specific charset
131: * is searched for, then a country specific one and lastly a language
132: * specific one. If none is found, the default charset is returned.
133: *
134: * @param locale the locale.
135: * @return the charset.
136: */
137: String getCharSet(Locale locale);
138:
139: /**
140: * Gets the charset for a locale with a variant. The search
141: * is performed in the following order:
142: * "lang"_"country"_"variant"="charset",
143: * _"counry"_"variant"="charset",
144: * "lang"__"variant"="charset",
145: * __"variant"="charset",
146: * "lang"_"country"="charset",
147: * _"country"="charset",
148: * "lang"="charset".
149: * If nothing of the above is found, the default charset is returned.
150: *
151: * @param locale the locale.
152: * @param variant a variant field.
153: * @return the charset.
154: */
155: String getCharSet(Locale locale, String variant);
156:
157: /**
158: * Gets the charset for a specified key.
159: *
160: * @param key the key for the charset.
161: * @return the found charset or the default one.
162: */
163: String getCharSet(String key);
164:
165: /**
166: * Gets the charset for a specified key.
167: *
168: * @param key the key for the charset.
169: * @param def the default charset if none is found.
170: * @return the found charset or the given default.
171: */
172: String getCharSet(String key, String def);
173: }
|