1 15 package org.apache.tapestry.web; 16 17 import java.util.Locale ; 18 19 import org.apache.hivemind.util.LocalizedNameGenerator; 20 import org.apache.hivemind.util.LocalizedResource; 21 22 28 29 public class LocalizedWebContextResourceFinder 30 { 31 private WebContext _context; 32 33 public LocalizedWebContextResourceFinder(WebContext context) 34 { 35 _context = context; 36 } 37 38 45 46 public LocalizedResource resolve(String contextPath, Locale locale) 47 { 48 int dotx = contextPath.lastIndexOf('.'); 49 String basePath = contextPath.substring(0, dotx); 50 String suffix = contextPath.substring(dotx); 51 52 LocalizedNameGenerator generator = new LocalizedNameGenerator(basePath, locale, suffix); 53 54 while (generator.more()) 55 { 56 String candidatePath = generator.next(); 57 58 if (isExistingResource(candidatePath)) 59 return new LocalizedResource(candidatePath, generator.getCurrentLocale()); 60 } 61 62 return null; 63 } 64 65 private boolean isExistingResource(String path) 66 { 67 return _context.getResource(path) != null; 68 } 69 } | Popular Tags |