cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r596517 - in /cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon: SourceIOInputStream.java SourceResource.java SourceResourceLoader.java
Date Tue, 20 Nov 2007 02:40:39 GMT
Author: vgritsenko
Date: Mon Nov 19 18:40:38 2007
New Revision: 596517

URL: http://svn.apache.org/viewvc?rev=596517&view=rev
Log:
If classpath: location is passed to SourceResourceLoader,
it could be incorrectly resolved by the SourceResolver as Avalon's FileSource.
Check for classpath: and call delegate Spring ResourceLoader to fix this.

Modified:
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceIOInputStream.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResource.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResourceLoader.java

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceIOInputStream.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceIOInputStream.java?rev=596517&r1=596516&r2=596517&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceIOInputStream.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceIOInputStream.java
Mon Nov 19 18:40:38 2007
@@ -22,6 +22,9 @@
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 
+/**
+ * @version $Id$
+ */
 public class SourceIOInputStream extends InputStream {
 
     protected final InputStream delegate;
@@ -32,11 +35,11 @@
 
     protected final SourceResolver resolver;
 
+
     public SourceIOInputStream(SourceResolver resolver, Source source) throws IOException
{
         this.source = source;
         this.delegate = source.getInputStream();
         this.resolver = resolver;
-        this.closed = false;
     }
 
     /**

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResource.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResource.java?rev=596517&r1=596516&r2=596517&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResource.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResource.java
Mon Nov 19 18:40:38 2007
@@ -28,11 +28,15 @@
 import org.apache.excalibur.source.SourceUtil;
 import org.springframework.core.io.Resource;
 
+/**
+ * @version $Id$
+ */
 public class SourceResource implements Resource {
 
     protected Source source;
     protected SourceResolver resolver;
-    protected boolean open = false;
+    protected boolean open;
+
 
     public SourceResource(Source s, SourceResolver r) {
         this.source = s;
@@ -101,5 +105,4 @@
     public boolean isOpen() {
         return this.open;
     }
-
 }

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResourceLoader.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResourceLoader.java?rev=596517&r1=596516&r2=596517&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResourceLoader.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SourceResourceLoader.java
Mon Nov 19 18:40:38 2007
@@ -24,14 +24,20 @@
 import org.springframework.core.io.Resource;
 import org.springframework.core.io.ResourceLoader;
 
+import org.apache.cocoon.spring.configurator.ResourceUtils;
+
+/**
+ * @version $Id$
+ */
 public class SourceResourceLoader implements ResourceLoader {
 
-    protected final ResourceLoader wrappedLoader;
+    protected final ResourceLoader delegate;
 
     protected final SourceResolver resolver;
 
-    public SourceResourceLoader(ResourceLoader wrappedLoader, SourceResolver resolver) {
-        this.wrappedLoader = wrappedLoader;
+
+    public SourceResourceLoader(ResourceLoader delegate, SourceResolver resolver) {
+        this.delegate = delegate;
         this.resolver = resolver;
     }
 
@@ -39,20 +45,31 @@
      * @see org.springframework.core.io.ResourceLoader#getClassLoader()
      */
     public ClassLoader getClassLoader() {
-        return this.wrappedLoader.getClassLoader();
+        return this.delegate.getClassLoader();
     }
 
     /**
      * @see org.springframework.core.io.ResourceLoader#getResource(java.lang.String)
      */
     public Resource getResource(String location) {
-        if ( location != null && (location.indexOf(':') > 0 || !location.startsWith("/")))
{
-            try {
-                return new SourceResource(this.resolver.resolveURI(location), this.resolver);
-            } catch (IOException e) {
-                // we ignore it and leave it up to the wrapped loader
+        if (location != null) {
+            // If this is Spring 'classpath:' resource, call delegate before
+            // source resolver - it can not handle 'classpath:'.
+            if (ResourceUtils.isClasspathUri(location)) {
+                return this.delegate.getResource(location);
+            }
+
+            // If this is absolute URL with protocol, try source resolver
+            if (location.indexOf(':') > 0 || !location.startsWith("/")) {
+                try {
+                    return new SourceResource(this.resolver.resolveURI(location), this.resolver);
+                } catch (IOException e) {
+                    // we ignore it and leave it up to the wrapped loader
+                }
             }
         }
-        return this.wrappedLoader.getResource(location);
+
+        // Fallback to delegate
+        return this.delegate.getResource(location);
     }
 }



Mime
View raw message