Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 102   Methods: 7
NCLOC: 54   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 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.commons.logging.Log;
 23    import org.apache.commons.logging.LogFactory;
 24    import org.apache.hivemind.Resource;
 25    import org.apache.hivemind.util.AbstractResource;
 26    import org.apache.hivemind.util.LocalizedResource;
 27   
 28    /**
 29    * Implementation of {@link org.apache.hivemind.Resource}for resources found within a
 30    * {@link org.apache.tapestry.web.WebContext}.
 31    *
 32    * @author Howard Lewis Ship
 33    * @since 4.0
 34    */
 35   
 36    public class WebContextResource extends AbstractResource
 37    {
 38    private static final Log LOG = LogFactory.getLog(WebContextResource.class);
 39   
 40    private WebContext _context;
 41   
 42  1040 public WebContextResource(WebContext context, String path)
 43    {
 44  1040 this(context, path, null);
 45    }
 46   
 47  1043 public WebContextResource(WebContext context, String path, Locale locale)
 48    {
 49  1043 super(path, locale);
 50   
 51  1043 _context = context;
 52    }
 53   
 54    /**
 55    * Locates the resource using {@link LocalizedWebContextResourceFinder}and
 56    * {@link ServletContext#getResource(java.lang.String)}.
 57    */
 58   
 59  71 public Resource getLocalization(Locale locale)
 60    {
 61  71 LocalizedWebContextResourceFinder finder = new LocalizedWebContextResourceFinder(
 62    _context);
 63   
 64  71 String path = getPath();
 65  71 LocalizedResource localizedResource = finder.resolve(path, locale);
 66   
 67  71 if (localizedResource == null)
 68  1 return null;
 69   
 70  70 String localizedPath = localizedResource.getResourcePath();
 71  70 Locale pathLocale = localizedResource.getResourceLocale();
 72   
 73  70 if (localizedPath == null)
 74  0 return null;
 75   
 76  70 if (path.equals(localizedPath))
 77  68 return this;
 78   
 79  2 return new WebContextResource(_context, localizedPath, pathLocale);
 80    }
 81   
 82  594 public URL getResourceURL()
 83    {
 84  594 return _context.getResource(getPath());
 85    }
 86   
 87  45 public String toString()
 88    {
 89  45 return "context:" + getPath();
 90    }
 91   
 92  246 public int hashCode()
 93    {
 94  246 return 2387 & getPath().hashCode();
 95    }
 96   
 97  990 protected Resource newResource(String path)
 98    {
 99  990 return new WebContextResource(_context, path);
 100    }
 101   
 102    }