aoqi@0: /* aoqi@0: * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * aoqi@0: * This code is subject to the freebxml License, Version 1.1 aoqi@0: * aoqi@0: * Copyright (c) 2001 - 2005 freebxml.org. All rights reserved. aoqi@0: * aoqi@0: * $Header: /zpool01/javanet/scm/svn/tmp/cvs2svn/fi/FastInfoset/src/com/sun/xml/internal/fastinfoset/AbstractResourceBundle.java,v 1.3.2.4 2009-05-13 08:53:01 oleksiys Exp $ aoqi@0: */ aoqi@0: package com.sun.xml.internal.fastinfoset; aoqi@0: aoqi@0: import java.text.MessageFormat; aoqi@0: import java.util.Enumeration; aoqi@0: import java.util.Locale; aoqi@0: import java.util.ResourceBundle; aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * This class contains methods common to all *ResourceBundle classes aoqi@0: * aoqi@0: * @author FastInfoset team aoqi@0: */ aoqi@0: public abstract class AbstractResourceBundle extends ResourceBundle { aoqi@0: aoqi@0: public static final String LOCALE = "com.sun.xml.internal.fastinfoset.locale"; aoqi@0: aoqi@0: /** aoqi@0: * Gets 'key' from ResourceBundle and format mesage using 'args'. aoqi@0: * aoqi@0: * @param key String key for message. aoqi@0: * @param args Array of arguments for message. aoqi@0: * @return String formatted message. aoqi@0: */ aoqi@0: public String getString(String key, Object args[]) { aoqi@0: String pattern = getBundle().getString(key); aoqi@0: return MessageFormat.format(pattern, args); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Parse a locale string, return corresponding Locale instance. aoqi@0: * aoqi@0: * @param localeString aoqi@0: * Name for the locale of interest. If null, use VM default locale. aoqi@0: * @return New Locale instance. aoqi@0: */ aoqi@0: public static Locale parseLocale(String localeString) { aoqi@0: Locale locale = null; aoqi@0: if (localeString == null) { aoqi@0: locale = Locale.getDefault(); aoqi@0: } else { aoqi@0: try { aoqi@0: String[] args = localeString.split("_"); aoqi@0: if (args.length == 1) { aoqi@0: locale = new Locale(args[0]); aoqi@0: } else if (args.length == 2) { aoqi@0: locale = new Locale(args[0], args[1]); aoqi@0: } else if (args.length == 3) { aoqi@0: locale = new Locale(args[0], args[1], args[2]); aoqi@0: } aoqi@0: } catch (Throwable t) { aoqi@0: locale = Locale.getDefault(); aoqi@0: } aoqi@0: } aoqi@0: return locale; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Subclasses of this class must implement this method so that the aoqi@0: * correct resource bundle is passed to methods in this class aoqi@0: * aoqi@0: * @return aoqi@0: * A java.util.ResourceBundle from the subsclass. Methods in this class aoqi@0: * will use this reference. aoqi@0: */ aoqi@0: public abstract ResourceBundle getBundle(); aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Since we are changing the ResourceBundle extension point, must aoqi@0: * implement handleGetObject() using delegate getBundle(). Uses aoqi@0: * getObject() call to work around protected access to aoqi@0: * ResourceBundle.handleGetObject(). Happily, this means parent tree aoqi@0: * of delegate bundle is searched for a match. aoqi@0: * aoqi@0: * Implements java.util.ResourceBundle.handleGetObject; inherits that aoqi@0: * javadoc information. aoqi@0: * aoqi@0: * @see java.util.ResourceBundle#handleGetObject(String) aoqi@0: */ aoqi@0: protected Object handleGetObject(String key) { aoqi@0: return getBundle().getObject(key); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Since we are changing the ResourceBundle extension point, must aoqi@0: * implement getKeys() using delegate getBundle(). aoqi@0: * aoqi@0: * Implements java.util.ResourceBundle.getKeys; inherits that javadoc aoqi@0: * information. aoqi@0: * aoqi@0: * @see java.util.ResourceBundle#getKeys() aoqi@0: */ aoqi@0: public final Enumeration getKeys() { aoqi@0: return getBundle().getKeys(); aoqi@0: } aoqi@0: }