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