View Javadoc
1 package org.apache.turbine.services.mimetype; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 import java.io.File; 58 import java.util.Locale; 59 60 import org.apache.turbine.services.TurbineServices; 61 import org.apache.turbine.services.mimetype.util.MimeType; 62 63 /*** 64 * This is a static accessor to MIME types and charsets. 65 * 66 * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a> 67 * @version $Id: TurbineMimeTypes.java,v 1.1.1.1 2001/08/16 05:09:07 jvanzyl Exp $ 68 */ 69 public abstract class TurbineMimeTypes 70 { 71 /*** 72 * Gets the MIME content type for a file as a string. 73 * 74 * @param file the file. 75 * @return the MIME type string. 76 */ 77 public static String getContentType(File file) 78 { 79 return getService().getContentType(file); 80 } 81 82 /*** 83 * Gets the MIME content type for a named file as a string. 84 * 85 * @param name the name of the file. 86 * @return the MIME type string. 87 */ 88 public static String getContentType(String name) 89 { 90 return getService().getContentType(name); 91 } 92 93 /*** 94 * Gets the MIME content type for a file name extension as a string. 95 * 96 * @param ext the file name extension. 97 * @param def the default type if none is found. 98 * @return the MIME type string. 99 */ 100 public static String getContentType(String ext, 101 String def) 102 { 103 return getService().getContentType(ext,def); 104 } 105 106 /*** 107 * Gets the MIME content type for a file. 108 * 109 * @param file the file. 110 * @return the MIME type. 111 */ 112 public static MimeType getMimeContentType(File file) 113 { 114 return getService().getMimeContentType(file); 115 } 116 117 /*** 118 * Gets the MIME content type for a named file. 119 * 120 * @param name the name of the file. 121 * @return the MIME type. 122 */ 123 public static MimeType getMimeContentType(String name) 124 { 125 return getService().getMimeContentType(name); 126 } 127 128 /*** 129 * Gets the MIME content type for a file name extension. 130 * 131 * @param ext the file name extension. 132 * @param def the default type if none is found. 133 * @return the MIME type. 134 */ 135 public static MimeType getMimeContentType(String ext, 136 String def) 137 { 138 return getService().getMimeContentType(ext,def); 139 } 140 141 /*** 142 * Gets the default file name extension for a MIME type. 143 * Note that the mappers are called in the reverse order. 144 * 145 * @param mime the MIME type. 146 * @return the file name extension or null. 147 */ 148 public static String getDefaultExtension(MimeType mime) 149 { 150 return getService().getDefaultExtension(mime); 151 } 152 153 /*** 154 * Gets the charset for a locale. First a locale specific charset 155 * is searched for, then a country specific one and lastly a language 156 * specific one. If none is found, the default charset is returned. 157 * 158 * @param locale the locale. 159 * @return the charset. 160 */ 161 public static String getCharSet(Locale locale) 162 { 163 return getService().getCharSet(locale); 164 } 165 166 /*** 167 * Gets the charset for a locale with a variant. The search 168 * is performed in the following order: 169 * "lang"_"country"_"variant"="charset", 170 * _"counry"_"variant"="charset", 171 * "lang"__"variant"="charset", 172 * __"variant"="charset", 173 * "lang"_"country"="charset", 174 * _"country"="charset", 175 * "lang"="charset". 176 * If nothing of the above is found, the default charset is returned. 177 * 178 * @param locale the locale. 179 * @param variant a variant field. 180 * @return the charset. 181 */ 182 public static String getCharSet(Locale locale, 183 String variant) 184 { 185 return getService().getCharSet(locale,variant); 186 } 187 188 /*** 189 * Gets the charset for a specified key. 190 * 191 * @param key the key for the charset. 192 * @return the found charset or the default one. 193 */ 194 public static String getCharSet(String key) 195 { 196 return getService().getCharSet(key); 197 } 198 199 /*** 200 * Gets the charset for a specified key. 201 * 202 * @param key the key for the charset. 203 * @param def the default charset if none is found. 204 * @return the found charset or the given default. 205 */ 206 public static String getCharSet(String key, 207 String def) 208 { 209 return getService().getCharSet(key,def); 210 } 211 212 /*** 213 * Gets the MIME type service implementation. 214 * 215 * @return the MIME type service implementation. 216 */ 217 protected static MimeTypeService getService() 218 { 219 return (MimeTypeService) TurbineServices. 220 getInstance().getService(MimeTypeService.SERVICE_NAME); 221 } 222 }

This page was automatically generated by Maven