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: 99   Methods: 4
NCLOC: 47   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PrivateAsset.java 50% 76.9% 75% 73.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.ClasspathResource;
 24    import org.apache.tapestry.IRequestCycle;
 25    import org.apache.tapestry.Tapestry;
 26    import org.apache.tapestry.engine.IEngineService;
 27    import org.apache.tapestry.engine.ILink;
 28   
 29    /**
 30    * An implementation of {@link org.apache.tapestry.IAsset}for localizable assets within the JVM's
 31    * classpath.
 32    * <p>
 33    * The localization code here is largely cut-and-paste from {@link ContextAsset}.
 34    *
 35    * @author Howard Ship
 36    */
 37   
 38    public class PrivateAsset extends AbstractAsset
 39    {
 40    private IEngineService _assetService;
 41   
 42    /**
 43    * @deprecated To be removed (someday). Use
 44    * {@link #PrivateAsset(ClasspathResource, IEngineService, Location)}&nbsp;instead.
 45    */
 46  0 public PrivateAsset(ClasspathResource resourceLocation, Location location)
 47    {
 48  0 this(resourceLocation, null, location);
 49    }
 50   
 51  75 public PrivateAsset(ClasspathResource resourceLocation, IEngineService assetService,
 52    Location location)
 53    {
 54  75 super(resourceLocation, location);
 55   
 56  75 _assetService = assetService;
 57    }
 58   
 59    /**
 60    * Gets the localized version of the resource. Build the URL for the resource. If possible, the
 61    * application's {@link AssetExternalizerImpl}is located, to copy the resource to a directory
 62    * visible to the web server.
 63    */
 64   
 65  77 public String buildURL(IRequestCycle cycle)
 66    {
 67  77 String path = getResourceLocation().getPath();
 68   
 69    // ClasspathAssetFactory will provide the asset service as a constructor
 70    // parameter, but there are a few odd uses of PrivateAsset where this
 71    // is not handy.
 72   
 73  77 if (_assetService == null)
 74  0 _assetService = cycle.getEngine().getService(Tapestry.ASSET_SERVICE);
 75   
 76  77 ILink link = _assetService.getLink(cycle, false, path);
 77   
 78  77 return link.getURL();
 79    }
 80   
 81  1 public InputStream getResourceAsStream(IRequestCycle cycle)
 82    {
 83  1 Resource location = getResourceLocation();
 84   
 85  1 try
 86    {
 87  1 URL url = location.getResourceURL();
 88   
 89  1 return url.openStream();
 90    }
 91    catch (Exception ex)
 92    {
 93  0 throw new ApplicationRuntimeException(Tapestry.format(
 94    "PrivateAsset.resource-missing",
 95    location), ex);
 96    }
 97    }
 98   
 99    }