1 48 49 package org.jpublish.view.freemarker; 50 51 import java.io.IOException ; 52 import java.io.Reader ; 53 54 import freemarker.cache.TemplateLoader; 55 import org.apache.commons.logging.Log; 56 import org.apache.commons.logging.LogFactory; 57 import org.jpublish.SiteContext; 58 import org.jpublish.view.ContentSource; 59 60 66 67 public class JPublishTemplateLoader implements TemplateLoader { 68 69 private Log log = LogFactory.getLog(JPublishTemplateLoader.class); 70 71 private SiteContext siteContext; 72 73 78 79 public void setSiteContext(SiteContext siteContext) { 80 this.siteContext = siteContext; 81 } 82 83 89 90 public Object findTemplateSource(String name) { 91 if (log.isDebugEnabled()) { 92 log.debug("findTemplateSource(" + name + ")"); 93 } 94 95 Object content = siteContext.getContentSource(name); 96 if (log.isDebugEnabled()) { 97 log.debug("findTemplateSource() content: " + content); 98 } 99 return content; 100 } 101 102 108 109 public long getLastModified(Object templateSource) { 110 try { 111 log.debug("getLastModified() invoked"); 112 long lastModified = 113 ((ContentSource) templateSource).getLastModified(); 114 if (log.isDebugEnabled()) { 115 log.debug("Last modified time: " + lastModified); 116 } 117 return lastModified; 118 } catch (IOException e) { 119 log.error("An IO exception occured while retrieving the last " + 120 "modified time"); 121 return -1; 122 } 123 } 124 125 133 134 public Reader getReader(Object templateSource, String encoding) 135 throws IOException { 136 log.debug("getReader() invoked"); 137 return ((ContentSource) templateSource).getReader(encoding); 138 } 139 140 145 146 public void closeTemplateSource(Object templateSource) { 147 } 149 150 } 151 | Popular Tags |