0N/A/*
3679N/A * Copyright (c) 2011, 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. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Oracle in the LICENSE file that accompanied this code.
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,
1472N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1472N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
1879N/A
1879N/Apackage com.apple.resources;
1879N/A
1879N/Aimport java.security.*;
1879N/Aimport java.util.PropertyResourceBundle;
1879N/Aimport java.util.ResourceBundle;
1879N/Aimport java.io.*;
1879N/A
1879N/Apublic class MacOSXResourceBundle extends PropertyResourceBundle {
1879N/A MacOSXResourceBundle(InputStream stream) throws IOException {
0N/A super(stream);
0N/A }
0N/A
0N/A void setItsParent(ResourceBundle rb) {
0N/A setParent(rb);
0N/A }
0N/A
0N/A public static ResourceBundle getMacResourceBundle(String baseJavaBundle) throws Exception {
0N/A return getMacResourceBundle(baseJavaBundle, null);
0N/A }
0N/A
0N/A public static ResourceBundle getMacResourceBundle(String baseJavaBundle, String filename) throws Exception {
263N/A LoadNativeBundleAction lnba = new LoadNativeBundleAction(baseJavaBundle, filename);
0N/A return (ResourceBundle)java.security.AccessController.doPrivileged(lnba);
0N/A }
0N/A}
0N/A
0N/Aclass LoadNativeBundleAction implements PrivilegedExceptionAction {
0N/A String mBaseJavaBundle;
0N/A String mFilenameOverride;
0N/A
0N/A LoadNativeBundleAction(String baseJavaBundle, String filenameOverride) {
0N/A mBaseJavaBundle = baseJavaBundle;
0N/A mFilenameOverride = filenameOverride;
0N/A }
263N/A
263N/A public Object run() {
263N/A java.util.ResourceBundle returnValue = null;
263N/A MacOSXResourceBundle macOSrb = null;
263N/A
263N/A // Load the Mac OS X resources.
0N/A // Use a base filename if we were given one. Otherwise, we will look for the last piece of the bundle path
263N/A // with '.properties' appended. Either way, the native method will take care of the extension.
263N/A String filename = mFilenameOverride;
263N/A
263N/A if (filename == null) {
263N/A filename = mBaseJavaBundle.substring(mBaseJavaBundle.lastIndexOf('.') + 1);
263N/A }
0N/A
0N/A File propsFile = null;
535N/A String propertyFileName = getPathToBundleFile(filename);
0N/A InputStream stream = null;
535N/A
0N/A try {
535N/A propsFile = new File(propertyFileName);
535N/A stream = new FileInputStream(propsFile);
0N/A stream = new java.io.BufferedInputStream(stream);
0N/A macOSrb = new MacOSXResourceBundle(stream);
0N/A } catch (Exception e) {
0N/A //e.printStackTrace();
0N/A //System.out.println("Failed to create resources from application bundle. Using Java-based resources.");
0N/A } finally {
0N/A try {
0N/A if (stream != null) stream.close();
0N/A stream = null;
0N/A } catch (Exception e) {
0N/A e.printStackTrace();
0N/A }
0N/A }
0N/A
0N/A returnValue = ResourceBundle.getBundle(mBaseJavaBundle);
0N/A
0N/A // If we have a platform-specific bundle, make it the parent of the generic bundle, so failures propagate up to the parent.
0N/A if (returnValue != null) {
0N/A if (macOSrb != null) {
0N/A macOSrb.setItsParent(returnValue);
0N/A returnValue = macOSrb;
0N/A }
0N/A }
0N/A
0N/A return returnValue;
13N/A }
263N/A
0N/A private static native String getPathToBundleFile(String filename);
0N/A}
0N/A
0N/A