cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r473733 - /cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java
Date Sat, 11 Nov 2006 15:35:40 GMT
Author: danielf
Date: Sat Nov 11 07:35:40 2006
New Revision: 473733

URL: http://svn.apache.org/viewvc?view=rev&rev=473733
Log:
Hack for making the block context source usable in the block context.

Modified:
    cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java

Modified: cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java?view=diff&rev=473733&r1=473732&r2=473733
==============================================================================
--- cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java
(original)
+++ cocoon/trunk/core/cocoon-blocks-fw/cocoon-blocks-fw-impl/src/main/java/org/apache/cocoon/blocks/BlockContext.java
Sat Nov 11 07:35:40 2006
@@ -36,6 +36,10 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.cocoon.blocks.util.ServletContextWrapper;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.web.context.support.WebApplicationContextUtils;
 
 /**
  * @version $Id$
@@ -103,7 +107,26 @@
     public URL getResource(String path) throws MalformedURLException {
         if (path.length() == 0 || path.charAt(0) != '/')
             throw new MalformedURLException("The path must start with '/' " + path);
-        
+
+        // hack for getting a file protocol or other protocols that can be used as context
+        // path in the getResource method in the servlet context
+        if (!(blockContextURL.startsWith("file:") || blockContextURL.startsWith("/")
+                || blockContextURL.indexOf(':') == -1)) {
+            SourceResolver resolver = null;
+            Source source = null;
+            try {
+                BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(this);
+                resolver = (SourceResolver) factory.getBean(SourceResolver.ROLE);
+                source = resolver.resolveURI(blockContextURL);
+                blockContextURL = source.getURI();
+            } catch (IOException e) {
+                throw new MalformedURLException("Could not resolve " + blockContextURL);
+            } finally {
+                if (resolver != null)
+                    resolver.release(source);
+            }
+        }
+
         // HACK: allow file:/ URLs for reloading of sitemaps during development
         if (this.blockContextURL.startsWith("file:")) {
             return new URL(this.blockContextURL + path);



Mime
View raw message