Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 102   Methods: 7
NCLOC: 54   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover 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  1148
     public WebContextResource(WebContext context, String path)
 43   
     {
 44  1148
         this(context, path, null);
 45   
     }
 46   
 
 47  1151
     public WebContextResource(WebContext context, String path, Locale locale)
 48   
     {
 49  1151
         super(path, locale);
 50   
 
 51  1151
         _context = context;
 52   
     }
 53   
 
 54   
     /**
 55   
      * Locates the resource using {@link LocalizedWebContextResourceFinder}and
 56   
      * {@link ServletContext#getResource(java.lang.String)}.
 57   
      */
 58   
 
 59  76
     public Resource getLocalization(Locale locale)
 60   
     {
 61  76
         LocalizedWebContextResourceFinder finder = new LocalizedWebContextResourceFinder(
 62   
                 _context);
 63   
 
 64  76
         String path = getPath();
 65  76
         LocalizedResource localizedResource = finder.resolve(path, locale);
 66   
 
 67  76
         if (localizedResource == null)
 68  1
             return null;
 69   
 
 70  75
         String localizedPath = localizedResource.getResourcePath();
 71  75
         Locale pathLocale = localizedResource.getResourceLocale();
 72   
 
 73  75
         if (localizedPath == null)
 74  0
             return null;
 75   
 
 76  75
         if (path.equals(localizedPath))
 77  73
             return this;
 78   
 
 79  2
         return new WebContextResource(_context, localizedPath, pathLocale);
 80   
     }
 81   
 
 82  666
     public URL getResourceURL()
 83   
     {
 84  666
         return _context.getResource(getPath());
 85   
     }
 86   
 
 87  43
     public String toString()
 88   
     {
 89  43
         return "context:" + getPath();
 90   
     }
 91   
 
 92  256
     public int hashCode()
 93   
     {
 94  256
         return 2387 & getPath().hashCode();
 95   
     }
 96   
 
 97  1094
     protected Resource newResource(String path)
 98   
     {
 99  1094
         return new WebContextResource(_context, path);
 100   
     }
 101   
 
 102   
 }