Clover coverage report - Code Coverage for tapestry release 4.0-beta-7
Coverage timestamp: Sat Sep 17 2005 14:18:59 EDT
file stats: LOC: 101   Methods: 7
NCLOC: 56   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ContextAssetFactory.java 75% 85.7% 85.7% 84%
coverage 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.ClassResolver;
 21    import org.apache.hivemind.Location;
 22    import org.apache.hivemind.Resource;
 23    import org.apache.hivemind.util.ClasspathResource;
 24    import org.apache.tapestry.IAsset;
 25    import org.apache.tapestry.engine.IEngineService;
 26    import org.apache.tapestry.web.WebContext;
 27    import org.apache.tapestry.web.WebContextResource;
 28   
 29    /**
 30    * For the moment, all "context:" prefixed asset paths are interpreted relative to the web context
 31    * (the web application's root folder).
 32    *
 33    * @author Howard M. Lewis Ship
 34    * @since 4.0
 35    */
 36    public class ContextAssetFactory implements AssetFactory
 37    {
 38    private WebContext _context;
 39   
 40    private String _contextPath;
 41   
 42    private Resource _servletRoot;
 43   
 44    private ClassResolver _classResolver;
 45   
 46    private IEngineService _assetService;
 47   
 48  6 public void initializeService()
 49    {
 50  6 _servletRoot = new WebContextResource(_context, "/");
 51    }
 52   
 53  7 public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location)
 54    {
 55  7 Resource assetResource = _servletRoot.getRelativeResource(path);
 56   
 57    // Here's the thing; In Tapestry 3.0 and earlier, you could specify
 58    // library path like /org/apache/tapestry/contrib/Contrib.library. In the new scheme
 59    // of things, that should be "classpath:/org/apache/tapestry/contrib/Contrib.library".
 60    // But to keep a lot of things from breaking, we'll kludgely allow that here.
 61   
 62  7 if (assetResource.getResourceURL() == null && path.startsWith("/"))
 63    {
 64  1 ClasspathResource resource = new ClasspathResource(_classResolver, path);
 65  1 return new PrivateAsset(resource, _assetService, location);
 66    }
 67   
 68  6 Resource localized = assetResource.getLocalization(locale);
 69   
 70  6 if (localized == null)
 71  0 throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, _servletRoot),
 72    location, null);
 73   
 74  6 return new ContextAsset(_contextPath, localized, location);
 75    }
 76   
 77  0 public IAsset createAsset(Resource resource, Location location)
 78    {
 79  0 return new ContextAsset(_contextPath, resource, location);
 80    }
 81   
 82  6 public void setContext(WebContext context)
 83    {
 84  6 _context = context;
 85    }
 86   
 87  6 public void setContextPath(String contextPath)
 88    {
 89  6 _contextPath = contextPath;
 90    }
 91   
 92  6 public void setAssetService(IEngineService assetService)
 93    {
 94  6 _assetService = assetService;
 95    }
 96   
 97  6 public void setClassResolver(ClassResolver classResolver)
 98    {
 99  6 _classResolver = classResolver;
 100    }
 101    }