Coverage Report - org.apache.fulcrum.mimetype.MimeTypeService
 
Classes in this File Line Coverage Branch Coverage Complexity
MimeTypeService
N/A
N/A
1
MimeTypeService$1
100%
1/1
N/A
1
 
 1  
 package org.apache.fulcrum.mimetype;
 2  
 
 3  
 
 4  
 /*
 5  
  * Licensed to the Apache Software Foundation (ASF) under one
 6  
  * or more contributor license agreements.  See the NOTICE file
 7  
  * distributed with this work for additional information
 8  
  * regarding copyright ownership.  The ASF licenses this file
 9  
  * to you under the Apache License, Version 2.0 (the
 10  
  * "License"); you may not use this file except in compliance
 11  
  * with the License.  You may obtain a copy of the License at
 12  
  *
 13  
  *   http://www.apache.org/licenses/LICENSE-2.0
 14  
  *
 15  
  * Unless required by applicable law or agreed to in writing,
 16  
  * software distributed under the License is distributed on an
 17  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 18  
  * KIND, either express or implied.  See the License for the
 19  
  * specific language governing permissions and limitations
 20  
  * under the License.
 21  
  */
 22  
 
 23  
 
 24  
 import java.io.File;
 25  
 import java.util.Locale;
 26  
 
 27  
 import org.apache.fulcrum.mimetype.util.MimeType;
 28  
 
 29  
 /**
 30  
  * The MimeType Service maintains mappings between MIME types and
 31  
  * the corresponding file name extensions, and between locales and
 32  
  * character encodings. The mappings are typically defined in
 33  
  * properties or files located in user's home directory, Java home
 34  
  * directory or the current class jar depending on the implementation.
 35  
  *
 36  
  * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
 37  
  * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
 38  
  * @version $Id: MimeTypeService.java 535465 2007-05-05 06:58:06Z tv $
 39  
  */
 40  
 public interface MimeTypeService
 41  
 {
 42  
     /** Avalon role - used to id the component within the manager */
 43  3
     String ROLE = MimeTypeService.class.getName();
 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  
     public void setContentType(String spec);
 53  
 
 54  
     /**
 55  
      * Gets the MIME content type for a file as a string.
 56  
      *
 57  
      * @param file The file to look up a MIME type mapping for.
 58  
      * @return the MIME type string.
 59  
      */
 60  
     public String getContentType(File file);
 61  
 
 62  
     /**
 63  
      * Gets the MIME content type for a named file as a string.
 64  
      *
 65  
      * @param fileName The name of the file to look up a MIME type
 66  
      * mapping for.
 67  
      * @return the MIME type string.
 68  
      */
 69  
     public String getContentType(String fileName);
 70  
 
 71  
     /**
 72  
      * Gets the MIME content type for a file name extension as a string.
 73  
      *
 74  
      * @param fileName The name of the file to look up a MIME type
 75  
      * mapping for.
 76  
      * @param def The default MIME type to use if no mapping exists.
 77  
      * @return the MIME type string.
 78  
      */
 79  
     public String getContentType(String fileName, String def);
 80  
 
 81  
     /**
 82  
      * Gets the MIME content type for a file.
 83  
      *
 84  
      * @param file the file.
 85  
      * @return the MIME type.
 86  
      */
 87  
     public MimeType getMimeContentType(File file);
 88  
 
 89  
     /**
 90  
      * Gets the MIME content type for a named file.
 91  
      *
 92  
      * @param name the name of the file.
 93  
      * @return the MIME type.
 94  
      */
 95  
     public MimeType getMimeContentType(String name);
 96  
 
 97  
     /**
 98  
      * Gets the MIME content type for a file name extension.
 99  
      *
 100  
      * @param ext the file name extension.
 101  
      * @param def the default type if none is found.
 102  
      * @return the MIME type.
 103  
      */
 104  
     public MimeType getMimeContentType(String ext,
 105  
                                        String def);
 106  
 
 107  
     /**
 108  
      * Gets the default file name extension for a MIME type.
 109  
      * Note that the mappers are called in the reverse order.
 110  
      *
 111  
      * @param type the MIME type as a string.
 112  
      * @return the file name extension or null.
 113  
      */
 114  
     public String getDefaultExtension(String type);
 115  
 
 116  
     /**
 117  
      * Gets the default file name extension for a MIME type.
 118  
      * Note that the mappers are called in the reverse order.
 119  
      *
 120  
      * @param mime the MIME type.
 121  
      * @return the file name extension or null.
 122  
      */
 123  
     public String getDefaultExtension(MimeType mime);
 124  
 
 125  
     /**
 126  
      * Sets a locale-charset mapping.
 127  
      *
 128  
      * @param key the key for the charset.
 129  
      * @param charset the corresponding charset.
 130  
      */
 131  
     public  void setCharSet(String key,
 132  
                             String charset);
 133  
 
 134  
     /**
 135  
      * Gets the charset for a locale. First a locale specific charset
 136  
      * is searched for, then a country specific one and lastly a language
 137  
      * specific one. If none is found, the default charset is returned.
 138  
      *
 139  
      * @param locale the locale.
 140  
      * @return the charset.
 141  
      */
 142  
     public String getCharSet(Locale locale);
 143  
 
 144  
     /**
 145  
      * Gets the charset for a locale with a variant. The search
 146  
      * is performed in the following order:
 147  
      * "lang"_"country"_"variant"="charset",
 148  
      * _"counry"_"variant"="charset",
 149  
      * "lang"__"variant"="charset",
 150  
      * __"variant"="charset",
 151  
      * "lang"_"country"="charset",
 152  
      * _"country"="charset",
 153  
      * "lang"="charset".
 154  
      * If nothing of the above is found, the default charset is returned.
 155  
      *
 156  
      * @param locale the locale.
 157  
      * @param variant a variant field.
 158  
      * @return the charset.
 159  
      */
 160  
     public String getCharSet(Locale locale,
 161  
                              String variant);
 162  
 
 163  
     /**
 164  
      * Gets the charset for a specified key.
 165  
      *
 166  
      * @param key the key for the charset.
 167  
      * @return the found charset or the default one.
 168  
      */
 169  
     public String getCharSet(String key);
 170  
 
 171  
     /**
 172  
      * Gets the charset for a specified key.
 173  
      *
 174  
      * @param key the key for the charset.
 175  
      * @param def the default charset if none is found.
 176  
      * @return the found charset or the given default.
 177  
      */
 178  
     public String getCharSet(String key,
 179  
                              String def);
 180  
 }