1 15 package org.apache.hivemind.util; 16 17 import java.util.Locale ; 18 19 import org.apache.hivemind.ClassResolver; 20 21 29 public class LocalizedResourceFinder 30 { 31 private ClassResolver _resolver; 32 33 public LocalizedResourceFinder(ClassResolver resolver) 34 { 35 _resolver = resolver; 36 } 37 38 48 49 public LocalizedResource resolve(String resourcePath, Locale locale) 50 { 51 int dotx = resourcePath.lastIndexOf('.'); 52 String basePath; 53 String suffix; 54 if (dotx >= 0) { 55 basePath = resourcePath.substring(0, dotx); 56 suffix = resourcePath.substring(dotx); 57 } 58 else 59 { 60 basePath = resourcePath; 62 suffix = ""; 63 } 64 65 LocalizedNameGenerator generator = new LocalizedNameGenerator(basePath, locale, suffix); 66 67 while (generator.more()) 68 { 69 String candidatePath = generator.next(); 70 71 if (_resolver.getResource(candidatePath) != null) 72 return new LocalizedResource(candidatePath, generator.getCurrentLocale()); 73 } 74 75 return null; 76 } 77 } 78 | Popular Tags |