Clover coverage report - Code Coverage for tapestry release 4.0-beta-6
Coverage timestamp: Wed Sep 7 2005 18:41:34 EDT
file stats: LOC: 105   Methods: 4
NCLOC: 59   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DirectServiceEncoder.java 91.7% 97.1% 100% 96.1%
coverage coverage
 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 {@link org.apache.tapestry.engine.DirectService direct service}
 25    *  that encodes the page name and component id path into the servlet path, and encodes the
 26    * stateful flag by choosing one of two extensions.
 27    *
 28    * @author Howard M. Lewis Ship
 29    * @since 4.0
 30    */
 31    public class DirectServiceEncoder implements ServiceEncoder
 32    {
 33    private String _statelessExtension;
 34   
 35    private String _statefulExtension;
 36   
 37  4 public void encode(ServiceEncoding encoding)
 38    {
 39  4 String service = encoding.getParameterValue(ServiceConstants.SERVICE);
 40  4 if (!service.equals(Tapestry.DIRECT_SERVICE))
 41  1 return;
 42   
 43  3 String pageName = encoding.getParameterValue(ServiceConstants.PAGE);
 44   
 45    // Only handle pages in the application namespace (not from a library).
 46   
 47  3 if (pageName.indexOf(INamespace.SEPARATOR) >= 0)
 48  1 return;
 49   
 50  2 String stateful = encoding.getParameterValue(ServiceConstants.SESSION);
 51  2 String componentIdPath = encoding.getParameterValue(ServiceConstants.COMPONENT);
 52   
 53  2 StringBuffer buffer = new StringBuffer("/");
 54  2 buffer.append(pageName);
 55   
 56  2 buffer.append(",");
 57  2 buffer.append(componentIdPath);
 58   
 59  2 buffer.append(".");
 60  2 buffer.append(stateful != null ? _statefulExtension : _statelessExtension);
 61   
 62  2 encoding.setServletPath(buffer.toString());
 63   
 64  2 encoding.setParameterValue(ServiceConstants.SERVICE, null);
 65  2 encoding.setParameterValue(ServiceConstants.PAGE, null);
 66  2 encoding.setParameterValue(ServiceConstants.SESSION, null);
 67  2 encoding.setParameterValue(ServiceConstants.COMPONENT, null);
 68    }
 69   
 70  3 public void decode(ServiceEncoding encoding)
 71    {
 72  3 String servletPath = encoding.getServletPath();
 73   
 74  3 int dotx = servletPath.lastIndexOf('.');
 75  3 if (dotx < 0)
 76  0 return;
 77   
 78  3 String extension = servletPath.substring(dotx + 1);
 79   
 80  3 if (!(extension.equals(_statefulExtension) || extension.equals(_statelessExtension)))
 81  1 return;
 82   
 83  2 int commax = servletPath.lastIndexOf(',');
 84   
 85  2 String pageName = servletPath.substring(1, commax);
 86  2 String componentIdPath = servletPath.substring(commax + 1, dotx);
 87   
 88  2 encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.DIRECT_SERVICE);
 89  2 encoding.setParameterValue(ServiceConstants.PAGE, pageName);
 90  2 encoding.setParameterValue(
 91    ServiceConstants.SESSION,
 92  2 extension.equals(_statefulExtension) ? "T" : null);
 93  2 encoding.setParameterValue(ServiceConstants.COMPONENT, componentIdPath);
 94    }
 95   
 96  4 public void setStatefulExtension(String statefulExtension)
 97    {
 98  4 _statefulExtension = statefulExtension;
 99    }
 100   
 101  4 public void setStatelessExtension(String statelessExtension)
 102    {
 103  4 _statelessExtension = statelessExtension;
 104    }
 105    }