]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Added patch for loading config via Thread ContextClassLoader
authorKelly Campbell <kellyc@apache.org>
Thu, 21 Jun 2001 18:05:09 +0000 (18:05 +0000)
committerKelly Campbell <kellyc@apache.org>
Thu, 21 Jun 2001 18:05:09 +0000 (18:05 +0000)
PR: 2255
Obtained from:
Submitted by: Davanum Srinivas
Reviewed by:

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194308 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/apps/Options.java
src/org/apache/fop/layout/hyphenation/Hyphenator.java

index 6ed8322feadbaddff5d20045dde3f8cf01a2b258..db54cc413fc59436741f320de56a3fb7e1f0e768 100644 (file)
@@ -116,10 +116,23 @@ public class Options {
        throws FOPException
     {
         String file = "config.xml";
+        InputStream configfile = null;
+
+        // Try to use Context Class Loader to load the properties file.
+        try {
+          java.lang.reflect.Method getCCL = 
+                Thread.class.getMethod("getContextClassLoader", new Class[0]);
+          if (getCCL != null) {
+            ClassLoader contextClassLoader = 
+                (ClassLoader) getCCL.invoke(Thread.currentThread(), new Object[0]);
+            configfile = contextClassLoader.getResourceAsStream("conf/" + file);
+          }
+        }
+        catch (Exception e) {}
 
         // the entry /conf/config.xml refers to a directory conf which is a sibling of org
-        InputStream configfile =
-           ConfigurationReader.class.getResourceAsStream("/conf/"+
+        if(configfile == null)
+               ConfigurationReader.class.getResourceAsStream("/conf/"+
                                                          file);
         if (configfile == null) {
             throw new FOPException("can't find default configuration file");
index 2a8ee5fcbd09d76e275fc447f299ae717c21255b..9981a32bff607c49d746757ab8639c8525e420aa 100644 (file)
@@ -60,16 +60,36 @@ public class Hyphenator {
         return hTree;
     }
 
+    private static InputStream getResourceStream (String key) {
+        InputStream is = null;
+        // Try to use Context Class Loader to load the properties file.
+        try {
+          java.lang.reflect.Method getCCL = 
+                Thread.class.getMethod("getContextClassLoader", new Class[0]);
+          if (getCCL != null) {
+            ClassLoader contextClassLoader = 
+                (ClassLoader) getCCL.invoke(Thread.currentThread(), new Object[0]);
+            is = contextClassLoader.getResourceAsStream("hyph/" + key + ".hyp");
+          }
+        }
+        catch (Exception e) {}
+
+        if(is==null) {
+            is = Hyphenator.class.getResourceAsStream("/hyph/" + key + ".hyp");
+        }
+
+        return is;
+    }
+
     public static HyphenationTree getFopHyphenationTree (String key) {
         HyphenationTree hTree = null;
         ObjectInputStream ois = null;
         InputStream is = null;
         try {
-            is = Hyphenator.class.getResourceAsStream("/hyph/" + key + ".hyp");
+            is = getResourceStream(key); 
             if (is == null) {
                 if (key.length() == 5) {
-                    is = Hyphenator.class.getResourceAsStream("/hyph/" +
-                        key.substring(0,2) + ".hyp"); 
+                    is = getResourceStream(key.substring(0,2));
                     if (is != null) {
                         MessageHandler.errorln(
                           "Couldn't find hyphenation pattern  " + key