myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1074277 - in /myfaces: core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java shared/trunk/core/src/main/java/org/apache/myfaces/shared/resource/ClassLoaderResourceLoader.java
Date Thu, 24 Feb 2011 19:56:37 GMT
Author: lu4242
Date: Thu Feb 24 19:56:36 2011
New Revision: 1074277

URL: http://svn.apache.org/viewvc?rev=1074277&view=rev
Log:
MYFACES-3044 Resource jsf.js not found when using the OSGi bundle (Alternate fix) and MYFACES-3051
Use multiple ClassLoaders to find resources (not only ContextClassLoader)

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/resource/ClassLoaderResourceLoader.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java?rev=1074277&r1=1074276&r2=1074277&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java
Thu Feb 24 19:56:36 2011
@@ -18,18 +18,19 @@
  */
 package org.apache.myfaces.resource;
 
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.faces.context.FacesContext;
+
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
 import org.apache.myfaces.shared_impl.resource.AliasResourceMetaImpl;
 import org.apache.myfaces.shared_impl.resource.ResourceLoader;
 import org.apache.myfaces.shared_impl.resource.ResourceMeta;
 import org.apache.myfaces.shared_impl.resource.ResourceMetaImpl;
-import org.apache.myfaces.shared_impl.util.MyFacesClassLoader;
+import org.apache.myfaces.shared_impl.util.ClassUtils;
 import org.apache.myfaces.shared_impl.util.WebConfigParamUtils;
 
-import javax.faces.context.FacesContext;
-import java.io.InputStream;
-import java.net.URL;
-
 /**
  * A resource loader implementation which loads resources from the thread ClassLoader.
  * 
@@ -47,7 +48,6 @@ public class InternalClassLoaderResource
     public static final String USE_MULTIPLE_JS_FILES_FOR_JSF_UNCOMPRESSED_JS = "org.apache.myfaces.USE_MULTIPLE_JS_FILES_FOR_JSF_UNCOMPRESSED_JS";
     
     private final boolean _useMultipleJsFilesForJsfUncompressedJs;
-    private MyFacesClassLoader classLoader;
 
     public InternalClassLoaderResourceLoader(String prefix)
     {
@@ -65,26 +65,50 @@ public class InternalClassLoaderResource
     @Override
     public InputStream getResourceInputStream(ResourceMeta resourceMeta)
     {
+        InputStream is = null;
         if (getPrefix() != null && !"".equals(getPrefix()))
         {
-            return getClassLoader().getResourceAsStream(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+            String name = getPrefix() + '/' + resourceMeta.getResourceIdentifier();
+            is = getClassLoader().getResourceAsStream(name);
+            if (is == null)
+            {
+                is = this.getClass().getClassLoader().getResourceAsStream(name);
+            }
+            return is;
         }
         else
         {
-            return getClassLoader().getResourceAsStream(resourceMeta.getResourceIdentifier());
+            is = getClassLoader().getResourceAsStream(resourceMeta.getResourceIdentifier());
+            if (is == null)
+            {
+                is = this.getClass().getClassLoader().getResourceAsStream(resourceMeta.getResourceIdentifier());
+            }
+            return is;
         }
     }
 
     @Override
     public URL getResourceURL(ResourceMeta resourceMeta)
     {
+        URL url = null;
         if (getPrefix() != null && !"".equals(getPrefix()))
         {
-            return getClassLoader().getResource(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+            String name = getPrefix() + '/' + resourceMeta.getResourceIdentifier();
+            url = getClassLoader().getResource(name);
+            if (url == null)
+            {
+                url = this.getClass().getClassLoader().getResource(name);
+            }
+            return url;
         }
         else
         {
-            return getClassLoader().getResource(resourceMeta.getResourceIdentifier());
+            url = getClassLoader().getResource(resourceMeta.getResourceIdentifier());
+            if (url == null)
+            {
+                url = this.getClass().getClassLoader().getResource(resourceMeta.getResourceIdentifier());
+            }
+            return url; 
         }
     }
 
@@ -138,11 +162,7 @@ public class InternalClassLoaderResource
      */
     protected ClassLoader getClassLoader()
     {
-        if (classLoader == null)
-        {
-            classLoader = new MyFacesClassLoader();
-        }
-        return classLoader;
+        return ClassUtils.getContextClassLoader();
     }
 
     @Override
@@ -151,6 +171,10 @@ public class InternalClassLoaderResource
         if (getPrefix() != null && !"".equals(getPrefix()))
         {
             URL url = getClassLoader().getResource(getPrefix() + '/' + libraryName);
+            if (url == null)
+            {
+                url = this.getClass().getClassLoader().getResource(getPrefix() + '/' + libraryName);
+            }
             if (url != null)
             {
                 return true;
@@ -159,6 +183,10 @@ public class InternalClassLoaderResource
         else
         {
             URL url = getClassLoader().getResource(libraryName);
+            if (url == null)
+            {
+                url = this.getClass().getClassLoader().getResource(libraryName);
+            }
             if (url != null)
             {
                 return true;

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/resource/ClassLoaderResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/resource/ClassLoaderResourceLoader.java?rev=1074277&r1=1074276&r2=1074277&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/resource/ClassLoaderResourceLoader.java
(original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/resource/ClassLoaderResourceLoader.java
Thu Feb 24 19:56:36 2011
@@ -18,13 +18,14 @@
  */
 package org.apache.myfaces.shared.resource;
 
-import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
-import org.apache.myfaces.shared.util.MyFacesClassLoader;
+import java.io.InputStream;
+import java.net.URL;
 
 import javax.faces.application.ProjectStage;
 import javax.faces.context.FacesContext;
-import java.io.InputStream;
-import java.net.URL;
+
+import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
+import org.apache.myfaces.shared.util.ClassUtils;
 
 /**
  * A resource loader implementation which loads resources from the thread ClassLoader.
@@ -73,7 +74,6 @@ public class ClassLoaderResourceLoader e
     };*/
     
     private final boolean _developmentStage;
-    private MyFacesClassLoader classLoader;
 
     public ClassLoaderResourceLoader(String prefix)
     {
@@ -243,26 +243,50 @@ public class ClassLoaderResourceLoader e
     @Override
     public InputStream getResourceInputStream(ResourceMeta resourceMeta)
     {
+        InputStream is = null;
         if (getPrefix() != null && !"".equals(getPrefix()))
         {
-            return getClassLoader().getResourceAsStream(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+            String name = getPrefix() + '/' + resourceMeta.getResourceIdentifier();
+            is = getClassLoader().getResourceAsStream(name);
+            if (is == null)
+            {
+                is = this.getClass().getClassLoader().getResourceAsStream(name);
+            }
+            return is;
         }
         else
         {
-            return getClassLoader().getResourceAsStream(resourceMeta.getResourceIdentifier());
+            is = getClassLoader().getResourceAsStream(resourceMeta.getResourceIdentifier());
+            if (is == null)
+            {
+                is = this.getClass().getClassLoader().getResourceAsStream(resourceMeta.getResourceIdentifier());
+            }
+            return is;
         }
     }
 
     @Override
     public URL getResourceURL(ResourceMeta resourceMeta)
     {
+        URL url = null;
         if (getPrefix() != null && !"".equals(getPrefix()))
         {
-            return getClassLoader().getResource(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+            String name = getPrefix() + '/' + resourceMeta.getResourceIdentifier();
+            url = getClassLoader().getResource(name);
+            if (url == null)
+            {
+                url = this.getClass().getClassLoader().getResource(name);
+            }
+            return url;
         }
         else
         {
-            return getClassLoader().getResource(resourceMeta.getResourceIdentifier());
+            url = getClassLoader().getResource(resourceMeta.getResourceIdentifier());
+            if (url == null)
+            {
+                url = this.getClass().getClassLoader().getResource(resourceMeta.getResourceIdentifier());
+            }
+            return url;
         }
     }
 
@@ -435,11 +459,7 @@ public class ClassLoaderResourceLoader e
      */
     protected ClassLoader getClassLoader()
     {
-        if (classLoader == null)
-        {
-            classLoader = new MyFacesClassLoader();
-        }
-        return classLoader;
+        return ClassUtils.getContextClassLoader();
     }
 
     @Override
@@ -448,6 +468,10 @@ public class ClassLoaderResourceLoader e
         if (getPrefix() != null && !"".equals(getPrefix()))
         {
             URL url = getClassLoader().getResource(getPrefix() + '/' + libraryName);
+            if (url == null)
+            {
+                url = this.getClass().getClassLoader().getResource(getPrefix() + '/' + libraryName);
+            }
             if (url != null)
             {
                 return true;
@@ -456,6 +480,10 @@ public class ClassLoaderResourceLoader e
         else
         {
             URL url = getClassLoader().getResource(libraryName);
+            if (url == null)
+            {
+                url = this.getClass().getClassLoader().getResource(libraryName);
+            }
             if (url != null)
             {
                 return true;



Mime
View raw message