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