0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A/*
0N/A * @test
0N/A * @bug 5102289 4403721
0N/A * @summary Test XML support as shown in the ResourceBundle.Control description.
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.net.*;
0N/Aimport java.util.*;
0N/Aimport static java.util.ResourceBundle.Control.*;
0N/A
0N/Apublic class XMLResourceBundleTest {
0N/A public static void main(String[] args) {
0N/A ResourceBundle.Control xmlControl = new ResourceBundle.Control() {
0N/A @Override
0N/A public List<String> getFormats(String baseName) {
0N/A if (baseName == null) {
0N/A throw new NullPointerException();
0N/A }
0N/A return Arrays.asList("xml");
0N/A }
0N/A @Override
0N/A public ResourceBundle newBundle(String baseName, Locale locale,
0N/A String format,
0N/A ClassLoader loader,
0N/A boolean reload)
0N/A throws IllegalAccessException,
0N/A InstantiationException, IOException {
0N/A if (baseName == null || locale == null
0N/A || format == null || loader == null) {
0N/A throw new NullPointerException();
0N/A }
0N/A ResourceBundle bundle = null;
0N/A if (format.equals("xml")) {
0N/A String bundleName = toBundleName(baseName, locale);
0N/A String resourceName = toResourceName(bundleName, format);
0N/A URL url = loader.getResource(resourceName);
0N/A if (url != null) {
0N/A URLConnection connection = url.openConnection();
0N/A if (connection != null) {
0N/A if (reload) {
0N/A // disable caches if reloading
0N/A connection.setUseCaches(false);
0N/A }
0N/A InputStream stream = connection.getInputStream();
0N/A if (stream != null) {
0N/A BufferedInputStream bis = new BufferedInputStream(stream);
0N/A bundle = new XMLResourceBundle(bis);
0N/A bis.close();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A return bundle;
0N/A }
0N/A };
0N/A ResourceBundle rb = ResourceBundle.getBundle("XmlRB", new Locale(""), xmlControl);
0N/A String type = rb.getString("type");
0N/A if (!type.equals("XML")) {
0N/A throw new RuntimeException("Root Locale: type: got " + type
0N/A + ", expected XML (ASCII)");
0N/A }
0N/A
0N/A rb = ResourceBundle.getBundle("XmlRB", Locale.JAPAN, xmlControl);
0N/A type = rb.getString("type");
0N/A // Expect fullwidth "XML"
0N/A if (!type.equals("\uff38\uff2d\uff2c")) {
0N/A throw new RuntimeException("Locale.JAPAN: type: got " + type
0N/A + ", expected \uff38\uff2d\uff2c (fullwidth XML)");
0N/A }
0N/A }
0N/A
0N/A private static class XMLResourceBundle extends ResourceBundle {
0N/A private Properties props;
0N/A
0N/A XMLResourceBundle(InputStream stream) throws IOException {
0N/A props = new Properties();
0N/A props.loadFromXML(stream);
0N/A }
0N/A
0N/A protected Object handleGetObject(String key) {
0N/A if (key == null) {
0N/A throw new NullPointerException();
0N/A }
0N/A return props.get(key);
0N/A }
0N/A
0N/A public Enumeration<String> getKeys() {
0N/A // Not implemented
0N/A return null;
0N/A }
0N/A }
0N/A}