1 52 53 54 package freemarker.cache; 55 56 import java.io.IOException ; 57 import java.io.InputStreamReader ; 58 import java.io.Reader ; 59 import java.net.URL ; 60 61 69 public abstract class URLTemplateLoader implements TemplateLoader 70 { 71 public Object findTemplateSource(String name) 72 throws 73 IOException 74 { 75 URL url = getURL(name); 76 return url == null ? null : new URLTemplateSource(url); 77 } 78 79 87 protected abstract URL getURL(String name); 88 89 public long getLastModified(Object templateSource) 90 { 91 return ((URLTemplateSource) templateSource).lastModified(); 92 } 93 94 public Reader getReader(Object templateSource, String encoding) 95 throws 96 IOException 97 { 98 return new InputStreamReader ( 99 ((URLTemplateSource) templateSource).getInputStream(), 100 encoding); 101 } 102 103 public void closeTemplateSource(Object templateSource) 104 throws 105 IOException 106 { 107 ((URLTemplateSource) templateSource).close(); 108 } 109 110 117 protected static String canonicalizePrefix(String prefix) 118 { 119 prefix = prefix.replace('\\', '/'); 121 if (prefix.length() > 0 && !prefix.endsWith("/")) 123 { 124 prefix += "/"; 125 } 126 return prefix; 127 } 128 } 129 | Popular Tags |