Clover coverage report - Code Coverage for tapestry release 4.0-beta-9
Coverage timestamp: Sat Oct 1 2005 08:36:20 EDT
file stats: LOC: 97   Methods: 6
NCLOC: 49   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ContextAssetFactory.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.asset;
 16   
 17    import java.util.Locale;
 18   
 19    import org.apache.hivemind.ApplicationRuntimeException;
 20    import org.apache.hivemind.Location;
 21    import org.apache.hivemind.Resource;
 22    import org.apache.tapestry.IAsset;
 23    import org.apache.tapestry.web.WebContext;
 24    import org.apache.tapestry.web.WebContextResource;
 25   
 26    /**
 27    * All "context:" prefixed asset paths are interpreted relative to the web context (the web
 28    * application's root folder).
 29    *
 30    * @author Howard M. Lewis Ship
 31    * @since 4.0
 32    */
 33    public class ContextAssetFactory implements AssetFactory
 34    {
 35    private String _contextPath;
 36   
 37    private AssetFactory _classpathAssetFactory;
 38   
 39    private WebContext _webContext;
 40   
 41  8 public void setWebContext(WebContext webContext)
 42    {
 43  8 _webContext = webContext;
 44    }
 45   
 46  4 public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location)
 47    {
 48    // We always create a new asset relative to an existing resource; the type of resource
 49    // will jive with the type of asset returned. Path may start with a leading slash, which
 50    // yields an absolute, not relative, path to the resource.
 51   
 52  4 Resource assetResource = baseResource.getRelativeResource(path);
 53   
 54    // Here's the thing; In Tapestry 3.0 and earlier, you could specify
 55    // library path like /org/apache/tapestry/contrib/Contrib.library. In the new scheme
 56    // of things, that should be "classpath:/org/apache/tapestry/contrib/Contrib.library".
 57    // But to keep a lot of things from breaking, we'll kludgely allow that here.
 58   
 59  4 if (assetResource.getResourceURL() == null && path.startsWith("/"))
 60  2 return _classpathAssetFactory.createAbsoluteAsset(path, locale, location);
 61   
 62  2 Resource localized = assetResource.getLocalization(locale);
 63   
 64  2 if (localized == null)
 65  1 throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, baseResource),
 66    location, null);
 67   
 68  1 return createAsset(localized, location);
 69    }
 70   
 71  8 public IAsset createAbsoluteAsset(String path, Locale locale, Location location)
 72    {
 73  8 Resource base = new WebContextResource(_webContext, path);
 74  8 Resource localized = base.getLocalization(locale);
 75   
 76  8 if (localized == null)
 77  1 throw new ApplicationRuntimeException(AssetMessages.missingContextResource(path),
 78    location, null);
 79   
 80  7 return createAsset(localized, location);
 81    }
 82   
 83  8 public IAsset createAsset(Resource resource, Location location)
 84    {
 85  8 return new ContextAsset(_contextPath, resource, location);
 86    }
 87   
 88  11 public void setContextPath(String contextPath)
 89    {
 90  11 _contextPath = contextPath;
 91    }
 92   
 93  7 public void setClasspathAssetFactory(AssetFactory classpathAssetFactory)
 94    {
 95  7 _classpathAssetFactory = classpathAssetFactory;
 96    }
 97    }