Coverage Report - org.apache.tapestry.engine.encoders.DirectServiceEncoder
 
Classes in this File Line Coverage Branch Coverage Complexity
DirectServiceEncoder
0%
0/37
0%
0/14
3.75
 
 1  
 // Copyright 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.engine.encoders;
 16  
 
 17  
 import org.apache.tapestry.INamespace;
 18  
 import org.apache.tapestry.Tapestry;
 19  
 import org.apache.tapestry.engine.ServiceEncoder;
 20  
 import org.apache.tapestry.engine.ServiceEncoding;
 21  
 import org.apache.tapestry.services.ServiceConstants;
 22  
 
 23  
 /**
 24  
  * A specialized encoder for the
 25  
  * {@link org.apache.tapestry.engine.DirectService direct service}  that
 26  
  * encodes the page name and component id path into the servlet path, and
 27  
  * encodes the stateful flag by choosing one of two extensions.
 28  
  * 
 29  
  * @author Howard M. Lewis Ship
 30  
  * @since 4.0
 31  
  */
 32  0
 public class DirectServiceEncoder implements ServiceEncoder
 33  
 {
 34  
 
 35  
     private String _statelessExtension;
 36  
 
 37  
     private String _statefulExtension;
 38  
 
 39  
     public void encode(ServiceEncoding encoding)
 40  
     {
 41  0
         String service = encoding.getParameterValue(ServiceConstants.SERVICE);
 42  0
         if (!service.equals(Tapestry.DIRECT_SERVICE)) return;
 43  
 
 44  0
         String pageName = encoding.getParameterValue(ServiceConstants.PAGE);
 45  
 
 46  
         // Only handle pages in the application namespace (not from a library).
 47  
 
 48  0
         if (pageName.indexOf(INamespace.SEPARATOR) >= 0) return;
 49  
 
 50  0
         String stateful = encoding.getParameterValue(ServiceConstants.SESSION);
 51  0
         String componentIdPath = encoding
 52  
                 .getParameterValue(ServiceConstants.COMPONENT);
 53  
 
 54  0
         StringBuffer buffer = new StringBuffer("/");
 55  0
         buffer.append(pageName);
 56  
 
 57  0
         buffer.append(",");
 58  0
         buffer.append(componentIdPath);
 59  
 
 60  0
         buffer.append(".");
 61  0
         buffer.append(stateful != null ? _statefulExtension
 62  
                 : _statelessExtension);
 63  
 
 64  0
         encoding.setServletPath(buffer.toString());
 65  
 
 66  0
         encoding.setParameterValue(ServiceConstants.SERVICE, null);
 67  0
         encoding.setParameterValue(ServiceConstants.PAGE, null);
 68  0
         encoding.setParameterValue(ServiceConstants.SESSION, null);
 69  0
         encoding.setParameterValue(ServiceConstants.COMPONENT, null);
 70  0
     }
 71  
 
 72  
     public void decode(ServiceEncoding encoding)
 73  
     {
 74  0
         String servletPath = encoding.getServletPath();
 75  
 
 76  0
         int dotx = servletPath.lastIndexOf('.');
 77  0
         if (dotx < 0) return;
 78  
 
 79  0
         String extension = servletPath.substring(dotx + 1);
 80  
 
 81  0
         if (!(extension.equals(_statefulExtension) || extension
 82  0
                 .equals(_statelessExtension))) return;
 83  
 
 84  0
         int commax = servletPath.lastIndexOf(',');
 85  
 
 86  0
         String pageName = servletPath.substring(1, commax);
 87  0
         String componentIdPath = servletPath.substring(commax + 1, dotx);
 88  
 
 89  0
         encoding.setParameterValue(ServiceConstants.SERVICE,
 90  
                 Tapestry.DIRECT_SERVICE);
 91  0
         encoding.setParameterValue(ServiceConstants.PAGE, pageName);
 92  0
         encoding.setParameterValue(ServiceConstants.SESSION, extension
 93  
                 .equals(_statefulExtension) ? "T" : null);
 94  0
         encoding.setParameterValue(ServiceConstants.COMPONENT, componentIdPath);
 95  0
     }
 96  
 
 97  
     public void setStatefulExtension(String statefulExtension)
 98  
     {
 99  0
         _statefulExtension = statefulExtension;
 100  0
     }
 101  
 
 102  
     public void setStatelessExtension(String statelessExtension)
 103  
     {
 104  0
         _statelessExtension = statelessExtension;
 105  0
     }
 106  
 }