View Javadoc
1 package org.apache.turbine.services.localization; 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.util.Locale; 58 import java.util.ResourceBundle; 59 import javax.servlet.http.HttpServletRequest; 60 61 import org.apache.turbine.services.Service; 62 63 /*** 64 * Provides localization functionality using the interface provided by 65 * <code>ResourceBundle</code>. 66 * 67 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> 68 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> 69 * @version $Id: LocalizationService.java,v 1.4 2002/02/27 17:17:23 dlr Exp $ 70 */ 71 public interface LocalizationService 72 extends Service 73 { 74 /*** 75 * The name of this service. 76 */ 77 public static final String SERVICE_NAME = "LocalizationService"; 78 79 /*** 80 * A constant for the HTTP <code>Accept-Language</code> header. 81 */ 82 public static final String ACCEPT_LANGUAGE = "Accept-Language"; 83 84 /*** 85 * Retrieves the name of the default bundle (as specified in the 86 * config file), or the first in the list if there are more than 87 * one. 88 */ 89 public String getDefaultBundleName(); 90 91 /*** 92 * Convenience method to get a default ResourceBundle. 93 * 94 * @return A localized ResourceBundle. 95 */ 96 public ResourceBundle getBundle(); 97 98 /*** 99 * Convenience method to get a ResourceBundle based on name. 100 * 101 * @param bundleName Name of bundle. 102 * @return A localized ResourceBundle. 103 */ 104 public ResourceBundle getBundle(String bundleName); 105 106 /*** 107 * Convenience method to get a ResourceBundle based on name and 108 * HTTP Accept-Language header. 109 * 110 * @param bundleName Name of bundle. 111 * @param languageHeader A String with the language header. 112 * @return A localized ResourceBundle. 113 */ 114 public ResourceBundle getBundle(String bundleName, String languageHeader); 115 116 /*** 117 * Convenience method to get a ResourceBundle based on HTTP 118 * Accept-Language header in HttpServletRequest. 119 * 120 * @param req The HTTP request to parse the 121 * <code>Accept-Language</code> of. 122 * @return A localized ResourceBundle. 123 */ 124 public ResourceBundle getBundle (HttpServletRequest req); 125 126 /*** 127 * Convenience method to get a ResourceBundle based on name and 128 * HTTP Accept-Language header in HttpServletRequest. 129 * 130 * @param bundleName Name of bundle. 131 * @param req The HTTP request to parse the 132 * <code>Accept-Language</code> of. 133 * @return A localized ResourceBundle. 134 */ 135 public ResourceBundle getBundle(String bundleName, HttpServletRequest req); 136 137 /*** 138 * Convenience method to get a ResourceBundle based on name and 139 * Locale. 140 * 141 * @param bundleName Name of bundle. 142 * @param locale A Locale. 143 * @return A localized ResourceBundle. 144 */ 145 public ResourceBundle getBundle(String bundleName, Locale locale); 146 147 /*** 148 * Attempts to pull the <code>Accept-Language</code> header out of 149 * the <code>HttpServletRequest</code> object and then parse it. 150 * If the header is not present, it will return a 151 * <code>null</code> <code>Locale</code>. 152 * 153 * @param req The HTTP request to parse the 154 * <code>Accept-Language</code> of. 155 * @return The parsed locale. 156 */ 157 public Locale getLocale(HttpServletRequest req); 158 159 /*** 160 * This method parses the <code>Accept-Language</code> header and 161 * attempts to create a <code>Locale</code> out of it. 162 * 163 * @param languageHeader The <code>Accept-Language</code> HTTP 164 * header. 165 * @return The parsed locale. 166 */ 167 public Locale getLocale(String languageHeader); 168 169 /*** 170 * This method sets the name of the defaultBundle. 171 * 172 * @param defaultBundle Name of default bundle. 173 */ 174 public void setBundle(String defaultBundle); 175 176 177 /*** 178 * Tries very hard to return a value, looking first in the 179 * specified bundle, then searching list of default bundles 180 * (giving precedence to earlier bundles over later bundles). 181 * 182 * @param bundleName Name of the bundle to look in first. 183 * @param locale Locale to get text for. 184 * @param key Name of the text to retrieve. 185 * @return Localized text. 186 */ 187 public String getString(String bundleName, Locale locale, String key); 188 189 }

This page was automatically generated by Maven