Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 95   Methods: 7
NCLOC: 49   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WebContextResource.java 83.3% 94.7% 100% 93.8%
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.web;
 16   
 17    import java.net.URL;
 18    import java.util.Locale;
 19   
 20    import org.apache.hivemind.Resource;
 21    import org.apache.hivemind.util.AbstractResource;
 22    import org.apache.hivemind.util.LocalizedResource;
 23   
 24    /**
 25    * Implementation of {@link org.apache.hivemind.Resource}for resources found within a
 26    * {@link org.apache.tapestry.web.WebContext}.
 27    *
 28    * @author Howard Lewis Ship
 29    * @since 4.0
 30    */
 31   
 32    public class WebContextResource extends AbstractResource
 33    {
 34    private WebContext _context;
 35   
 36  1944 public WebContextResource(WebContext context, String path)
 37    {
 38  1944 this(context, path, null);
 39    }
 40   
 41  1956 public WebContextResource(WebContext context, String path, Locale locale)
 42    {
 43  1956 super(path, locale);
 44   
 45  1956 _context = context;
 46    }
 47   
 48    /**
 49    * Locates the resource using {@link LocalizedWebContextResourceFinder}and
 50    * {@link ServletContext#getResource(java.lang.String)}.
 51    */
 52   
 53  140 public Resource getLocalization(Locale locale)
 54    {
 55  140 LocalizedWebContextResourceFinder finder = new LocalizedWebContextResourceFinder(_context);
 56   
 57  140 String path = getPath();
 58  140 LocalizedResource localizedResource = finder.resolve(path, locale);
 59   
 60  140 if (localizedResource == null)
 61  4 return null;
 62   
 63  136 String localizedPath = localizedResource.getResourcePath();
 64  136 Locale pathLocale = localizedResource.getResourceLocale();
 65   
 66  136 if (localizedPath == null)
 67  0 return null;
 68   
 69  136 if (path.equals(localizedPath))
 70  126 return this;
 71   
 72  10 return new WebContextResource(_context, localizedPath, pathLocale);
 73    }
 74   
 75  1074 public URL getResourceURL()
 76    {
 77  1074 return _context.getResource(getPath());
 78    }
 79   
 80  118 public String toString()
 81    {
 82  118 return "context:" + getPath();
 83    }
 84   
 85  206 public int hashCode()
 86    {
 87  206 return 2387 & getPath().hashCode();
 88    }
 89   
 90  1838 protected Resource newResource(String path)
 91    {
 92  1838 return new WebContextResource(_context, path);
 93    }
 94   
 95    }