You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2003/08/16 15:30:04 UTC

cvs commit: cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper MutableEnvironmentFacade.java EnvironmentWrapper.java

sylvain     2003/08/16 06:30:04

  Modified:    .        status.xml
               src/java/org/apache/cocoon Cocoon.java Processor.java
                        ProcessorWrapper.java
               src/java/org/apache/cocoon/components/source/impl
                        SitemapSource.java
               src/java/org/apache/cocoon/components/treeprocessor
                        InvokeContext.java TreeProcessor.java
               src/java/org/apache/cocoon/environment
                        ForwardRedirector.java
               src/java/org/apache/cocoon/environment/wrapper
                        EnvironmentWrapper.java
  Added:       src/java/org/apache/cocoon/environment/wrapper
                        MutableEnvironmentFacade.java
  Log:
  Rewrite handling of internal-redirects (i.e. redirects to "cocoon:" URLs).
  Previously, internal redirects where not handled for internal requests (i.e. sitemap source).
  This bug prevented among other cases the use of flow-driven pages enclosed in an aggregation.
  
  Revision  Changes    Path
  1.123     +6 -1      cocoon-2.1/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/status.xml,v
  retrieving revision 1.122
  retrieving revision 1.123
  diff -u -r1.122 -r1.123
  --- status.xml	15 Aug 2003 05:47:41 -0000	1.122
  +++ status.xml	16 Aug 2003 13:30:03 -0000	1.123
  @@ -189,6 +189,11 @@
     <changes>
   
    <release version="@version@" date="@date@">
  +   <action dev="SW" type="fix">
  +     Rewrite handling of internal-redirects (i.e. redirects to "cocoon:" URLs). Previously, internal redirects
  +     where not handled for internal requests (i.e. sitemap source). This bug prevented among other cases the use
  +     of flow-driven pages enclosed in an aggregation.
  +   </action>
      <action dev="CZ" type="fix">
        The jars in /lib/local are used during compilation again.
      </action>
  
  
  
  1.13      +9 -1      cocoon-2.1/src/java/org/apache/cocoon/Cocoon.java
  
  Index: Cocoon.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/Cocoon.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Cocoon.java	6 Aug 2003 10:45:31 -0000	1.12
  +++ Cocoon.java	16 Aug 2003 13:30:04 -0000	1.13
  @@ -711,6 +711,14 @@
       public Map getComponentConfigurations() {
           return Collections.EMPTY_MAP;
       }
  +    
  +    /**
  +     * Return this (Cocoon is always at the root of the processing chain).
  +     * @since 2.1.1
  +     */
  +    public Processor getRootProcessor() {
  +        return this;
  +    }
   
       /**
        * Process the given <code>Environment</code> to generate Java code for specified XSP files.
  
  
  
  1.5       +8 -1      cocoon-2.1/src/java/org/apache/cocoon/Processor.java
  
  Index: Processor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/Processor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Processor.java	31 Jul 2003 03:20:37 -0000	1.4
  +++ Processor.java	16 Aug 2003 13:30:04 -0000	1.5
  @@ -93,4 +93,11 @@
        * @since 2.1
        */
       Map getComponentConfigurations();
  +    
  +    /**
  +     * Get the root processor parent of this processor.
  +     *
  +     * @sicne 2.1.1
  +     */
  +    Processor getRootProcessor();
   }
  
  
  
  1.4       +9 -1      cocoon-2.1/src/java/org/apache/cocoon/ProcessorWrapper.java
  
  Index: ProcessorWrapper.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/ProcessorWrapper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProcessorWrapper.java	6 Jul 2003 11:44:30 -0000	1.3
  +++ ProcessorWrapper.java	16 Aug 2003 13:30:04 -0000	1.4
  @@ -102,5 +102,13 @@
       public Map getComponentConfigurations() {
           return this.processor.getComponentConfigurations();
       }
  +    
  +    /**
  +     * Get the root parent processor of this processor
  +     * @since 2.1.1
  +     */
  +    public Processor getRootProcessor() {
  +        return this.processor.getRootProcessor();
  +    }
   
   }
  
  
  
  1.10      +20 -10    cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
  
  Index: SitemapSource.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SitemapSource.java	9 Aug 2003 18:21:49 -0000	1.9
  +++ SitemapSource.java	16 Aug 2003 13:30:04 -0000	1.10
  @@ -63,6 +63,7 @@
   import org.apache.cocoon.components.source.SourceUtil;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.environment.ObjectModelHelper;
  +import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade;
   import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
   import org.apache.cocoon.xml.ContentHandlerWrapper;
   import org.apache.cocoon.xml.XMLConsumer;
  @@ -106,7 +107,7 @@
       private String systemIdForCaching;
       
       /** The uri */
  -    private String uri;
  +//    private String uri;
   
       /** The current ComponentManager */
       private ComponentManager manager;
  @@ -118,10 +119,10 @@
       private Processor pipelineProcessor;
   
       /** The environment */
  -    private EnvironmentWrapper environment;
  +    private MutableEnvironmentFacade environment;
   
       /** The prefix for the processing */
  -    private String prefix;
  +//    private String prefix;
   
       /** The <code>ProcessingPipeline</code> */
       private ProcessingPipeline processingPipeline;
  @@ -160,6 +161,11 @@
   
           this.manager = manager;
           this.enableLogging(logger);
  +
  +
  +
  +
  +
           boolean rawMode = false;
   
           // remove the protocol
  @@ -176,6 +182,7 @@
           }
   
           // does the uri point to this sitemap or to the root sitemap?
  +        String prefix;
           if (uri.startsWith("//", position)) {
               position += 2;
               try {
  @@ -183,10 +190,10 @@
               } catch (ComponentException e) {
                   throw new MalformedURLException("Cannot get Processor instance");
               }
  -            this.prefix = ""; // start at the root
  +            prefix = ""; // start at the root
           } else if (uri.startsWith("/", position)) {
               position ++;
  -            this.prefix = null;
  +            prefix = null;
               this.processor = CocoonComponentManager.getCurrentProcessor();
           } else {
               throw new MalformedURLException("Malformed cocoon URI: " + uri);
  @@ -201,7 +208,6 @@
           } else if (position > 0) {
               uri = uri.substring(position);
           }
  -        this.uri = uri;
           
           // determine if the queryString specifies a cocoon-view
           String view = null;
  @@ -227,7 +233,7 @@
           }
   
           // build the request uri which is relative to the context
  -        String requestURI = (this.prefix == null ? env.getURIPrefix() + uri : uri);
  +        String requestURI = (prefix == null ? env.getURIPrefix() + uri : uri);
   
           // create system ID
           this.systemId = queryString == null ?
  @@ -235,8 +241,13 @@
               this.protocol + "://" + requestURI + "?" + queryString;
   
           // create environment...
  -        this.environment = new EnvironmentWrapper(env, requestURI, 
  +        EnvironmentWrapper wrapper = new EnvironmentWrapper(env, requestURI, 
                                                      queryString, logger, manager, rawMode, view);
  +        wrapper.setURI(prefix, uri);
  +        
  +        // The environment is a facade whose delegate can be changed in case of internal redirects
  +        this.environment = new MutableEnvironmentFacade(wrapper);
  +
           // ...and put information passed from the parent request to the internal request
           if ( null != parameters ) {
               this.environment.getObjectModel().put(ObjectModelHelper.PARENT_CONTEXT, parameters);
  @@ -370,7 +381,6 @@
           this.systemIdForCaching = this.systemId;
           try {
               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.environment.changeToLastContext();
  
  
  
  1.3       +12 -1     cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/InvokeContext.java
  
  Index: InvokeContext.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/InvokeContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InvokeContext.java	6 Jul 2003 11:44:30 -0000	1.2
  +++ InvokeContext.java	16 Aug 2003 13:30:04 -0000	1.3
  @@ -298,6 +298,17 @@
           mapToName.remove(map);
           nameToMap.remove(name);
       }
  +    
  +    /**
  +     * Prepare this context for reuse
  +     *
  +     */
  +    public final void reset() {
  +        this.mapStack.clear();
  +        this.mapToName.clear();
  +        this.nameToMap.clear();
  +        dispose();
  +    }
   
       /**
        * Release the pipelines, if any, if they were looked up by this context.
  
  
  
  1.11      +103 -22   cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
  
  Index: TreeProcessor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TreeProcessor.java	29 Jul 2003 07:41:27 -0000	1.10
  +++ TreeProcessor.java	16 Aug 2003 13:30:04 -0000	1.11
  @@ -81,7 +81,11 @@
   import org.apache.cocoon.components.pipeline.ProcessingPipeline;
   import org.apache.cocoon.components.source.SourceUtil;
   import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
  +import org.apache.cocoon.components.source.impl.SitemapSourceEnvironment;
   import org.apache.cocoon.environment.Environment;
  +import org.apache.cocoon.environment.ForwardRedirector;
  +import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade;
  +import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
   import org.apache.excalibur.source.Source;
   
   /**
  @@ -102,6 +106,8 @@
                  Contextualizable,
                  Disposable {
   
  +    public static final String COCOON_REDIRECT_ATTR = "cocoon: redirect url";
  +
       private static final String XCONF_URL =
           "resource://org/apache/cocoon/components/treeprocessor/treeprocessor-builtins.xml";
   
  @@ -178,7 +184,9 @@
           this.language = (language == null) ? parent.language : language;
   
           // Copy all that can be copied from the parent
  +        this.enableLogging(parent.getLogger());
           this.context = parent.context;
  +        this.roleManager = parent.roleManager;
           this.logKit = parent.logKit;
           this.builderSelector = parent.builderSelector;
           this.checkReload = parent.checkReload;
  @@ -203,10 +211,9 @@
           Source source)
         throws Exception {
   
  -        // FIXME(VG): Why child isn't configure()d/contextualize(d)/etc ???
  +        // Note: lifecycle methods aren't called, since this constructors copies all
  +        // that can be copied from the parent (see above)
           TreeProcessor child = new TreeProcessor(this, manager, language);
  -        child.enableLogging(getLogger());
  -        child.setRoleManager(this.roleManager);
           child.source = new DelayedRefreshSourceWrapper(source, lastModifiedDelay);
           return child;
       }
  @@ -312,24 +319,6 @@
           }
       }
   
  -    protected boolean process(Environment environment, InvokeContext context)
  -    throws Exception {
  -
  -        // first, check for sitemap changes
  -        if (this.rootNode == null ||
  -            (this.checkReload && this.source.getLastModified() > this.lastModified)) {
  -            setupRootNode(environment);
  -        }
  -
  -        // and now process
  -        CocoonComponentManager.enterEnvironment(environment, this.sitemapComponentManager, this);
  -        try {
  -            return this.rootNode.invoke(environment, context);
  -        } finally {
  -            CocoonComponentManager.leaveEnvironment();
  -        }
  -    }
  -
       /**
        * Process the given <code>Environment</code> to assemble
        * a <code>ProcessingPipeline</code>.
  @@ -350,6 +339,98 @@
           } finally {
               context.dispose();
           }
  +    }
  +
  +    /**
  +     * Do the actual processing, be it producing the response or just building the pipeline
  +     * @param environment
  +     * @param context
  +     * @return
  +     * @throws Exception
  +     */
  +    protected boolean process(Environment environment, InvokeContext context)
  +    throws Exception {
  +
  +        // first, check for sitemap changes
  +        if (this.rootNode == null ||
  +            (this.checkReload && this.source.getLastModified() > this.lastModified)) {
  +            setupRootNode(environment);
  +        }
  +
  +        // and now process
  +        CocoonComponentManager.enterEnvironment(environment, this.sitemapComponentManager, this);
  +        try {
  +            boolean success = this.rootNode.invoke(environment, context);
  +            
  +            if (success) {
  +                // Do we have a cocoon: redirect ?
  +                String cocoonRedirect = (String)environment.getAttribute(COCOON_REDIRECT_ATTR);
  +                if (cocoonRedirect != null) {
  +                    // Remove the redirect indication
  +                    environment.removeAttribute(COCOON_REDIRECT_ATTR);
  +                    // and handle the redirect
  +                    return handleCocoonRedirect(cocoonRedirect, environment, context);
  +                } else {
  +                    // "normal" success
  +                    return true;
  +                }
  +           
  +            } else {
  +                return false;
  +            }
  +
  +        } finally {
  +            CocoonComponentManager.leaveEnvironment();
  +        }
  +    }
  +    
  +    private boolean handleCocoonRedirect(String uri, Environment environment, InvokeContext context) throws Exception
  +    {
  +        
  +        // Build an environment wrapper
  +        // If the current env is a facade, change the delegate and continue processing the facade, since
  +        // we may have other redirects that will in turn also change the facade delegate
  +        
  +        MutableEnvironmentFacade facade = environment instanceof MutableEnvironmentFacade ?
  +            ((MutableEnvironmentFacade)environment) : null;
  +        
  +        if (facade != null) {
  +            // Consider the facade delegate (the real environment)
  +            environment = facade.getDelegate();
  +        }
  +        
  +        Environment newEnv = new EnvironmentWrapper(environment, this.manager, uri, getLogger());
  +        
  +        if (facade != null) {
  +            // Change the facade delegate
  +            facade.setDelegate((EnvironmentWrapper)newEnv);
  +            newEnv = facade;
  +        }
  +        
  +        // Get the processor that should process this request
  +        TreeProcessor processor;
  +        if (newEnv.getRootContext() == newEnv.getContext()) {
  +            processor = (TreeProcessor)getRootProcessor();
  +        } else {
  +            processor = this;
  +        }
  +        
  +        // Process the redirect
  +        context.reset();
  +        return processor.process(newEnv, context);
  +    }
  +    
  +    /**
  +     * Get the root parent of this processor
  +     * @since 2.1.1
  +     */
  +    public Processor getRootProcessor() {
  +        TreeProcessor result = this;
  +        while(result.parent != null) {
  +            result = result.parent;
  +        }
  +        
  +        return result;
       }
   
       /**
  
  
  
  1.6       +97 -95    cocoon-2.1/src/java/org/apache/cocoon/environment/ForwardRedirector.java
  
  Index: ForwardRedirector.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/ForwardRedirector.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ForwardRedirector.java	6 Jul 2003 11:44:30 -0000	1.5
  +++ ForwardRedirector.java	16 Aug 2003 13:30:04 -0000	1.6
  @@ -58,6 +58,8 @@
   import org.apache.cocoon.Processor;
   import org.apache.cocoon.components.CocoonComponentManager;
   import org.apache.cocoon.components.pipeline.ProcessingPipeline;
  +import org.apache.cocoon.components.source.impl.SitemapSourceEnvironment;
  +import org.apache.cocoon.components.treeprocessor.TreeProcessor;
   import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
   
   import java.io.IOException;
  @@ -74,6 +76,9 @@
   
       /** Was there a call to <code>redirect()</code> ? */
       private boolean hasRedirected = false;
  +    
  +    /** Was the redirect to a "cocoon:/" (and not "cocoon://") ?
  +    private boolean hasLocalRedirect = false;
   
       /** The <code>Environment to use for redirection (either internal or external) */
       private Environment env;
  @@ -160,92 +165,93 @@
   
       private void cocoonRedirect(boolean sessionMode, String uri)
       throws IOException, ProcessingException {
  -        Processor actualProcessor = null;
  -        try {
  -            boolean rawMode = false;
  -            String prefix;
  -
  -            // remove the protocol
  -            int protocolEnd = uri.indexOf(':');
  -            if (protocolEnd != -1) {
  -                uri = uri.substring(protocolEnd + 1);
  -                // check for subprotocol
  -                if (uri.startsWith("raw:")) {
  -                    uri = uri.substring(4);
  -                    rawMode = true;
  -                }
  -            }
  -
  -            Processor usedProcessor;
  -
  -            // Does the uri point to this sitemap or to the root sitemap?
  -            if (uri.startsWith("//")) {
  -                uri = uri.substring(2);
  -                prefix = ""; // start at the root
  -                try {
  -                    actualProcessor = (Processor)this.manager.lookup(Processor.ROLE);
  -                    usedProcessor = actualProcessor;
  -                } catch (ComponentException e) {
  -                    throw new ProcessingException("Cannot get Processor instance", e);
  -                }
  -
  -            } else if (uri.startsWith("/")) {
  -                prefix = null; // means use current prefix
  -                uri = uri.substring(1);
  -                usedProcessor = this.processor;
  -
  -            } else {
  -                throw new ProcessingException("Malformed cocoon URI.");
  -            }
  -
  -            // create the queryString (if available)
  -            String queryString = null;
  -            int queryStringPos = uri.indexOf('?');
  -            if (queryStringPos != -1) {
  -                queryString = uri.substring(queryStringPos + 1);
  -                uri = uri.substring(0, queryStringPos);
  -            }
  -
  -            // build the request uri which is relative to the context
  -            String requestURI = (prefix == null ? env.getURIPrefix() + uri : uri);
  -
  -            ForwardEnvironmentWrapper newEnv =
  -                new ForwardEnvironmentWrapper(env, requestURI, queryString, getLogger(), rawMode);
  -            newEnv.setURI(prefix, uri);
  -
  -            boolean processingResult;
  -
  -            // FIXME - What to do here?
  -            Object processKey = CocoonComponentManager.startProcessing(newEnv);
  -            try {
  -                
  -                if ( !this.internal ) {
  -                    processingResult = usedProcessor.process(newEnv);
  -                } else {
  -                    ProcessingPipeline pp = usedProcessor.buildPipeline(newEnv);
  -                    if (pp != null) pp.release();
  -                    processingResult = pp != null;
  -                }
  -            } finally {
  -                CocoonComponentManager.endProcessing(newEnv, processKey);
  -            }
  -
  -
  -            if (!processingResult) {
  -                throw new ProcessingException("Couldn't process URI " + requestURI);
  -            }
  -
  -        } catch(IOException ioe) {
  -            throw ioe;
  -        } catch(ProcessingException pe) {
  -            throw pe;
  -        } catch(Exception e) {
  -            String msg = "Error while redirecting to " + uri;
  -            getLogger().error(msg, e);
  -            throw new ProcessingException(msg, e);
  -        } finally {
  -            this.manager.release( actualProcessor );
  -        }
  +        this.env.setAttribute(TreeProcessor.COCOON_REDIRECT_ATTR, uri);
  +//        Processor actualProcessor = null;
  +//        try {
  +//            boolean rawMode = false;
  +//            String prefix;
  +//
  +//            // remove the protocol
  +//            int protocolEnd = uri.indexOf(':');
  +//            if (protocolEnd != -1) {
  +//                uri = uri.substring(protocolEnd + 1);
  +//                // check for subprotocol
  +//                if (uri.startsWith("raw:")) {
  +//                    uri = uri.substring(4);
  +//                    rawMode = true;
  +//                }
  +//            }
  +//
  +//            Processor usedProcessor;
  +//
  +//            // Does the uri point to this sitemap or to the root sitemap?
  +//            if (uri.startsWith("//")) {
  +//                uri = uri.substring(2);
  +//                prefix = ""; // start at the root
  +//                try {
  +//                    actualProcessor = (Processor)this.manager.lookup(Processor.ROLE);
  +//                    usedProcessor = actualProcessor;
  +//                } catch (ComponentException e) {
  +//                    throw new ProcessingException("Cannot get Processor instance", e);
  +//                }
  +//
  +//            } else if (uri.startsWith("/")) {
  +//                prefix = null; // means use current prefix
  +//                uri = uri.substring(1);
  +//                usedProcessor = this.processor;
  +//
  +//            } else {
  +//                throw new ProcessingException("Malformed cocoon URI.");
  +//            }
  +//
  +//            // create the queryString (if available)
  +//            String queryString = null;
  +//            int queryStringPos = uri.indexOf('?');
  +//            if (queryStringPos != -1) {
  +//                queryString = uri.substring(queryStringPos + 1);
  +//                uri = uri.substring(0, queryStringPos);
  +//            }
  +//
  +//            // build the request uri which is relative to the context
  +//            String requestURI = (prefix == null ? env.getURIPrefix() + uri : uri);
  +//
  +//            ForwardEnvironmentWrapper newEnv =
  +//                new ForwardEnvironmentWrapper(env, requestURI, queryString, getLogger(), rawMode);
  +//            newEnv.setURI(prefix, uri);
  +//
  +//            boolean processingResult;
  +//
  +//            // FIXME - What to do here?
  +//            Object processKey = CocoonComponentManager.startProcessing(newEnv);
  +//            try {
  +//                
  +//                if ( !this.internal ) {
  +//                    processingResult = usedProcessor.process(newEnv);
  +//                } else {
  +//                    ProcessingPipeline pp = usedProcessor.buildPipeline(newEnv);
  +//                    if (pp != null) pp.release();
  +//                    processingResult = pp != null;
  +//                }
  +//            } finally {
  +//                CocoonComponentManager.endProcessing(newEnv, processKey);
  +//            }
  +//
  +//
  +//            if (!processingResult) {
  +//                throw new ProcessingException("Couldn't process URI " + requestURI);
  +//            }
  +//
  +//        } catch(IOException ioe) {
  +//            throw ioe;
  +//        } catch(ProcessingException pe) {
  +//            throw pe;
  +//        } catch(Exception e) {
  +//            String msg = "Error while redirecting to " + uri;
  +//            getLogger().error(msg, e);
  +//            throw new ProcessingException(msg, e);
  +//        } finally {
  +//            this.manager.release( actualProcessor );
  +//        }
       }
   
       /**
  @@ -254,19 +260,15 @@
       public boolean hasRedirected() {
           return this.hasRedirected;
       }
  -
  +    
       /**
        * Local extension of EnvironmentWrapper to propagate otherwise blocked
        * methods to the actual environment.
        */
  -    private final class ForwardEnvironmentWrapper extends EnvironmentWrapper {
  +    public static final class ForwardEnvironmentWrapper extends SitemapSourceEnvironment {
   
  -        public ForwardEnvironmentWrapper(Environment env,
  -                              String      requestURI,
  -                              String      queryString,
  -                              Logger      logger,
  -                              boolean     rawMode) throws MalformedURLException {
  -            super(env, requestURI, queryString, logger, rawMode);
  +        public ForwardEnvironmentWrapper(SitemapSourceEnvironment.WrapperData data) throws MalformedURLException {
  +            super(data);
           }
   
           public void setStatus(int statusCode) {
  
  
  
  1.11      +100 -2    cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
  
  Index: EnvironmentWrapper.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- EnvironmentWrapper.java	9 Aug 2003 18:21:49 -0000	1.10
  +++ EnvironmentWrapper.java	16 Aug 2003 13:30:04 -0000	1.11
  @@ -59,6 +59,7 @@
   
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.cocoon.Constants;
   import org.apache.cocoon.environment.AbstractEnvironment;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.environment.ObjectModelHelper;
  @@ -155,10 +156,23 @@
                                 String           view)
       throws MalformedURLException {
           super(env.getURI(), view, env.getContext(), env.getAction());
  +        init(env, requestURI, queryString, logger, manager, rawMode, view);
  +    }
  +
  +    private void init(Environment      env,
  +                              String           requestURI,
  +                              String           queryString,
  +                              Logger           logger,
  +                              ComponentManager manager,
  +                              boolean          rawMode,
  +                              String           view)
  +        throws MalformedURLException {
  +//        super(env.getURI(), view, env.getContext(), env.getAction());
           this.rootContext = env.getRootContext();
   
           this.enableLogging(logger);
           this.environment = env;
  +        this.view = view;
   
           this.prefix = new StringBuffer(env.getURIPrefix());
   
  @@ -182,6 +196,90 @@
                                             rawMode);
           this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, this.request);
       }
  +   
  +    public EnvironmentWrapper(Environment env, ComponentManager manager, String uri,  Logger logger)  throws MalformedURLException {
  +        super(env.getURI(), env.getView(), env.getContext(), env.getAction());
  +
  +        // FIXME(SW): code stolen from SitemapSource. Factorize somewhere...
  +        boolean rawMode = false;
  +
  +        // remove the protocol
  +        int position = uri.indexOf(':') + 1;
  +        if (position != 0) {
  +//            this.protocol = uri.substring(0, position-1);
  +            // check for subprotocol
  +            if (uri.startsWith("raw:", position)) {
  +                position += 4;
  +                rawMode = true;
  +            }
  +        } else {
  +            throw new MalformedURLException("No protocol found for sitemap source in " + uri);
  +        }
  +
  +        // does the uri point to this sitemap or to the root sitemap?
  +        String prefix;
  +        if (uri.startsWith("//", position)) {
  +            position += 2;
  +//            try {
  +//                this.processor = (Processor)this.manager.lookup(Processor.ROLE);
  +//            } catch (ComponentException e) {
  +//                throw new MalformedURLException("Cannot get Processor instance");
  +//            }
  +            prefix = ""; // start at the root
  +        } else if (uri.startsWith("/", position)) {
  +            position ++;
  +            prefix = null;
  +//            this.processor = CocoonComponentManager.getCurrentProcessor();
  +        } else {
  +            throw new MalformedURLException("Malformed cocoon URI: " + uri);
  +        }
  +
  +        // create the queryString (if available)
  +        String queryString = null;
  +        int queryStringPos = uri.indexOf('?', position);
  +        if (queryStringPos != -1) {
  +            queryString = uri.substring(queryStringPos + 1);
  +            uri = uri.substring(position, queryStringPos);
  +        } else if (position > 0) {
  +            uri = uri.substring(position);
  +        }
  +
  +        
  +        // determine if the queryString specifies a cocoon-view
  +        String view = null;
  +        if (queryString != null) {
  +            int index = queryString.indexOf(Constants.VIEW_PARAM);
  +            if (index != -1 
  +                && (index == 0 || queryString.charAt(index-1) == '&')
  +                && queryString.length() > index + Constants.VIEW_PARAM.length() 
  +                && queryString.charAt(index+Constants.VIEW_PARAM.length()) == '=') {
  +                
  +                String tmp = queryString.substring(index+Constants.VIEW_PARAM.length()+1);
  +                index = tmp.indexOf('&');
  +                if (index != -1) {
  +                    view = tmp.substring(0,index);
  +                } else {
  +                    view = tmp;
  +                }
  +            } else {
  +                view = env.getView();
  +            }
  +        } else {
  +            view = env.getView();
  +        }
  +
  +        // build the request uri which is relative to the context
  +        String requestURI = (prefix == null ? env.getURIPrefix() + uri : uri);
  +
  +//        // create system ID
  +//        this.systemId = queryString == null ?
  +//            this.protocol + "://" + requestURI :
  +//            this.protocol + "://" + requestURI + "?" + queryString;
  +
  +        this.init(env, requestURI, queryString, logger, manager, rawMode, view);
  +        this.setURI(prefix, uri);
  +        
  +    }
   
       /**
        * Redirect the client to a new URL is not allowed
  @@ -276,7 +374,7 @@
       public String getRedirectURL() {
           return this.redirectURL;
       }
  -
  +    
       public void reset() {
           this.redirectURL = null;
       }
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper/MutableEnvironmentFacade.java
  
  Index: MutableEnvironmentFacade.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.environment.wrapper;
  
  import java.io.IOException;
  import java.io.OutputStream;
  import java.net.MalformedURLException;
  import java.util.Enumeration;
  import java.util.Map;
  
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Source;
  import org.xml.sax.SAXException;
  
  /**
   * Enviroment facade, whose delegate object can be changed. This class is required to handle internal redirects
   * in sitemap sources ("cocoon:"). This is because {@link org.apache.cocoon.components.source.SitemapSource} keeps
   * the environment in which the internal request should be processed. But internal redirects create a new
   * processing environment and there's no way to change the one held by the <code>SitemapSource</code>. So the
   * processing of internal redirects actually changes the delegate of this class, transparently for the 
   * <code>SitemapSource</code>.
   * 
   * @see org.apache.cocoon.components.source.impl.SitemapSource
   * @see org.apache.cocoon.components.treeprocessor.TreeProcessor#handleCocoonRedirect(String, Environment, InvokeContext)
   *
   * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
   * @version CVS $Id: MutableEnvironmentFacade.java,v 1.1 2003/08/16 13:30:04 sylvain Exp $
   */
  public class MutableEnvironmentFacade implements Environment {
  
      private EnvironmentWrapper env;
      
      public MutableEnvironmentFacade(EnvironmentWrapper env) {
          this.env = env;
      }
      
      public EnvironmentWrapper getDelegate() {
          return this.env;
      }
      
      public void setDelegate(EnvironmentWrapper env) {
          this.env = env;
      }
      
      //----------------------------------
      // EnvironmentWrapper-specific method (SW:still have to understand why SitemapSource needs them)
      public void setURI(String prefix, String uri) {
          this.env.setURI(prefix, uri);
      }
  
      public void setOutputStream(OutputStream os) {
          this.env.setOutputStream(os);
      }
  
      public void changeToLastContext() {
          this.env.changeToLastContext();
      }
      
      // Move this to the Environment interface ?
      public String getRedirectURL() {
          return this.env.getRedirectURL();
      }
      
      public void reset() {
          this.env.reset();
      }
      //----------------------------------
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getURI()
  	 */
  	public String getURI() {
  		return env.getURI();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getURIPrefix()
  	 */
  	public String getURIPrefix() {
  		return env.getURIPrefix();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getRootContext()
  	 */
  	public String getRootContext() {
  		return env.getRootContext();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getContext()
  	 */
  	public String getContext() {
  		return env.getContext();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getView()
  	 */
  	public String getView() {
  		return env.getView();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getAction()
  	 */
  	public String getAction() {
  		return env.getAction();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#setContext(java.lang.String, java.lang.String, java.lang.String)
  	 */
  	public void setContext(String prefix, String uri, String context) {
          env.setContext(prefix, uri, context);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#changeContext(java.lang.String, java.lang.String)
  	 */
  	public void changeContext(String uriprefix, String context) throws Exception {
          env.changeContext(uriprefix, context);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#redirect(boolean, java.lang.String)
  	 */
  	public void redirect(boolean sessionmode, String url) throws IOException {
          env.redirect(sessionmode, url);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#setContentType(java.lang.String)
  	 */
  	public void setContentType(String mimeType) {
  		env.setContentType(mimeType);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getContentType()
  	 */
  	public String getContentType() {
  		return env.getContentType();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#setContentLength(int)
  	 */
  	public void setContentLength(int length) {
  		env.setContentLength(length);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#setStatus(int)
  	 */
  	public void setStatus(int statusCode) {
  		env.setStatus(statusCode);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getOutputStream()
  	 */
  	public OutputStream getOutputStream() throws IOException {
  		return env.getOutputStream();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getOutputStream(int)
  	 */
  	public OutputStream getOutputStream(int bufferSize) throws IOException {
  		return env.getOutputStream(bufferSize);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getObjectModel()
  	 */
  	public Map getObjectModel() {
  		return env.getObjectModel();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#isResponseModified(long)
  	 */
  	public boolean isResponseModified(long lastModified) {
  		return env.isResponseModified(lastModified);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#setResponseIsNotModified()
  	 */
  	public void setResponseIsNotModified() {
          env.setResponseIsNotModified();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#setAttribute(java.lang.String, java.lang.Object)
  	 */
  	public void setAttribute(String name, Object value) {
  		env.setAttribute(name, value);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getAttribute(java.lang.String)
  	 */
  	public Object getAttribute(String name) {
  		return env.getAttribute(name);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#removeAttribute(java.lang.String)
  	 */
  	public void removeAttribute(String name) {
  		env.removeAttribute(name);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#getAttributeNames()
  	 */
  	public Enumeration getAttributeNames() {
  		return env.getAttributeNames();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#tryResetResponse()
  	 */
  	public boolean tryResetResponse() throws IOException {
  		return env.tryResetResponse();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#commitResponse()
  	 */
  	public void commitResponse() throws IOException {
  		env.commitResponse();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#startingProcessing()
  	 */
  	public void startingProcessing() {
          env.startingProcessing();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#finishingProcessing()
  	 */
  	public void finishingProcessing() {
          env.finishingProcessing();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.Environment#isExternal()
  	 */
  	public boolean isExternal() {
  		return env.isExternal();
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.cocoon.environment.SourceResolver#resolve(java.lang.String)
  	 */
  	public Source resolve(String systemID) throws ProcessingException, SAXException, IOException {
  		return env.resolve(systemID);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.excalibur.source.SourceResolver#resolveURI(java.lang.String)
  	 */
  	public org.apache.excalibur.source.Source resolveURI(String arg0) throws MalformedURLException, IOException {
  		return env.resolveURI(arg0);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.excalibur.source.SourceResolver#resolveURI(java.lang.String, java.lang.String, java.util.Map)
  	 */
  	public org.apache.excalibur.source.Source resolveURI(String arg0, String arg1, Map arg2) throws MalformedURLException, IOException {
  		return env.resolveURI(arg0, arg1, arg2);
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.excalibur.source.SourceResolver#release(org.apache.excalibur.source.Source)
  	 */
  	public void release(org.apache.excalibur.source.Source arg0) {
          env.release(arg0);
  	}
  }
  
  
  

Re: cvs commit: cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper MutableEnvironmentFacade.java EnvironmentWrapper.java

Posted by Joerg Heinicke <jo...@gmx.de>.
And this was only because I'm testing Marc Leicester's newest midi patch 
at the moment. I wanted to build the samples to see everything is 
working and I thought "there is new stuff, take it and test it too". 
There was no need for the update :-)

Joerg

Sylvain Wallez wrote:

> Joerg Heinicke wrote:
> 
>> It seems 
>> org.apache.cocoon.components.source.impl.SitemapSourceEnvironment is 
>> missing.
> 
> 
> 
> Aaargh : in-air collision : you updated your CVS in the 12-minutes 
> period that was needed for me to detect and correct the broken 
> compilation :-/
> 
> Update again, this is fixed ! Sorry for the inconvenience.
> 
> Sylvain


Re: cvs commit: cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper MutableEnvironmentFacade.java EnvironmentWrapper.java

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Joerg Heinicke wrote:

> It seems 
> org.apache.cocoon.components.source.impl.SitemapSourceEnvironment is 
> missing.


Aaargh : in-air collision : you updated your CVS in the 12-minutes 
period that was needed for me to detect and correct the broken 
compilation :-/

Update again, this is fixed ! Sorry for the inconvenience.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



Re: cvs commit: cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper MutableEnvironmentFacade.java EnvironmentWrapper.java

Posted by Joerg Heinicke <jo...@gmx.de>.
It seems 
org.apache.cocoon.components.source.impl.SitemapSourceEnvironment is 
missing.

Joerg

sylvain@apache.org wrote:

> sylvain     2003/08/16 06:30:04
> 
>   Modified:    .        status.xml
>                src/java/org/apache/cocoon Cocoon.java Processor.java
>                         ProcessorWrapper.java
>                src/java/org/apache/cocoon/components/source/impl
>                         SitemapSource.java
>                src/java/org/apache/cocoon/components/treeprocessor
>                         InvokeContext.java TreeProcessor.java
>                src/java/org/apache/cocoon/environment
>                         ForwardRedirector.java
>                src/java/org/apache/cocoon/environment/wrapper
>                         EnvironmentWrapper.java
>   Added:       src/java/org/apache/cocoon/environment/wrapper
>                         MutableEnvironmentFacade.java
>   Log:
>   Rewrite handling of internal-redirects (i.e. redirects to "cocoon:" URLs).
>   Previously, internal redirects where not handled for internal requests (i.e. sitemap source).
>   This bug prevented among other cases the use of flow-driven pages enclosed in an aggregation.