cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components/source/impl SitemapSource.java
Date Fri, 25 Jun 2004 15:36:39 GMT
cziegeler    2004/06/25 08:36:39

  Modified:    src/java/org/apache/cocoon/environment
                        AbstractEnvironment.java
               src/java/org/apache/cocoon/environment/wrapper
                        EnvironmentWrapper.java
               src/java/org/apache/cocoon/components/treeprocessor
                        ConcreteTreeProcessor.java
               src/java/org/apache/cocoon/components/source/impl
                        SitemapSource.java
  Added:       src/java/org/apache/cocoon/environment/internal
                        ForwardEnvironmentWrapper.java
  Log:
  Cleaning up creation of wrapper environments; remove duplicate code
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/environment/internal/ForwardEnvironmentWrapper.java
  
  Index: ForwardEnvironmentWrapper.java
  ===================================================================
  /*
   * Copyright 1999-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.cocoon.environment.internal;
  
  import java.net.MalformedURLException;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.cocoon.components.source.impl.SitemapSourceInfo;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
  
  /**
   * Local extension of EnvironmentWrapper to propagate otherwise blocked
   * methods to the actual environment.
   * 
   * @version CVS $Id: ForwardEnvironmentWrapper.java,v 1.1 2004/06/25 15:36:38 cziegeler
Exp $
  */
  public final class ForwardEnvironmentWrapper extends EnvironmentWrapper {
  
      public ForwardEnvironmentWrapper(Environment env,
                                       SitemapSourceInfo info, 
                                       Logger logger) 
      throws MalformedURLException {
          super(env, info, logger);
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.environment.Environment#setStatus(int)
       */
      public void setStatus(int statusCode) {
          environment.setStatus(statusCode);
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.environment.Environment#setContentLength(int)
       */
      public void setContentLength(int length) {
          environment.setContentLength(length);
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.environment.Environment#setContentType(java.lang.String)
       */
      public void setContentType(String contentType) {
          environment.setContentType(contentType);
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.environment.Environment#getContentType()
       */
      public String getContentType() {
          return environment.getContentType();
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.environment.Environment#isResponseModified(long)
       */
      public boolean isResponseModified(long lastModified) {
          return environment.isResponseModified(lastModified);
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.environment.Environment#setResponseIsNotModified()
       */
      public void setResponseIsNotModified() {
          environment.setResponseIsNotModified();
      }
  }
  
  
  1.24      +2 -3      cocoon-2.1/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
  
  Index: AbstractEnvironment.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/AbstractEnvironment.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- AbstractEnvironment.java	29 May 2004 17:39:38 -0000	1.23
  +++ AbstractEnvironment.java	25 Jun 2004 15:36:38 -0000	1.24
  @@ -51,7 +51,7 @@
       protected String action;
   
       /** The object model */
  -    protected HashMap objectModel;
  +    protected Map objectModel = new HashMap();
   
       /** The attributes */
       private Map attributes = new HashMap();
  @@ -76,7 +76,6 @@
           this.uri = uri;
           this.view = view;
           this.action = action;
  -        this.objectModel = new HashMap();
       }
   
       /**
  
  
  
  1.21      +18 -67    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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- EnvironmentWrapper.java	23 Jun 2004 17:13:00 -0000	1.20
  +++ EnvironmentWrapper.java	25 Jun 2004 15:36:38 -0000	1.21
  @@ -17,7 +17,6 @@
   
   import java.io.IOException;
   import java.io.OutputStream;
  -import java.net.MalformedURLException;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
  @@ -44,16 +43,13 @@
       extends AbstractEnvironment {
   
       /** The wrapped environment */
  -    protected Environment environment;
  -
  -    /** The object model */
  -    protected Map objectModel;
  +    protected final Environment environment;
   
       /** The redirect url */
       protected String redirectURL;
   
       /** The request object */
  -    protected Request request;
  +    protected final Request request;
   
       /** The stream to output to */
       protected OutputStream outputStream;
  @@ -63,58 +59,18 @@
       protected boolean internalRedirect = false;
       
       /**
  -     * Constructs an EnvironmentWrapper object from a Request
  -     * and Response objects
  -     */
  -    public EnvironmentWrapper(Environment env,
  -                              String      requestURI,
  -                              String      queryString,
  -                              Logger      logger) {
  -        this(env, requestURI, queryString, logger,  false, null);
  -    }
  -
  -    /**
  -     * Constructs an EnvironmentWrapper object from a Request
  -     * and Response objects
  -     */
  -    public EnvironmentWrapper(Environment      env,
  -                              String           requestURI,
  -                              String           queryString,
  -                              Logger           logger,
  -                              boolean          rawMode,
  -                              String           view) {
  -        super(env.getURI(), view, env.getAction());
  -        init(env, requestURI, queryString, logger, rawMode, view);
  -        this.setURI(env.getURIPrefix(), env.getURI());
  -    }
  -    
  -    /**
  -     * Constructor
  -     * @param env
  -     * @param uri
  -     * @param logger
  -     * @throws MalformedURLException
  -     */
  -    public EnvironmentWrapper(Environment env, String uri,  Logger logger) throws MalformedURLException
{
  -        super(env.getURI(), env.getView(), env.getAction());
  -
  -        SitemapSourceInfo info = SitemapSourceInfo.parseURI(env, uri);
  -
  -        this.init(env, info.requestURI, info.queryString, logger, info.rawMode, info.view);
  -        this.setURI(info.prefix, info.uri);
  +     * Construct a new environment
  +     * @param env    The origial Environment
  +     * @param info   A description of the uri for the new environment
  +     * @param logger The logger to be used by this environment
  +     */
  +    public EnvironmentWrapper(Environment       env,
  +                              SitemapSourceInfo info,
  +                              Logger            logger) {
  +        super(env.getURI(), info.view, env.getAction());
           
  -    }
  -    
  -    private void init(Environment    env,
  -                      String         requestURI,
  -                      String         queryString,
  -                      Logger         logger,
  -                      boolean        rawMode,
  -                      String         view){
  -
           this.enableLogging(logger);
           this.environment = env;
  -        this.view = view;
   
           // create new object model and replace the request object
           Map oldObjectModel = env.getObjectModel();
  @@ -130,13 +86,15 @@
               }
           }
           this.request = new RequestWrapper(ObjectModelHelper.getRequest(oldObjectModel),
  -                                          requestURI,
  -                                          queryString,
  +                                          info.requestURI,
  +                                          info.queryString,
                                             this,
  -                                          rawMode);
  +                                          info.rawMode);
           this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, this.request);
  +
  +        this.setURI(info.prefix, info.uri);        
       }
  -   
  +    
       /* (non-Javadoc)
        * @see org.apache.cocoon.environment.Environment#redirect(java.lang.String, boolean,
boolean)
        */
  @@ -231,13 +189,6 @@
        */
       public String getContentType() {
           return this.contentType;
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.cocoon.environment.Environment#getObjectModel()
  -     */
  -    public Map getObjectModel() {
  -        return this.objectModel;
       }
   
       /**
  
  
  
  1.4       +6 -41     cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java
  
  Index: ConcreteTreeProcessor.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/ConcreteTreeProcessor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConcreteTreeProcessor.java	11 Jun 2004 20:03:35 -0000	1.3
  +++ ConcreteTreeProcessor.java	25 Jun 2004 15:36:38 -0000	1.4
  @@ -16,7 +16,6 @@
   package org.apache.cocoon.components.treeprocessor;
   
   import java.io.IOException;
  -import java.net.MalformedURLException;
   import java.util.Collections;
   import java.util.HashMap;
   import java.util.List;
  @@ -29,17 +28,18 @@
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.Processor;
   import org.apache.cocoon.components.ChainedConfiguration;
   import org.apache.cocoon.components.container.ComponentManagerWrapper;
  +import org.apache.cocoon.components.source.impl.SitemapSourceInfo;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.environment.ForwardRedirector;
   import org.apache.cocoon.environment.Redirector;
   import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.environment.internal.EnvironmentHelper;
  +import org.apache.cocoon.environment.internal.ForwardEnvironmentWrapper;
   import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
   import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade;
   import org.apache.cocoon.sitemap.SitemapExecutor;
  @@ -318,7 +318,8 @@
   
           // test if this is a call from flow
           boolean isRedirect = (environment.getObjectModel().remove("cocoon:forward") ==
null);
  -        Environment newEnv = new ForwardEnvironmentWrapper(environment, uri, getLogger());
  +        final SitemapSourceInfo info = SitemapSourceInfo.parseURI(environment, uri);
  +        Environment newEnv = new ForwardEnvironmentWrapper(environment, info, getLogger());
           if ( isRedirect ) {
               ((ForwardEnvironmentWrapper)newEnv).setInternalRedirect(true);
           }
  @@ -384,43 +385,7 @@
           }
       }
   
  -    /**
  -     * Local extension of EnvironmentWrapper to propagate otherwise blocked
  -     * methods to the actual environment.
  -     */
  -    private static final class ForwardEnvironmentWrapper extends EnvironmentWrapper {
  -
  -        public ForwardEnvironmentWrapper(Environment env,
  -            String uri, Logger logger) throws MalformedURLException {
  -            super(env, uri, logger);
  -        }
  -
  -        public void setStatus(int statusCode) {
  -            environment.setStatus(statusCode);
  -        }
  -
  -        public void setContentLength(int length) {
  -            environment.setContentLength(length);
  -        }
  -
  -        public void setContentType(String contentType) {
  -            environment.setContentType(contentType);
  -        }
  -
  -        public String getContentType() {
  -            return environment.getContentType();
  -        }
  -
  -        public boolean isResponseModified(long lastModified) {
  -            return environment.isResponseModified(lastModified);
  -        }
  -
  -        public void setResponseIsNotModified() {
  -            environment.setResponseIsNotModified();
  -        }
  -    }
  -
  -	public SourceResolver getSourceResolver() {
  +    public SourceResolver getSourceResolver() {
   		return wrappingProcessor.getSourceResolver();
   	}
   
  
  
  
  1.22      +2 -4      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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- SitemapSource.java	23 Jun 2004 17:13:00 -0000	1.21
  +++ SitemapSource.java	25 Jun 2004 15:36:39 -0000	1.22
  @@ -128,9 +128,7 @@
           }
   
           // create environment...
  -        EnvironmentWrapper wrapper = new EnvironmentWrapper(env, info.requestURI, 
  -                                                   info.queryString, logger, info.rawMode,
info.view);
  -        wrapper.setURI(info.prefix, info.uri);
  +        final EnvironmentWrapper wrapper = new EnvironmentWrapper(env, info, logger);
           
           // The environment is a facade whose delegate can be changed in case of internal
redirects
           this.environment = new MutableEnvironmentFacade(wrapper);
  
  
  

Mime
View raw message