Clover coverage report - Code Coverage for tapestry release 4.0-beta-4
Coverage timestamp: Wed Aug 10 2005 21:19:31 EDT
file stats: LOC: 97   Methods: 7
NCLOC: 50   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 javax.servlet.ServletContext;
 21   
 22    import org.apache.hivemind.Resource;
 23    import org.apache.hivemind.util.AbstractResource;
 24    import org.apache.hivemind.util.LocalizedResource;
 25   
 26    /**
 27    * Implementation of {@link org.apache.hivemind.Resource}for resources found within a
 28    * {@link org.apache.tapestry.web.WebContext}.
 29    *
 30    * @author Howard Lewis Ship
 31    * @since 4.0
 32    */
 33   
 34    public class WebContextResource extends AbstractResource
 35    {
 36    private WebContext _context;
 37   
 38  1055 public WebContextResource(WebContext context, String path)
 39    {
 40  1055 this(context, path, null);
 41    }
 42   
 43  1058 public WebContextResource(WebContext context, String path, Locale locale)
 44    {
 45  1058 super(path, locale);
 46   
 47  1058 _context = context;
 48    }
 49   
 50    /**
 51    * Locates the resource using {@link LocalizedWebContextResourceFinder}and
 52    * {@link ServletContext#getResource(java.lang.String)}.
 53    */
 54   
 55  71 public Resource getLocalization(Locale locale)
 56    {
 57  71 LocalizedWebContextResourceFinder finder = new LocalizedWebContextResourceFinder(_context);
 58   
 59  71 String path = getPath();
 60  71 LocalizedResource localizedResource = finder.resolve(path, locale);
 61   
 62  71 if (localizedResource == null)
 63  1 return null;
 64   
 65  70 String localizedPath = localizedResource.getResourcePath();
 66  70 Locale pathLocale = localizedResource.getResourceLocale();
 67   
 68  70 if (localizedPath == null)
 69  0 return null;
 70   
 71  70 if (path.equals(localizedPath))
 72  68 return this;
 73   
 74  2 return new WebContextResource(_context, localizedPath, pathLocale);
 75    }
 76   
 77  591 public URL getResourceURL()
 78    {
 79  591 return _context.getResource(getPath());
 80    }
 81   
 82  30 public String toString()
 83    {
 84  30 return "context:" + getPath();
 85    }
 86   
 87  113 public int hashCode()
 88    {
 89  113 return 2387 & getPath().hashCode();
 90    }
 91   
 92  1005 protected Resource newResource(String path)
 93    {
 94  1005 return new WebContextResource(_context, path);
 95    }
 96   
 97    }