1 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 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 public WebContextResource(WebContext context, String path) 43 { 44 this(context, path, null); 45 } 46 47 public WebContextResource(WebContext context, String path, Locale locale) 48 { 49 super(path, locale); 50 51 _context = context; 52 } 53 54 58 59 public Resource getLocalization(Locale locale) 60 { 61 LocalizedWebContextResourceFinder finder = new LocalizedWebContextResourceFinder( 62 _context); 63 64 String path = getPath(); 65 LocalizedResource localizedResource = finder.resolve(path, locale); 66 67 if (localizedResource == null) 68 return null; 69 70 String localizedPath = localizedResource.getResourcePath(); 71 Locale pathLocale = localizedResource.getResourceLocale(); 72 73 if (localizedPath == null) 74 return null; 75 76 if (path.equals(localizedPath)) 77 return this; 78 79 return new WebContextResource(_context, localizedPath, pathLocale); 80 } 81 82 public URL getResourceURL() 83 { 84 return _context.getResource(getPath()); 85 } 86 87 public String toString() 88 { 89 return "context:" + getPath(); 90 } 91 92 public int hashCode() 93 { 94 return 2387 & getPath().hashCode(); 95 } 96 97 protected Resource newResource(String path) 98 { 99 return new WebContextResource(_context, path); 100 } 101 102 } | Popular Tags |