You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2005/08/05 00:15:34 UTC

cvs commit: jakarta-tapestry/framework/src/test/org/apache/tapestry/record TestClientPropertyPersistenceStrategy.java

hlship      2005/08/04 15:15:34

  Modified:    .        status.xml
               framework/src/java/org/apache/tapestry/record
                        ClientPropertyPersistenceStrategy.java
                        PageClientPropertyPersistenceScope.java
                        AppClientPropertyPersistenceScope.java
                        ClientPropertyPersistenceScope.java
               framework/src/test/org/apache/tapestry/record
                        TestClientPropertyPersistenceStrategy.java
  Log:
  TAPESTRY-524: Client Side Persistence Scopes can conflict with each other
  
  Revision  Changes    Path
  1.184     +1 -0      jakarta-tapestry/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.183
  retrieving revision 1.184
  diff -u -r1.183 -r1.184
  --- status.xml	4 Aug 2005 18:36:16 -0000	1.183
  +++ status.xml	4 Aug 2005 22:15:33 -0000	1.184
  @@ -65,6 +65,7 @@
         <action type="fix" dev="PF" fixes-bug="TAPESTRY-521">Button component creates invalid markup</action>
         <action type="update" dev="PF">Deprecate label parameter of Button component</action>
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-527">Tapestry 4.0 DTD invalid</action>
  +      <action type="fix" dev="HLS" fixes-bug="TAPESTRY-524" due-to="Adam Greene">Client Side Persistence Scopes can conflict with each other</action>
       </release>
       <release version="4.0-beta-3" date="Jul 22 2005">
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-398" due-to="Jonas Maurus">HiveMind configuration error breaks the useage of the state: binding prefix</action>
  
  
  
  1.5       +19 -19    jakarta-tapestry/framework/src/java/org/apache/tapestry/record/ClientPropertyPersistenceStrategy.java
  
  Index: ClientPropertyPersistenceStrategy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/record/ClientPropertyPersistenceStrategy.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ClientPropertyPersistenceStrategy.java	6 Jul 2005 10:27:35 -0000	1.4
  +++ ClientPropertyPersistenceStrategy.java	4 Aug 2005 22:15:33 -0000	1.5
  @@ -39,12 +39,6 @@
   public class ClientPropertyPersistenceStrategy implements PropertyPersistenceStrategy
   {
       /**
  -     * Query parameters consist of this prefix followed by the page name. Each page gets its own
  -     * query parameter.
  -     */
  -    public static final String PREFIX = "state:";
  -
  -    /**
        * Keyed on page name (String), values are
        * {@link org.apache.tapestry.record.PersistentPropertyData}.
        */
  @@ -53,7 +47,7 @@
       private final PersistentPropertyDataEncoder _encoder;
   
       private WebRequest _request;
  -    
  +
       private ClientPropertyPersistenceScope _scope;
   
       public ClientPropertyPersistenceStrategy()
  @@ -83,10 +77,11 @@
           {
               String name = (String) i.next();
   
  -            if (!name.startsWith(PREFIX))
  +            if (!_scope.isParameterForScope(name))
                   continue;
   
  -            String pageName = name.substring(PREFIX.length());
  +            String pageName = _scope.extractPageName(name);
  +
               String encoded = _request.getParameterValue(name);
   
               PersistentPropertyData data = new PersistentPropertyData(_encoder);
  @@ -135,11 +130,14 @@
   
               String pageName = (String) e.getKey();
               PersistentPropertyData data = (PersistentPropertyData) e.getValue();
  -            
  +
               ClientPropertyPersistenceScope scope = getScope();
   
  -            if (scope.addParametersForPersistentProperties(encoding, cycle, pageName, data))
  -            	encoding.setParameterValue(PREFIX + pageName, data.getEncoded());
  +            if (scope.shouldEncodeState(encoding, cycle, pageName, data))
  +            {
  +                String parameterName = _scope.constructParameterName(pageName);
  +                encoding.setParameterValue(parameterName, data.getEncoded());
  +            }
           }
       }
   
  @@ -148,11 +146,13 @@
           _request = request;
       }
   
  -	public ClientPropertyPersistenceScope getScope() {
  -		return _scope;
  -	}
  -
  -	public void setScope(ClientPropertyPersistenceScope scope) {
  -		_scope = scope;
  -	}
  +    public ClientPropertyPersistenceScope getScope()
  +    {
  +        return _scope;
  +    }
  +
  +    public void setScope(ClientPropertyPersistenceScope scope)
  +    {
  +        _scope = scope;
  +    }
   }
  \ No newline at end of file
  
  
  
  1.3       +30 -10    jakarta-tapestry/framework/src/java/org/apache/tapestry/record/PageClientPropertyPersistenceScope.java
  
  Index: PageClientPropertyPersistenceScope.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/record/PageClientPropertyPersistenceScope.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PageClientPropertyPersistenceScope.java	16 Jul 2005 00:23:24 -0000	1.2
  +++ PageClientPropertyPersistenceScope.java	4 Aug 2005 22:15:33 -0000	1.3
  @@ -14,25 +14,45 @@
   
   package org.apache.tapestry.record;
   
  -
   import org.apache.tapestry.IRequestCycle;
   import org.apache.tapestry.engine.ServiceEncoding;
   
   /**
  - * Defines the 'page' scope for persisting client properties.
  - * Persist the properties only if the current page name is the same as that of the property. 
  + * Defines the 'page' scope for persisting client properties. Persist the properties only if the
  + * current page name is the same as that of the property.
    * 
    * @author Mindbridge
    * @since 4.0
    * @see org.apache.tapestry.record.ClientPropertyPersistenceScope
    */
  -public class PageClientPropertyPersistenceScope implements
  -		ClientPropertyPersistenceScope {
  +public class PageClientPropertyPersistenceScope implements ClientPropertyPersistenceScope
  +{
  +    private static final String PREFIX = "state:";
  +
  +    /**
  +     * Returns true if the active page name matches the page for this property. This means that
  +     * <em>after a new page has been activated</em>, the state is discarded.
  +     */
  +
  +    public boolean shouldEncodeState(ServiceEncoding encoding,
  +            IRequestCycle cycle, String pageName, PersistentPropertyData data)
  +    {
  +        return pageName.equals(cycle.getPage().getPageName());
  +    }
  +
  +    public String constructParameterName(String pageName)
  +    {
  +        return PREFIX + pageName;
  +    }
  +
  +    public boolean isParameterForScope(String parameterName)
  +    {
  +        return parameterName.startsWith(PREFIX);
  +    }
   
  -	public boolean addParametersForPersistentProperties(
  -			ServiceEncoding encoding, IRequestCycle cycle, String pageName,
  -			PersistentPropertyData data) {
  -		return pageName.equals(cycle.getPage().getPageName());
  -	}
  +    public String extractPageName(String parameterName)
  +    {
  +        return parameterName.substring(PREFIX.length());
  +    }
   
   }
  
  
  
  1.3       +29 -9     jakarta-tapestry/framework/src/java/org/apache/tapestry/record/AppClientPropertyPersistenceScope.java
  
  Index: AppClientPropertyPersistenceScope.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/record/AppClientPropertyPersistenceScope.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AppClientPropertyPersistenceScope.java	16 Jul 2005 00:23:24 -0000	1.2
  +++ AppClientPropertyPersistenceScope.java	4 Aug 2005 22:15:34 -0000	1.3
  @@ -18,20 +18,40 @@
   import org.apache.tapestry.engine.ServiceEncoding;
   
   /**
  - * Defines the 'app' scope for persisting client properties.
  - * Persist the properties in all cases. 
  + * Defines the 'app' scope for persisting client properties. Persist the properties in all cases.
    * 
    * @author Mindbridge
    * @since 4.0
    * @see org.apache.tapestry.record.ClientPropertyPersistenceScope
    */
  -public class AppClientPropertyPersistenceScope implements
  -		ClientPropertyPersistenceScope {
  +public class AppClientPropertyPersistenceScope implements ClientPropertyPersistenceScope
  +{
   
  -	public boolean addParametersForPersistentProperties(
  -			ServiceEncoding encoding, IRequestCycle cycle, String pageName,
  -			PersistentPropertyData data) {
  -		return true;
  -	}
  +    private final static String PREFIX = "appstate:";
  +
  +    /**
  +     * Always returns true.
  +     */
  +
  +    public boolean shouldEncodeState(ServiceEncoding encoding,
  +            IRequestCycle cycle, String pageName, PersistentPropertyData data)
  +    {
  +        return true;
  +    }
  +
  +    public String constructParameterName(String pageName)
  +    {
  +        return PREFIX + pageName;
  +    }
  +
  +    public boolean isParameterForScope(String parameterName)
  +    {
  +        return parameterName.startsWith(PREFIX);
  +    }
  +
  +    public String extractPageName(String parameterName)
  +    {
  +        return parameterName.substring(PREFIX.length());
  +    }
   
   }
  
  
  
  1.3       +51 -4     jakarta-tapestry/framework/src/java/org/apache/tapestry/record/ClientPropertyPersistenceScope.java
  
  Index: ClientPropertyPersistenceScope.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/record/ClientPropertyPersistenceScope.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ClientPropertyPersistenceScope.java	16 Jul 2005 00:23:24 -0000	1.2
  +++ ClientPropertyPersistenceScope.java	4 Aug 2005 22:15:34 -0000	1.3
  @@ -18,13 +18,60 @@
   import org.apache.tapestry.engine.ServiceEncoding;
   
   /**
  - * Service tapestry.persist.ClientPropertyPersistenceScope.
  - * Determines whether a particular property needs to be persisted or not. 
  + * Service tapestry.persist.ClientPropertyPersistenceScope. Determines whether a particular property
  + * needs to be persisted or not.
    * 
    * @author Mindbridge
    * @since 4.0
    * @see org.apache.tapestry.record.ClientPropertyPersistenceStrategy
    */
  -public interface ClientPropertyPersistenceScope {
  -	public boolean addParametersForPersistentProperties(ServiceEncoding encoding, IRequestCycle cycle, String pageName, PersistentPropertyData data);
  +public interface ClientPropertyPersistenceScope
  +{
  +    /**
  +     * Determines whether state should be encoded for the request.
  +     * 
  +     * @param encoding
  +     *            identifies the service, URL and base set of parameters
  +     * @param cycle
  +     *            current request
  +     * @param pageName
  +     *            the page for which data is potentially to be encoded
  +     * @param data
  +     * @return true if state should be encoded into the encoding, false otherwise
  +     */
  +
  +    public boolean shouldEncodeState(ServiceEncoding encoding, IRequestCycle cycle,
  +            String pageName, PersistentPropertyData data);
  +
  +    /**
  +     * Constructs a parameter name for a particular page name. The parameter name can be recognized
  +     * (in a later request) by the {@link #isParameterForScope(String)} method.
  +     * 
  +     * @param pageName
  +     *            the name of the page for which a corresponding parameter name should be generated.
  +     * @returns a query parameter name that identifies the page and this client persistence scope.
  +     */
  +
  +    public String constructParameterName(String pageName);
  +
  +    /**
  +     * Checks a parameter to see if it was the result of {@link #constructParameterName(String)} for
  +     * this persistence scope.
  +     * 
  +     * @param parameterName
  +     *            a query parameter name
  +     * @return true if the parameterName was genereted (i.e., is properly prefixed) by this scope,
  +     *         false otherwise.
  +     */
  +
  +    public boolean isParameterForScope(String parameterName);
  +
  +    /**
  +     * Extracts a page name from a query parameter name.
  +     * 
  +     * @param parameterName
  +     *            the paramter name, for which {@link #isParameterForScope(String) must return true
  +     * @return the name of the page
  +     */
  +    public String extractPageName(String parameterName);
   }
  
  
  
  1.5       +25 -13    jakarta-tapestry/framework/src/test/org/apache/tapestry/record/TestClientPropertyPersistenceStrategy.java
  
  Index: TestClientPropertyPersistenceStrategy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/record/TestClientPropertyPersistenceStrategy.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestClientPropertyPersistenceStrategy.java	6 Jul 2005 10:28:32 -0000	1.4
  +++ TestClientPropertyPersistenceStrategy.java	4 Aug 2005 22:15:34 -0000	1.5
  @@ -42,6 +42,18 @@
           requestc.setReturnValue(Arrays.asList(new Object[]
           { "foo", "state:MyPage" }));
   
  +        MockControl scopec = newControl(ClientPropertyPersistenceScope.class);
  +        ClientPropertyPersistenceScope scope = (ClientPropertyPersistenceScope) scopec.getMock();
  +
  +        scope.isParameterForScope("foo");
  +        scopec.setReturnValue(false);
  +
  +        scope.isParameterForScope("state:MyPage");
  +        scopec.setReturnValue(true);
  +
  +        scope.extractPageName("state:MyPage");
  +        scopec.setReturnValue("MyPage");
  +
           request.getParameterValue("state:MyPage");
           requestc.setReturnValue("ENCODED");
   
  @@ -57,6 +69,7 @@
   
           ClientPropertyPersistenceStrategy strategy = new ClientPropertyPersistenceStrategy(encoder);
           strategy.setRequest(request);
  +        strategy.setScope(scope);
   
           strategy.initializeService();
   
  @@ -97,12 +110,12 @@
   
           request.getParameterNames();
           requestc.setReturnValue(Arrays.asList(new Object[]
  -        { "foo", "state:MyPage" }));
  +        { "bar", "appstate:MyPage" }));
   
  -        request.getParameterValue("state:MyPage");
  +        request.getParameterValue("appstate:MyPage");
           requestc.setReturnValue("ENCODED");
   
  -        encoding.setParameterValue("state:MyPage", "ENCODED");
  +        encoding.setParameterValue("appstate:MyPage", "ENCODED");
   
           replayControls();
   
  @@ -111,13 +124,12 @@
           strategy.setScope(new AppClientPropertyPersistenceScope());
   
           strategy.initializeService();
  -        
  +
           strategy.addParametersForPersistentProperties(encoding, cycle);
   
           verifyControls();
  -
       }
  -    
  +
       public void testPageScope()
       {
           MockControl requestc = newControl(WebRequest.class);
  @@ -125,24 +137,24 @@
   
           MockControl cyclec = newControl(IRequestCycle.class);
           IRequestCycle cycle = (IRequestCycle) cyclec.getMock();
  -        
  +
           MockControl pagec = newControl(IPage.class);
           IPage page = (IPage) pagec.getMock();
  -        
  +
           ServiceEncoding encoding = (ServiceEncoding) newMock(ServiceEncoding.class);
   
           cycle.getPage();
           cyclec.setReturnValue(page);
  -        
  +
           cycle.getPage();
           cyclec.setReturnValue(page);
  -        
  +
           page.getPageName();
           pagec.setReturnValue("MyPage");
  -        
  +
           page.getPageName();
           pagec.setReturnValue("MyPage");
  -        
  +
           request.getParameterNames();
           requestc.setReturnValue(Arrays.asList(new Object[]
           { "foo", "state:MyPage", "state:OtherPage" }));
  @@ -162,7 +174,7 @@
           strategy.setScope(new PageClientPropertyPersistenceScope());
   
           strategy.initializeService();
  -        
  +
           strategy.addParametersForPersistentProperties(encoding, cycle);
   
           verifyControls();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org