Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 72   Methods: 3
NCLOC: 36   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AssetEncoder.java 100% 100% 100% 100%
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.Tapestry;
 18    import org.apache.tapestry.asset.AssetService;
 19    import org.apache.tapestry.engine.ServiceEncoder;
 20    import org.apache.tapestry.engine.ServiceEncoding;
 21    import org.apache.tapestry.services.ServiceConstants;
 22   
 23    /**
 24    * Encoder for the {@link org.apache.tapestry.asset.AssetService} that uses servlet path info
 25    * to store the resource digest and the path to the resource.
 26    *
 27    * @author Howard M. Lewis Ship
 28    * @since 4.0
 29    */
 30    public class AssetEncoder implements ServiceEncoder
 31    {
 32    private String _path;
 33   
 34  3 public void setPath(String path)
 35    {
 36  3 _path = path;
 37    }
 38   
 39  2 public void encode(ServiceEncoding encoding)
 40    {
 41  2 if (!encoding.getParameterValue(ServiceConstants.SERVICE).equals(Tapestry.ASSET_SERVICE))
 42  1 return;
 43   
 44  1 String path = encoding.getParameterValue(AssetService.PATH);
 45  1 String digest = encoding.getParameterValue(AssetService.DIGEST);
 46   
 47    // _path ends with a slash, path starts with one.
 48   
 49  1 String fullPath = _path + digest + path;
 50   
 51  1 encoding.setServletPath(fullPath);
 52  1 encoding.setParameterValue(AssetService.PATH, null);
 53  1 encoding.setParameterValue(AssetService.DIGEST, null);
 54  1 encoding.setParameterValue(ServiceConstants.SERVICE, null);
 55    }
 56   
 57  2 public void decode(ServiceEncoding encoding)
 58    {
 59  2 String fullPath = encoding.getServletPath();
 60   
 61  2 if (!fullPath.startsWith(_path))
 62  1 return;
 63   
 64  1 String pathInfo = fullPath.substring(_path.length());
 65  1 int slashx = pathInfo.indexOf('/');
 66   
 67  1 encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.ASSET_SERVICE);
 68  1 encoding.setParameterValue(AssetService.DIGEST, pathInfo.substring(0, slashx));
 69  1 encoding.setParameterValue(AssetService.PATH, pathInfo.substring(slashx));
 70    }
 71   
 72    }