1 18 19 package org.apache.roller.ui.rendering.velocity; 20 21 import java.io.InputStream ; 22 import javax.servlet.ServletContext ; 23 import org.apache.commons.collections.ExtendedProperties; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.roller.ui.core.RollerContext; 27 import org.apache.velocity.exception.ResourceNotFoundException; 28 import org.apache.velocity.runtime.resource.Resource; 29 import org.apache.velocity.runtime.resource.loader.ResourceLoader; 30 31 32 39 public class WebappResourceLoader extends ResourceLoader { 40 41 private static Log log = LogFactory.getLog(WebappResourceLoader.class); 42 43 private ServletContext mContext = null; 44 45 46 49 public void init(ExtendedProperties config) { 50 51 log.debug("WebappResourceLoader : initialization starting."); 52 53 if (mContext == null) { 54 mContext = RollerContext.getServletContext(); 55 log.debug("Servlet Context = "+mContext.getRealPath("/WEB-INF/velocity/")); 56 } 57 58 log.debug(config); 59 60 log.debug("WebappResourceLoader : initialization complete."); 61 } 62 63 64 67 public InputStream getResourceStream(String name) 68 throws ResourceNotFoundException { 69 70 log.debug("Looking up resource named ... "+name); 71 72 if (name == null || name.length() == 0) { 73 throw new ResourceNotFoundException("No template name provided"); 74 } 75 76 InputStream result = null; 77 78 try { 79 if(!name.startsWith("/")) 80 name = "/WEB-INF/velocity/" + name; 81 82 result = this.mContext.getResourceAsStream(name); 83 84 } catch(Exception e) { 85 throw new ResourceNotFoundException(e.getMessage()); 86 } 87 88 if(result == null) { 89 throw new ResourceNotFoundException("Couldn't find "+name); 90 } 91 92 return result; 93 } 94 95 96 102 public boolean isSourceModified(Resource arg0) { 103 return false; 104 } 105 106 107 112 public long getLastModified(Resource arg0) { 113 return 0; 114 } 115 116 } 117 | Popular Tags |