cziegeler    2003/01/30 23:35:32

  Modified:    src/scratchpad/src/org/apache/cocoon/components/source/impl
                        SlideSource.java
               src/java/org/apache/cocoon/transformation
                        EncodeURLTransformer.java
  Log:
  Fixing (hopefully) encodeURL transformer and make it cacheable again
  Organizing imports
  
  Revision  Changes    Path
  1.31      +3 -24     
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/impl/SlideSource.java
  
  Index: SlideSource.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/components/source/impl/SlideSource.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- SlideSource.java  30 Jan 2003 20:01:07 -0000      1.30
  +++ SlideSource.java  31 Jan 2003 07:35:32 -0000      1.31
  @@ -58,61 +58,40 @@
   import java.util.ArrayList;
   import java.util.Date;
   import java.util.Enumeration;
  -import java.util.Iterator;
   import java.util.Vector;
   
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  -
   import org.apache.cocoon.CascadingIOException;
   import org.apache.cocoon.Constants;
  -import org.apache.cocoon.components.source.InspectableSource;
  -import org.apache.cocoon.components.source.LockableSource;
  -import org.apache.cocoon.components.source.ModifiableTraversableSource;
  -import org.apache.cocoon.components.source.MoveableSource;
  -import org.apache.cocoon.components.source.RestrictableSource;
  -import org.apache.cocoon.components.source.VersionableSource;
  -import org.apache.cocoon.components.source.WriteableSource;
  +import org.apache.cocoon.components.source.*;
   import org.apache.cocoon.components.source.helpers.GroupSourcePermission;
   import org.apache.cocoon.components.source.helpers.PrincipalSourcePermission;
   import org.apache.cocoon.components.source.helpers.SourceCredential;
   import org.apache.cocoon.components.source.helpers.SourceLock;
   import org.apache.cocoon.components.source.helpers.SourcePermission;
   import org.apache.cocoon.components.source.helpers.SourceProperty;
  -
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceValidity;
   import org.apache.excalibur.source.impl.validity.TimeStampValidity;
  -
   import org.apache.slide.authenticate.CredentialsToken;
   import org.apache.slide.common.NamespaceAccessToken;
   import org.apache.slide.common.NamespaceConfig;
   import org.apache.slide.common.SlideException;
   import org.apache.slide.common.SlideToken;
   import org.apache.slide.common.SlideTokenImpl;
  -import org.apache.slide.content.Content;
  -import org.apache.slide.content.NodeProperty;
  -import org.apache.slide.content.NodeRevisionContent;
  -import org.apache.slide.content.NodeRevisionDescriptor;
  -import org.apache.slide.content.NodeRevisionDescriptors;
  -import org.apache.slide.content.NodeRevisionNumber;
  -import org.apache.slide.content.RevisionDescriptorNotFoundException;
  +import org.apache.slide.content.*;
   import org.apache.slide.lock.Lock;
   import org.apache.slide.lock.NodeLock;
   import org.apache.slide.macro.Macro;
  -import org.apache.slide.security.AccessDeniedException;
   import org.apache.slide.security.NodePermission;
   import org.apache.slide.security.Security;
   import org.apache.slide.structure.GroupNode;
  -import org.apache.slide.structure.LinkedObjectNotFoundException;
   import org.apache.slide.structure.ObjectNode;
   import org.apache.slide.structure.ObjectNotFoundException;
   import org.apache.slide.structure.Structure;
  
  
  
  1.8       +41 -53    
xml-cocoon2/src/java/org/apache/cocoon/transformation/EncodeURLTransformer.java
  
  Index: EncodeURLTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/EncodeURLTransformer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- EncodeURLTransformer.java 27 Jan 2003 07:43:33 -0000      1.7
  +++ EncodeURLTransformer.java 31 Jan 2003 07:35:32 -0000      1.8
  @@ -57,7 +57,7 @@
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.cocoon.ProcessingException;
  -//import org.apache.cocoon.caching.CacheableProcessingComponent;
  +import org.apache.cocoon.caching.CacheableProcessingComponent;
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.environment.Response;
  @@ -85,7 +85,7 @@
    *   URLs introduced in the generator, and xslt transformer phase.
    * </p>
    * <p>
  - *   You can specify which attributes hold an URL values in order to restrict
  + *   You can specify which attributes hold URL values in order to restrict
    *   URL rewriting to specific attributes only.
    * </p>
    * <p>
  @@ -124,7 +124,7 @@
    */
   public class EncodeURLTransformer
     extends AbstractTransformer
  -  implements Configurable {
  +  implements Configurable, CacheableProcessingComponent {
   
       /**
        * Configuration name for specifying excluding patterns,
  @@ -155,39 +155,27 @@
   
       private ElementAttributeMatching elementAttributeMatching;
       private Response response;
  -    private Request request;
  -
  -
  -    /**
  -     * get the session from the request.
  -     * 
  -     * @return Session object, or null if no session is available
  -     */
  -    protected Session getSession() {
  -        // assume that request is already set
  -        Session session = this.request.getSession( false );
  -        return session;
  -    }
  +    private boolean isEncodeURLNeeded;
  +    private Session session;
   
       /**
        * check if encoding of URLs is neccessary.
        * 
  -     * @return true iff session object exists, and session-id 
  -     *   was provided from URL, or session is new,
  -     *   else return false
  -     */
  -    protected boolean isEncodeURLNeeded() {
  -        Session session = getSession();
  -        boolean isEncodeURLNeeded = false;
  +     * THis is true if session object exists, and session-id   
  +     * was provided from URL, or session is new.
  +     * The result is stored in some instance variables
  +     */
  +    protected void checkForEncoding(Request request) {
  +        this.session = request.getSession();
  +        this.isEncodeURLNeeded = false;
           
  -        if ( null != session ) {
  +        if ( null != this.session ) {
               // do encoding if session id is from URL, or the session is new, 
               // fixes BUG #13855, due to [EMAIL PROTECTED]
  -            if ( request.isRequestedSessionIdFromURL() || session.isNew()) {
  -                isEncodeURLNeeded = true;
  +            if ( request.isRequestedSessionIdFromURL() || this.session.isNew()) {
  +                this.isEncodeURLNeeded = true;
               }
           }
  -        return isEncodeURLNeeded;
       }
                   
   
  @@ -206,21 +194,24 @@
       public void setup(SourceResolver resolver, Map objectModel, String source, 
Parameters parameters)
       throws ProcessingException, SAXException, IOException {
   
  -        this.request = ObjectModelHelper.getRequest(objectModel);
  -        this.response = ObjectModelHelper.getResponse(objectModel);
  +        this.checkForEncoding(ObjectModelHelper.getRequest(objectModel));
  +        
  +        if (this.isEncodeURLNeeded) {
  +            this.response = ObjectModelHelper.getResponse(objectModel);
   
  -        // don't check if URL encoding is needed now, as
  -        // a generator might create a new session 
  -        final String includeName = parameters.getParameter(INCLUDE_NAME,
  -                                                           
this.includeNameConfigure);
  -        final String excludeName = parameters.getParameter(EXCLUDE_NAME,
  -                                                           
this.excludeNameConfigure);
  -        try {
  -            this.elementAttributeMatching = new 
ElementAttributeMatching(includeName, excludeName);
  -        } catch (RESyntaxException reex) {
  -            final String message = "Cannot parse include-name: " + includeName + " 
" +
  -                "or exclude-name: " + excludeName + "!";
  -            throw new ProcessingException(message, reex);
  +            // don't check if URL encoding is needed now, as
  +            // a generator might create a new session 
  +            final String includeName = parameters.getParameter(INCLUDE_NAME,
  +                                                               
this.includeNameConfigure);
  +            final String excludeName = parameters.getParameter(EXCLUDE_NAME,
  +                                                               
this.excludeNameConfigure);
  +            try {
  +                this.elementAttributeMatching = new 
ElementAttributeMatching(includeName, excludeName);
  +            } catch (RESyntaxException reex) {
  +                final String message = "Cannot parse include-name: " + includeName 
+ " " +
  +                    "or exclude-name: " + excludeName + "!";
  +                throw new ProcessingException(message, reex);
  +            }
           }
       }
   
  @@ -257,7 +248,7 @@
       public void recycle() {
           super.recycle();
           this.response = null;
  -        this.request = null;
  +        this.session = null;
           this.elementAttributeMatching = null;
       }
   
  @@ -269,7 +260,7 @@
        * @return The generated key hashes the src
        */
       public java.io.Serializable generateKey() {
  -        if (isEncodeURLNeeded()) {
  +        if (this.isEncodeURLNeeded) {
               return null;
           } else {
               return "1";
  @@ -283,7 +274,7 @@
        *         component is currently not cacheable.
        */
       public SourceValidity generateValidity() {
  -        if (isEncodeURLNeeded()) {
  +        if (this.isEncodeURLNeeded) {
               return null;
           } else {
               return NOPValidity.SHARED_INSTANCE;
  @@ -301,9 +292,7 @@
        */
       public void startElement(String uri, String name, String raw, Attributes 
attributes)
       throws SAXException {
  -        boolean isEncodeURLNeeded = isEncodeURLNeeded();
  -
  -        if (isEncodeURLNeeded && this.elementAttributeMatching != null) {
  +        if (this.isEncodeURLNeeded && this.elementAttributeMatching != null) {
               String lname = name;
               if (attributes != null && attributes.getLength() > 0) {
                   AttributesImpl new_attributes = new AttributesImpl(attributes);
  @@ -347,15 +336,14 @@
        */
       private String encodeURL(String url, Response response) {
           String encoded_url;
  -        if (response != null) {
  +        if (this.response != null) {
               // As some servlet-engine does not check if url has been already 
rewritten
  -            Session session = getSession();
  -            if (session != null && url.indexOf(session.getId()) > -1) {
  +            if (this.session != null && url.indexOf(this.session.getId()) > -1) {
                   // url contains already the session id encoded
                   encoded_url = url;
               } else {
                   // do encode the session id
  -                encoded_url = response.encodeURL(url);
  +                encoded_url = this.response.encodeURL(url);
               }
           } else {
               encoded_url = url;
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to