📄 projectresourcebundle.java
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.axis.i18n;import org.apache.axis.components.logger.LogFactory;import org.apache.commons.logging.Log;import java.util.Enumeration;import java.util.HashSet;import java.util.Hashtable;import java.util.Iterator;import java.util.Locale;import java.util.MissingResourceException;import java.util.ResourceBundle;/** * <p>Wrapper class for resource bundles. Property files are used to store * resource strings, which are the only types of resources available. * Property files can inherit properties from other files so that * a base property file can be used and a small number of properties * can be over-ridden by another property file. For example you may * create an english version of a resource file named "resource.properties". * You then decide that the British English version of all of the properties * except one are the same, so there is no need to redefine all of the * properties in "resource_en_GB", just the one that is different.</p> * <p>The basename is the name of the property file without the ".properties" * extension.</p> * <p>Properties will be cached for performance.<p> * <p>Property values stored in the property files can also contain dynamic * variables. Any dynamic variable defined in PropertiesUtil.getVariableValue() * can be used (such as {date}), as well as arguments in the form {0}, {1}, etc. * Argument values are specified in the various overloaded getString() methods.</p> * * @author Richard A. Sitze (rsitze@us.ibm.com) * @author Karl Moss (kmoss@macromedia.com) * @author Glen Daniels (gdaniels@apache.org) */public class ProjectResourceBundle extends ResourceBundle { protected static Log log = LogFactory.getLog(ProjectResourceBundle.class.getName()); // The static cache of ResourceBundles. // The key is the 'basename + locale + default locale' // The element is a ResourceBundle object private static final Hashtable bundleCache = new Hashtable(); private static final Locale defaultLocale = Locale.getDefault(); private final ResourceBundle resourceBundle; private final String resourceName; protected Object handleGetObject(String key) throws MissingResourceException { if (log.isDebugEnabled()) { log.debug(this.toString() + "::handleGetObject(" + key + ")"); }// return resourceBundle.handleGetObject(key); Object obj; try { obj = resourceBundle.getObject(key); } catch (MissingResourceException e) { /* catch missing resource, ignore, & return null * if this method doesn't return null, then parents * are not searched */ obj = null; } return obj; } public Enumeration getKeys() { Enumeration myKeys = resourceBundle.getKeys(); if (parent == null) { return myKeys; } else { final HashSet set = new HashSet(); while (myKeys.hasMoreElements()) { set.add(myKeys.nextElement()); } Enumeration pKeys = parent.getKeys(); while (pKeys.hasMoreElements()) { set.add(pKeys.nextElement()); } return new Enumeration() { private Iterator it = set.iterator(); public boolean hasMoreElements() { return it.hasNext(); } public Object nextElement() { return it.next(); } }; } } /** * Construct a new ProjectResourceBundle * * @param projectName The name of the project to which the class belongs. * It must be a proper prefix of the caller's package. * * @param caller The calling class. * This is used to get the package name to further construct * the basename as well as to get the proper ClassLoader. * * @param resourceName The name of the resource without the * ".properties" extension * * @throws MissingResourceException if projectName is not a prefix of * the caller's package name, or if the resource could not be * found/loaded. */ public static ProjectResourceBundle getBundle(String projectName, String packageName, String resourceName) throws MissingResourceException { return getBundle(projectName, packageName, resourceName, null, null, null); } /** * Construct a new ProjectResourceBundle * * @param projectName The name of the project to which the class belongs. * It must be a proper prefix of the caller's package. * * @param caller The calling class. * This is used to get the package name to further construct * the basename as well as to get the proper ClassLoader. * * @param resourceName The name of the resource without the * ".properties" extension * * @throws MissingResourceException if projectName is not a prefix of * the caller's package name, or if the resource could not be * found/loaded. */ public static ProjectResourceBundle getBundle(String projectName, Class caller, String resourceName, Locale locale) throws MissingResourceException { return getBundle(projectName, caller, resourceName, locale, null); } /** * Construct a new ProjectResourceBundle * * @param projectName The name of the project to which the class belongs. * It must be a proper prefix of the caller's package. * * @param caller The calling class. * This is used to get the package name to further construct * the basename as well as to get the proper ClassLoader. * * @param resourceName The name of the resource without the * ".properties" extension * * @param locale The locale * * @throws MissingResourceException if projectName is not a prefix of * the caller's package name, or if the resource could not be * found/loaded. */ public static ProjectResourceBundle getBundle(String projectName, String packageName, String resourceName, Locale locale, ClassLoader loader) throws MissingResourceException { return getBundle(projectName, packageName, resourceName, locale, loader, null); } /** * Construct a new ProjectResourceBundle * * @param projectName The name of the project to which the class belongs. * It must be a proper prefix of the caller's package. * * @param caller The calling class. * This is used to get the package name to further construct * the basename as well as to get the proper ClassLoader. * * @param resourceName The name of the resource without the * ".properties" extension * * @param locale The locale * * @param extendsBundle If non-null, then this ExtendMessages will * default to extendsBundle. * * @throws MissingResourceException if projectName is not a prefix of * the caller's package name, or if the resource could not be * found/loaded. */ public static ProjectResourceBundle getBundle(String projectName, Class caller, String resourceName, Locale locale, ResourceBundle extendsBundle) throws MissingResourceException { return getBundle(projectName, getPackage(caller.getClass().getName()), resourceName, locale, caller.getClass().getClassLoader(), extendsBundle); } /** * Construct a new ProjectResourceBundle * * @param projectName The name of the project to which the class belongs.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -