cziegeler    2004/01/05 02:53:35

  Modified:    src/java/org/apache/cocoon/components/cprocessor/sitemap
                        MountNode.java
               src/java/org/apache/cocoon/environment
                        EnvironmentHelper.java
  Log:
  Add method for resetting the environment context
  
  Revision  Changes    Path
  1.4       +2 -3      
cocoon-2.2/src/java/org/apache/cocoon/components/cprocessor/sitemap/MountNode.java
  
  Index: MountNode.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/cprocessor/sitemap/MountNode.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MountNode.java    5 Jan 2004 08:16:00 -0000       1.3
  +++ MountNode.java    5 Jan 2004 10:53:35 -0000       1.4
  @@ -151,8 +151,7 @@
               }
           } finally {
               // Restore context
  -            //FIXME - Reset the context
  -            processor.getEnvironmentHelper().setContext(env);
  +            processor.getEnvironmentHelper().resetContext(env);
   
               // Turning recomposing as a test, according to:
               // http://marc.theaimsgroup.com/?t=106802211400005&r=1&w=2
  
  
  
  1.13      +41 -25    
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java
  
  Index: EnvironmentHelper.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- EnvironmentHelper.java    5 Jan 2004 08:16:00 -0000       1.12
  +++ EnvironmentHelper.java    5 Jan 2004 10:53:35 -0000       1.13
  @@ -96,9 +96,6 @@
        /** The Context path */
       protected String context;
   
  -    /** The root context path */
  -    protected String rootContext;
  -
       /** The last prefix, which is stripped off from the request uri */
       protected String lastPrefix;
       
  @@ -109,12 +106,14 @@
        */
       public EnvironmentHelper(String context) {
           this.context = context;
  -        this.rootContext = context;
       }
       
  +    /**
  +     * Constructor
  +     *
  +     */
       public EnvironmentHelper(EnvironmentHelper parent) {
           this.context = parent.context;
  -        this.rootContext = parent.rootContext;
           this.lastPrefix = parent.lastPrefix;
           this.prefix = parent.prefix;
       }
  @@ -126,21 +125,15 @@
           this.manager = manager;
           this.resolver = (org.apache.excalibur.source.SourceResolver)
                             
this.manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE);
  -        if (this.context != null) {
  -            Source source = null;
  -            try {
  -                source = this.resolver.resolveURI(this.context);
  -                this.context = source.getURI();
  -                    
  -                if (this.rootContext == null) {// hack for EnvironmentWrapper
  -                    this.rootContext = this.context;
  -                }
  -            } catch (IOException ioe) {
  -                throw new ServiceException("EnvironmentHelper", "Unable to 
resolve environment context. ", ioe);
  -            } finally {
  -                this.resolver.release(source);
  -            }
  -            //this.context = null;
  +        Source source = null;
  +        try {
  +            source = this.resolver.resolveURI(this.context);
  +            this.context = source.getURI();
  +                
  +        } catch (IOException ioe) {
  +            throw new ServiceException("EnvironmentHelper", "Unable to 
resolve environment context. ", ioe);
  +        } finally {
  +            this.resolver.release(source);
           }
       }
   
  @@ -196,6 +189,12 @@
           return this.prefix;
       }
       
  +    /**
  +     * Change the context of the environment.
  +     * Call [EMAIL PROTECTED] #resetContext(Environment) to undo the change
  +     * @param env The environment to change
  +     * @throws ProcessingException
  +     */
       public void changeContext(Environment env) 
       throws ProcessingException {
           if ( this.lastPrefix != null ) {
  @@ -212,12 +211,30 @@
           }
       }
       
  +    /**
  +     * Reset the context of the environment. Use this together 
  +     * with [EMAIL PROTECTED] #changeContext(environment)}
  +     * @param env The environment to change
  +     * @throws ProcessingException
  +     */
  +    public void resetContext(Environment env) 
  +    throws ProcessingException {
  +        if (this.lastPrefix != null ) {
  +            // FIXME - This is not correct!
  +            env.setURI("", this.lastPrefix + env.getURI());
  +        }
  +    }
  +
  +    /**
  +     * Set the context of the environment.
  +     * @param env The environment to change
  +     * @throws ProcessingException
  +     */
       public void setContext(Environment env) 
       throws ProcessingException {
  -        //TODO
  -        /*
           if ( this.prefix != null ) {
  -            String uris = env.getURI();
  +            // FIXME - This is not correct!
  +            String uris = env.getURIPrefix() + env.getURI();
               if (!uris.startsWith(this.prefix)) {
                   String message = "The current URI (" + uris +
                                    ") doesn't start with given prefix (" + 
this.prefix + ")";
  @@ -228,7 +245,6 @@
               final int l = this.prefix.length();
               env.setURI(this.prefix, uris.substring(l));
           }
  -        */
       }
   
       /**
  
  
  

Reply via email to