You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gk...@apache.org on 2008/02/11 18:32:42 UTC

svn commit: r620536 - in /cocoon/whiteboard/micro/core/cocoon-core: pom.xml src/main/java/org/apache/cocoon/components/source/CocoonSourceResolver.java

Author: gkossakowski
Date: Mon Feb 11 09:32:25 2008
New Revision: 620536

URL: http://svn.apache.org/viewvc?rev=620536&view=rev
Log:
Calculate baseURL by using current servletContext which is obtained using CallStack (this is temporary).

This removes need for CocoonSourceResolver to implement Contextualizabe interface.

Modified:
    cocoon/whiteboard/micro/core/cocoon-core/pom.xml
    cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/CocoonSourceResolver.java

Modified: cocoon/whiteboard/micro/core/cocoon-core/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/pom.xml?rev=620536&r1=620535&r2=620536&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/pom.xml (original)
+++ cocoon/whiteboard/micro/core/cocoon-core/pom.xml Mon Feb 11 09:32:25 2008
@@ -105,6 +105,10 @@
       <artifactId>cocoon-servlet-service-impl</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-servlet-service-impl</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.cocoon.micro</groupId>
       <artifactId>cocoon-micro-pipeline-components</artifactId>
     </dependency>

Modified: cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/CocoonSourceResolver.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/CocoonSourceResolver.java?rev=620536&r1=620535&r2=620536&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/CocoonSourceResolver.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-core/src/main/java/org/apache/cocoon/components/source/CocoonSourceResolver.java Mon Feb 11 09:32:25 2008
@@ -16,16 +16,14 @@
  */
 package org.apache.cocoon.components.source;
 
-import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Map;
 
+import javax.servlet.ServletContext;
+
 import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
@@ -49,7 +47,7 @@
  * @version $Id$
  */
 public class CocoonSourceResolver extends AbstractLogEnabled
-                                  implements SourceResolver, Contextualizable, Serviceable, Disposable,
+                                  implements SourceResolver, Serviceable, Disposable,
                                              ThreadSafe {
 
     /** A (optional) custom source resolver */
@@ -60,32 +58,8 @@
 
     /** The base URL */
     protected URL baseURL;
-
-    /**
-     * @see Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
-     */
-    public void contextualize(Context context)
-    throws ContextException {
-        try {
-            if (context.get("context-root") instanceof URL) {
-                this.baseURL = (URL) context.get("context-root");
-            } else {
-                this.baseURL = ((File) context.get("context-root")).toURL();
-            }
-        } catch( ContextException ce ) {
-            // set the base URL to the current directory
-            try {
-                this.baseURL = new File( System.getProperty( "user.dir" ) ).toURL();
-                if (this.getLogger().isDebugEnabled()) {
-                    this.getLogger().debug("SourceResolver: Using base URL: " + this.baseURL);
-                }
-            } catch (MalformedURLException mue) {
-                throw new ContextException("Malformed URL for user.dir, and no container.rootDir exists", mue);
-            }
-        } catch (MalformedURLException mue) {
-            throw new ContextException("Malformed URL for container.rootDir", mue);
-        }
-    }
+    
+    private ServletContext servletContext;
 
     /**
      * @see SourceResolver#resolveURI(java.lang.String, java.lang.String, java.util.Map)
@@ -93,17 +67,21 @@
      */
     public Source resolveURI(String location, String baseURI, Map parameters)
     throws IOException {
-        //FIXME: This tieds CocoonSourceResolver to the SSF impl but it's temporary solution
+        //FIXME: This ties CocoonSourceResolver to the SSF impl but it's temporary solution
         //here we are switching baseURI to to the URI of the servlet we are in
-        if (baseURI == null && CallStack.getCurrentFrame() != null) {
-            baseURI = CallStackHelper.getCurrentServletContext().getResource("/").toExternalForm();
+        ServletContext servletContext = this.servletContext;
+        if (CallStack.getCurrentFrame() != null)
+            servletContext = CallStackHelper.getCurrentServletContext();
+        if (baseURI == null) {
+            baseURI = servletContext.getResource("/").toExternalForm();
         }
+        
         if (this.customResolver != null) {
             return this.customResolver.resolveURI(location, baseURI, parameters);
         }
 
         if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Resolving '" + location + "' with base '" + baseURI + "' in context '" + this.baseURL + "'");
+            getLogger().debug("Resolving '" + location + "' with base '" + baseURI);
         }
         if (location == null) {
             throw new MalformedURLException("Invalid System ID");
@@ -112,10 +90,6 @@
             throw new MalformedURLException("BaseURI is not valid, it must contain a protocol: " + baseURI);
         }
 
-        if (baseURI == null) {
-            baseURI = this.baseURL.toExternalForm();
-        }
-
         String systemID = location;
         // special handling for windows file paths
         if (location.length() > 1 && location.charAt(1) == ':') {
@@ -191,6 +165,7 @@
             this.customResolver = (org.apache.excalibur.source.SourceResolver)
                     this.manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE + "/Cocoon");
         }
+        this.servletContext = (ServletContext)manager.lookup("javax.servlet.ServletContext");
     }
 
     /**