Author: sylvain
Date: Fri Apr  8 09:03:06 2005
New Revision: 160557

URL: http://svn.apache.org/viewcvs?view=rev&rev=160557
Log:
fix environment context handling to allow the root sitemap to be at an 
arbitrary location

Modified:
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MountNode.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java?view=diff&r1=160556&r2=160557
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
 Fri Apr  8 09:03:06 2005
@@ -62,6 +62,8 @@
     private Map sitemapComponentConfigurations;
 
     private Configuration componentConfigurations;
+    
+    private String uriContext;
 
     /** Number of simultaneous uses of this processor (either by concurrent 
request or by internal requests) */
     private int requestCount;
@@ -72,14 +74,15 @@
        }
 
        /** Set the processor data, result of the treebuilder job */
-       public void setProcessorData(ComponentManager manager, ProcessingNode 
rootNode, List disposableNodes) {
-               if (this.sitemapComponentManager != null) {
-                       throw new IllegalStateException("setProcessorData() can 
only be called once");
-               }
+       public void setProcessorData(ComponentManager manager, ProcessingNode 
rootNode, List disposableNodes, String uriContext) {
+        if (this.sitemapComponentManager != null) {
+            throw new IllegalStateException("setProcessorData() can only be 
called once");
+        }
 
-               this.sitemapComponentManager = manager;
-               this.rootNode = rootNode;
-               this.disposableNodes = disposableNodes;
+        this.sitemapComponentManager = manager;
+        this.rootNode = rootNode;
+        this.disposableNodes = disposableNodes;
+        this.uriContext = uriContext;
        }
 
        /** Set the sitemap component configurations (called as part of the 
tree building process) */
@@ -216,11 +219,13 @@
 
                try {
                // and now process
-                CocoonComponentManager.enterEnvironment(environment, 
this.sitemapComponentManager, this);
+            CocoonComponentManager.enterEnvironment(environment, 
this.sitemapComponentManager, this);
+            String oldContext = environment.getContext();
+            environment.changeContext("", this.uriContext);
 
-                Map objectModel = environment.getObjectModel();
+            Map objectModel = environment.getObjectModel();
 
-                Object oldResolver = 
objectModel.get(ProcessingNode.OBJECT_SOURCE_RESOLVER);
+            Object oldResolver = 
objectModel.get(ProcessingNode.OBJECT_SOURCE_RESOLVER);
                final Redirector oldRedirector = context.getRedirector();
 
                // Build a redirector
@@ -236,6 +241,7 @@
                    return success;
 
                } finally {
+                    environment.changeContext("", oldContext);
                     CocoonComponentManager.leaveEnvironment(success);
                     // Restore old redirector and resolver
                    context.setRedirector(oldRedirector);

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java?view=diff&r1=160556&r2=160557
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
 Fri Apr  8 09:03:06 2005
@@ -308,26 +308,40 @@
         this.setupLogger(newProcessor);
         //FIXME (SW): why do we need to enterProcessor here?
         CocoonComponentManager.enterEnvironment(env, this.manager, this);
+        String oldContext = env.getContext();
         try {
             if (builder instanceof Recomposable) {
                 ((Recomposable)builder).recompose(this.manager);
             }
             builder.setProcessor(newProcessor);
-            if (this.fileName == null) {
-                this.fileName = builder.getFileName();
-            }
 
             if (this.source == null) {
+                if (this.fileName == null) {
+                    // Case of the root sitemap if no explicit config was given
+                    this.fileName = builder.getFileName();
+                }
+
                 this.source = new 
DelayedRefreshSourceWrapper(this.resolver.resolveURI(this.fileName),
                                                               
lastModifiedDelay);
+                
+                if (this.parent == null) {
+                    // Ensure the root processor has a filename to change its 
context
+                    this.fileName = this.source.getURI();
+                }
             }
+            
+            // Set the context to the sitemap location as components may 
lookup some resources
+            // during their initialization
+            env.changeContext("", this.source.getURI());
 
             newLastModified = this.source.getLastModified();
 
             ProcessingNode root = builder.build(this.source);
 
-            
newProcessor.setProcessorData(builder.getSitemapComponentManager(), root, 
builder.getDisposableNodes());
+            
newProcessor.setProcessorData(builder.getSitemapComponentManager(), root, 
builder.getDisposableNodes(), this.source.getURI());
         } finally {
+            // Restore the context (FIXME: need to separate this from URI 
prefix)
+            env.changeContext("", oldContext);
             CocoonComponentManager.leaveEnvironment();
             this.builderSelector.release(builder);
         }

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MountNode.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MountNode.java?view=diff&r1=160556&r2=160557
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MountNode.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MountNode.java
 Fri Apr  8 09:03:06 2005
@@ -103,7 +103,8 @@
         boolean pipelineWasBuilt = false;
 
         try {
-            env.changeContext(resolvedPrefix, resolvedSource);
+            // We only change the prefix here. Context will be changed by the 
processor itself.
+            env.changeContext(resolvedPrefix, "");
 
             if (context.isBuildingPipelineOnly()) {
                 // Propagate pipelines

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java?view=diff&r1=160556&r2=160557
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
 Fri Apr  8 09:03:06 2005
@@ -243,7 +243,7 @@
     /**
      * Adds an prefix to the overall stripped off prefix from the request uri
      */
-    public void changeContext(String prefix, String newContext)
+    public void changeContext(String newPrefix, String newContext)
     throws IOException {
         if (!this.initializedComponents) {
             this.initComponents();
@@ -252,19 +252,19 @@
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Changing Cocoon context");
             getLogger().debug("  from context(" + this.context + ") and 
prefix(" + this.prefix + ")");
-            getLogger().debug("  to context(" + newContext + ") and prefix(" + 
prefix + ")");
+            getLogger().debug("  to context(" + newContext + ") and prefix(" + 
newPrefix + ")");
             getLogger().debug("  at URI " + this.uris);
         }
 
-        int l = prefix.length();
+        int l = newPrefix.length();
         if (l >= 1) {
-            if (!this.uris.startsWith(prefix)) {
+            if (!this.uris.startsWith(newPrefix)) {
                 String message = "The current URI (" + this.uris +
-                                 ") doesn't start with given prefix (" + 
prefix + ")";
+                                 ") doesn't start with given prefix (" + 
newPrefix + ")";
                 getLogger().error(message);
                 throw new RuntimeException(message);
             }
-            this.prefix.append(prefix);
+            this.prefix.append(newPrefix);
             this.uris = this.uris.substring(l);
 
             // check for a slash at the beginning to avoid problems with 
subsitemaps
@@ -274,7 +274,7 @@
             }
         }
 
-        if (SourceUtil.getScheme(this.context).equals("zip")) {
+        if (this.context.startsWith("zip:")) {
             // if the resource is zipped into a war file (e.g. Weblogic temp 
deployment)
             // FIXME (VG): Is this still required? Better to unify both cases.
             if (getLogger().isDebugEnabled()) {
@@ -288,7 +288,7 @@
             } finally {
                 this.sourceResolver.release(source);
             }
-        } else {
+        } else if (newContext.length() > 0){
             String sContext;
             // if we got a absolute context or one with a protocol resolve it
             if (newContext.charAt(0) == '/') {

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&r1=160556&r2=160557
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Fri Apr  8 09:03:06 2005
@@ -196,6 +196,10 @@
 
   <changes>
   <release version="@version@" date="@date@">
+    <action dev="SW" type="fix">
+      Fix environment handling to allow the root sitemap to be at an abitrary 
location
+      and not only in the main webapp context directory.
+    </action>
     <action dev="VG" type="fix">
       Updated excalibur-pool to 2.0.0, excalibur-datasource to 1.2.0.
       Fixes problem of database connections pools not coming up after


Reply via email to