cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Timm, Sean" <ST...@mailgo.com>
Subject [PATCH] Cocoon 2 Relative Directory Fix
Date Mon, 17 Apr 2000 11:01:15 GMT
The following diff allows relative paths specified in the sitemap
configuration file to be based off of the context root specified in the
servlet engine configuration.  In other words, if the context "/cocoon" is
mapped to "C:\my_cocoon_install\web", then specifying "../index.xml" will
refer to  "C:\my_cocoon_install\index.xml" and "subdir/index.xml" will refer
to "C:\my_cocoon_install\web\subdir\index.xml".

This does bring up a question, though.  It seems to me that if I refer to
"/whatever" in my sitemap, it should be relative to my context root, as
well, so it should resolve as "C:\my_cocoon_install\whatever".  However, it
currently resolves to "C:\whatever".  I'm not so sure that Cocoon should be
playing outside of the context the servlet engine passes it.  The patch I am
submitting only takes care of the relative paths, but it seems like we
should handle these absolute paths differently, as well.

- Sean T.

Here's the patch:
Index: CocoonServlet.java
===================================================================
RCS file:
/home/cvspublic/xml-cocoon/src/org/apache/cocoon/servlet/Attic/CocoonServlet
.java,v
retrieving revision 1.1.4.8
diff -u -r1.1.4.8 CocoonServlet.java
--- CocoonServlet.java	2000/03/21 18:23:50	1.1.4.8
+++ CocoonServlet.java	2000/04/17 10:49:19
@@ -9,6 +9,7 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.URL;
 import java.util.Enumeration;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -173,7 +174,9 @@
     private Cocoon create() {
         try {
             this.context.log("Reloading from: "+this.configurationFile);
-            Cocoon c=new Cocoon(this.configurationFile);
+            String rootPath = this.context.getRealPath("/");
+            URL root = new URL("file", "", rootPath);
+            Cocoon c=new Cocoon(root, this.configurationFile);
             this.creationTime=System.currentTimeMillis();
             return(c);
         } catch (Exception e) {
Index: Cocoon.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon/src/org/apache/cocoon/Cocoon.java,v
retrieving revision 1.4.2.5
diff -u -r1.4.2.5 Cocoon.java
--- Cocoon.java	2000/02/27 05:45:17	1.4.2.5
+++ Cocoon.java	2000/04/17 10:49:48
@@ -85,6 +85,18 @@
         this.setConfiguration(b.getConfiguration());
         this.root=this.configurationFile.getParentFile().toURL();
     }
+    
+    /**
+     * Create a new <code>Cocoon</code> object, overriding the default
+     * root based off of the location of the configuration file.
+     */
+    public Cocoon(URL root, String configuration)
+    throws SAXException, IOException, ConfigurationException {
+        this(configuration);
+        if(root != null) {
+            this.root = root;
+        }
+    }
 
     /**
      * Get the <code>Component</code> associated with the given role.

Mime
View raw message