1 15 package org.apache.hivemind.util; 16 17 import java.io.File ; 18 import java.net.MalformedURLException ; 19 import java.net.URL ; 20 import java.util.Locale ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.hivemind.Resource; 25 26 32 public class FileResource extends AbstractResource 33 { 34 private static final Log LOG = LogFactory.getLog(FileResource.class); 35 36 public FileResource(String path) 37 { 38 super(path); 39 } 40 41 public FileResource(String path, Locale locale) 42 { 43 super(path, locale); 44 } 45 46 protected Resource newResource(String path) 47 { 48 return new FileResource(path); 49 } 50 51 private File getFile() 52 { 53 return new File (getPath()); 54 } 55 56 public URL getResourceURL() 57 { 58 File file = getFile(); 59 60 try 61 { 62 if (file == null || !file.exists()) 63 return null; 64 65 return file.toURL(); 66 } 67 catch (MalformedURLException ex) 68 { 69 LOG.error(UtilMessages.badFileURL(getPath(), ex), ex); 70 return null; 71 } 72 } 73 74 public Resource getLocalization(Locale locale) 75 { 76 LocalizedFileResourceFinder f = new LocalizedFileResourceFinder(); 77 78 String path = getPath(); 79 80 String finalPath = f.findLocalizedPath(path, locale); 81 82 if (finalPath.equals(path)) 83 return this; 84 85 return newResource(finalPath); 86 } 87 88 public String toString() 89 { 90 return getPath(); 91 } 92 93 } 94 | Popular Tags |