Author: sylvain
Date: Tue Feb  1 07:43:40 2005
New Revision: 149408

URL: http://svn.apache.org/viewcvs?view=rev&rev=149408
Log:
more fixes of path-through with deeply nested cocoon: sources

Modified:
    
cocoon/branches/BRANCH_2_1_X/src/deprecated/java/org/apache/cocoon/components/source/SitemapSource.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/CocoonComponentManager.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
    
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/environment/AbstractEnvironment.java
    
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
    
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/explain-test.xml
    
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/sitemap.xmap

Modified: 
cocoon/branches/BRANCH_2_1_X/src/deprecated/java/org/apache/cocoon/components/source/SitemapSource.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/deprecated/java/org/apache/cocoon/components/source/SitemapSource.java?view=diff&r1=149407&r2=149408
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/deprecated/java/org/apache/cocoon/components/source/SitemapSource.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/deprecated/java/org/apache/cocoon/components/source/SitemapSource.java
 Tue Feb  1 07:43:40 2005
@@ -133,7 +133,7 @@
         } else if (uri.startsWith("/", position)) {
             position ++;
             this.prefix = null;
-            this.processor = CocoonComponentManager.getCurrentProcessor();
+            this.processor = CocoonComponentManager.getActiveProcessor();
         } else {
             throw new ProcessingException("Malformed cocoon URI.");
         }
@@ -243,7 +243,7 @@
             this.processKey = 
CocoonComponentManager.startProcessing(this.environment);
             this.environment.setURI(this.prefix, this.uri);
             this.processingPipeline = 
this.processor.buildPipeline(this.environment);
-            this.pipelineProcessor = 
CocoonComponentManager.getLastProcessor(this.environment); 
+            this.pipelineProcessor = 
CocoonComponentManager.getActiveProcessor(); 
             String redirectURL = this.environment.getRedirectURL();
             if (redirectURL != null) {
                 if (redirectURL.indexOf(":") == -1) {

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/CocoonComponentManager.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/CocoonComponentManager.java?view=diff&r1=149407&r2=149408
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/CocoonComponentManager.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/CocoonComponentManager.java
 Tue Feb  1 07:43:40 2005
@@ -58,6 +58,9 @@
 
     /** The key used to store the current process environment */
     private static final String PROCESS_KEY = 
CocoonComponentManager.class.getName();
+    
+    /** The environment attribute used to keep track of the actual environment 
in which the pipeline was built. */
+    private static final String PROCESSOR_ATTR = 
"CocoonComponentManager.processor";
 
     /** The environment information */
     private static InheritableThreadLocal environmentStack = new 
CloningInheritableThreadLocal();
@@ -120,7 +123,7 @@
                stack.push(new Object[] {env, processor, manager, new 
Integer(stack.getOffset())});
         stack.setOffset(stack.size()-1);
 
-        env.setAttribute("CocoonComponentManager.processor", processor);
+        env.setAttribute(PROCESSOR_ATTR, processor);
     }
 
     /**
@@ -128,9 +131,20 @@
      * It's the counterpart to [EMAIL PROTECTED] 
#enterEnvironment(Environment, ComponentManager, Processor)}.
      */
     public static void leaveEnvironment() {
+        leaveEnvironment(false);
+    }
+
+    /**
+     * This hook must be called by the sitemap each time a sitemap is left.
+     * It's the counterpart to [EMAIL PROTECTED] 
#enterEnvironment(Environment, ComponentManager, Processor)}.
+     * 
+     * @param success indicates if the request was successfully handled by the 
environment that's being left
+     */
+    public static void leaveEnvironment(boolean success) {
         final EnvironmentStack stack = 
(EnvironmentStack)environmentStack.get();
         final Object[] objs = (Object[])stack.pop();
         stack.setOffset(((Integer)objs[3]).intValue());
+
         if ( stack.isEmpty() ) {
             final Environment env = (Environment)objs[0];
             final Map globalComponents = 
(Map)env.getAttribute(GlobalRequestLifecycleComponent.class.getName());
@@ -144,6 +158,11 @@
                 }
             }
             
env.removeAttribute(GlobalRequestLifecycleComponent.class.getName());
+        } else {
+            if (!success) {
+                // Restore the current environment as being the active one
+                getCurrentEnvironment().setAttribute(PROCESSOR_ATTR, 
getCurrentProcessor());
+            }
         }
     }
 
@@ -242,10 +261,10 @@
     }
 
     /**
-     * Return the processor that is actually processing the request
+     * Return the processor that has actually processed the request
      */
-    public static Processor getLastProcessor(Environment env) {
-        return (Processor) 
env.getAttribute("CocoonComponentManager.processor");
+    public static Processor getActiveProcessor() {
+        return (Processor) 
getCurrentEnvironment().getAttribute(PROCESSOR_ATTR);
     }
 
     /**

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java?view=diff&r1=149407&r2=149408
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
 Tue Feb  1 07:43:40 2005
@@ -140,12 +140,12 @@
         String prefix;
         if (uri.startsWith("//", position)) {
             position += 2;
-            this.processor = 
CocoonComponentManager.getCurrentProcessor().getRootProcessor();
+            this.processor = 
CocoonComponentManager.getActiveProcessor().getRootProcessor();
             prefix = ""; // start at the root
         } else if (uri.startsWith("/", position)) {
             position ++;
             prefix = null;
-            this.processor = CocoonComponentManager.getCurrentProcessor();
+            this.processor = CocoonComponentManager.getActiveProcessor();
         } else {
             throw new MalformedURLException("Malformed cocoon URI: " + uri);
         }
@@ -330,7 +330,7 @@
         try {
             this.processKey = 
CocoonComponentManager.startProcessing(this.environment);
             this.processingPipeline = 
this.processor.buildPipeline(this.environment);
-            this.pipelineProcessor = 
CocoonComponentManager.getLastProcessor(this.environment);
+            this.pipelineProcessor = 
CocoonComponentManager.getActiveProcessor();
 
             String redirectURL = this.environment.getRedirectURL();
             if (redirectURL == null) {

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=149407&r2=149408
==============================================================================
--- 
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
 Tue Feb  1 07:43:40 2005
@@ -235,14 +235,15 @@
                setupLogger(redirector);
                context.setRedirector(redirector);
 
-                objectModel.put(ProcessingNode.OBJECT_SOURCE_RESOLVER, 
environment);
+            objectModel.put(ProcessingNode.OBJECT_SOURCE_RESOLVER, 
environment);
+            boolean success = false;
                try {
-                   boolean success = this.rootNode.invoke(environment, 
context);
+                   success = this.rootNode.invoke(environment, context);
                    
                    return success;
 
                } finally {
-                    CocoonComponentManager.leaveEnvironment();
+                    CocoonComponentManager.leaveEnvironment(success);
                     // Restore old redirector and resolver
                    context.setRedirector(oldRedirector);
                     objectModel.put(ProcessingNode.OBJECT_SOURCE_RESOLVER, 
oldResolver);

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=149407&r2=149408
==============================================================================
--- 
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
 Tue Feb  1 07:43:40 2005
@@ -328,7 +328,7 @@
 
             
newProcessor.setProcessorData(builder.getSitemapComponentManager(), root, 
builder.getDisposableNodes());
         } finally {
-            CocoonComponentManager.leaveEnvironment();
+            CocoonComponentManager.leaveEnvironment(false);
             this.builderSelector.release(builder);
         }
 

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=149407&r2=149408
==============================================================================
--- 
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
 Tue Feb  1 07:43:40 2005
@@ -447,6 +447,10 @@
     public void setAttribute(String name, Object value) {
         this.attributes.put(name, value);
     }
+    
+    protected boolean hasAttribute(String name) {
+        return this.attributes.containsKey(name);
+    }
 
     public void removeAttribute(String name) {
         this.attributes.remove(name);

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java?view=diff&r1=149407&r2=149408
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
 Tue Feb  1 07:43:40 2005
@@ -427,21 +427,22 @@
     public Object getAttribute(String name)
     {
         Object value = super.getAttribute(name);
-        if (value == null)
+        
+        // get it from the wrapped env only if it's not defined here with a 
null value
+        if (value == null  && !hasAttribute(name)) {
             value = this.environment.getAttribute(name);
+        }
 
         return value;
     }
 
     /**
-     * Remove attribute from the current instance, as well as from the
-     * wrapped environment.
+     * Remove attribute from the current instance.
      *
      * @param name a <code>String</code> value
      */
     public void removeAttribute(String name) {
         super.removeAttribute(name);
-        this.environment.removeAttribute(name);
     }
 
     /**

Modified: 
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/explain-test.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/explain-test.xml?view=diff&r1=149407&r2=149408
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/explain-test.xml
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/explain-test.xml
 Tue Feb  1 07:43:40 2005
@@ -29,8 +29,10 @@
         <para>
             Test links:
             <ul>
-                <li><link href="welcome">Correct page</link></li>
-                <li><link href="welcome-cocoon">Broken page</link></li>
+                <li><link href="welcome">Direct pipeline</link></li>
+                <li><link href="welcome1">One "cocoon:" URL</link></li>
+                <li><link href="welcome2">Two chained "cocoon:" 
URLs</link></li>
+                <li><link href="welcome3">Three chained "cocoon:" 
URLs</link></li>
             </ul>
         </para>
     </content>

Modified: 
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/sitemap.xmap
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/sitemap.xmap?view=diff&r1=149407&r2=149408
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/sitemap.xmap 
(original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/pass-through/sitemap.xmap 
Tue Feb  1 07:43:40 2005
@@ -8,18 +8,24 @@
 
       <map:match pattern="welcome">
         <map:generate src="welcome.xml"/>
-        <map:serialize type="xhtml"/>
+        <map:serialize/>
+      </map:match>
+
+      <map:match pattern="welcome1">
+        <map:generate src="cocoon:/welcome"/>
+        <map:serialize/>
       </map:match>
 
-      <map:match pattern="welcome-cocoon">
-        <map:generate src="cocoon:/welcome.ccn"/>
+      <map:match pattern="welcome2">
+        <map:generate src="cocoon:/welcome1"/>
         <map:serialize/>
       </map:match>
 
-      <map:match pattern="welcome.ccn">
-        <map:generate src="welcome.xml"/>
-        <map:serialize type="xhtml"/>
+      <map:match pattern="welcome3">
+        <map:generate src="cocoon:/welcome2"/>
+        <map:serialize/>
       </map:match>
+
     </map:pipeline>
   </map:pipelines>
 </map:sitemap>


Reply via email to