src/share/classes/sun/util/calendar/CalendarSystem.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -23,10 +23,17 @@
  * questions.
  */
 
 package sun.util.calendar;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Properties;
 import java.util.TimeZone;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
 /**

@@ -168,10 +175,48 @@
         }
         CalendarSystem cs =  calendars.putIfAbsent(calendarName, cal);
         return (cs == null) ? cal : cs;
     }
 
+    /**
+     * Returns a {@link Properties} loaded from lib/calendars.properties.
+     *
+     * @return a {@link Properties} loaded from lib/calendars.properties
+     * @throws IOException if an error occurred when reading from the input stream
+     * @throws IllegalArgumentException if the input stream contains any malformed
+     *                                  Unicode escape sequences
+     */
+    public static Properties getCalendarProperties() throws IOException {
+        Properties calendarProps = null;
+        try {
+            String homeDir = AccessController.doPrivileged(
+                new sun.security.action.GetPropertyAction("java.home"));
+            final String fname = homeDir + File.separator + "lib" + File.separator
+                                 + "calendars.properties";
+            calendarProps = AccessController.doPrivileged(new PrivilegedExceptionAction<Properties>() {
+                @Override
+                public Properties run() throws IOException {
+                    Properties props = new Properties();
+                    try (FileInputStream fis = new FileInputStream(fname)) {
+                        props.load(fis);
+                    }
+                    return props;
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            Throwable cause = e.getCause();
+            if (cause instanceof IOException) {
+                throw (IOException) cause;
+            } else if (cause instanceof IllegalArgumentException) {
+                throw (IllegalArgumentException) cause;
+            }
+            // Should not happen
+            throw new InternalError(cause);
+        }
+        return calendarProps;
+    }
+
     //////////////////////////////// Calendar API //////////////////////////////////
 
     /**
      * Returns the name of this calendar system.
      */