Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 83   Methods: 3
NCLOC: 42   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ContextAsset.java 50% 90.9% 100% 87.5%
coverage coverage
 1    // Copyright 2004, 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.asset;
 16   
 17    import java.io.InputStream;
 18    import java.net.URL;
 19   
 20    import org.apache.hivemind.ApplicationRuntimeException;
 21    import org.apache.hivemind.Location;
 22    import org.apache.hivemind.Resource;
 23    import org.apache.hivemind.util.Defense;
 24    import org.apache.tapestry.IAsset;
 25    import org.apache.tapestry.IRequestCycle;
 26    import org.apache.tapestry.Tapestry;
 27   
 28    /**
 29    * An asset whose path is relative to the {@link javax.servlet.ServletContext}containing the
 30    * application.
 31    *
 32    * @author Howard Lewis Ship
 33    */
 34   
 35    public class ContextAsset extends AbstractAsset implements IAsset
 36    {
 37    private String _contextPath;
 38   
 39    private String _resolvedURL;
 40   
 41    private IRequestCycle _requestCycle;
 42   
 43  18 public ContextAsset(String contextPath, Resource resource, Location location, IRequestCycle cycle)
 44    {
 45  18 super(resource, location);
 46   
 47  18 Defense.notNull(contextPath, "contextPath");
 48   
 49  18 _contextPath = contextPath;
 50   
 51  18 _requestCycle = cycle;
 52    }
 53   
 54    /**
 55    * Generates a URL for the client to retrieve the asset. The context path is prepended to the
 56    * asset path, which means that assets deployed inside web applications will still work (if
 57    * things are configured properly).
 58    */
 59   
 60  12 public String buildURL()
 61    {
 62  12 if (_resolvedURL == null)
 63  12 _resolvedURL = _contextPath + getResourceLocation().getPath();
 64   
 65  12 return _requestCycle.encodeURL(_resolvedURL);
 66    }
 67   
 68  2 public InputStream getResourceAsStream()
 69    {
 70  2 try
 71    {
 72  2 URL url = getResourceLocation().getResourceURL();
 73   
 74  2 return url.openStream();
 75    }
 76    catch (Exception ex)
 77    {
 78  0 throw new ApplicationRuntimeException(Tapestry.format(
 79    "ContextAsset.resource-missing",
 80    getResourceLocation()), ex);
 81    }
 82    }
 83    }