1 17 18 package org.apache.geronimo.jmxdebug.web.velocity; 19 20 import org.apache.velocity.runtime.resource.loader.ResourceLoader; 21 import org.apache.velocity.runtime.resource.Resource; 22 import org.apache.velocity.exception.ResourceNotFoundException; 23 24 import javax.servlet.ServletContext ; 25 import java.io.InputStream ; 26 27 import org.apache.commons.collections.ExtendedProperties; 28 29 35 public class WebappLoader extends ResourceLoader { 36 37 public ServletContext servletContext = null; 38 39 public static String KEY = "org.apache.geronimo.console.web.velocity.WebappLoader"; 40 41 44 public void init(ExtendedProperties configuration) { 45 46 rsvc.info("WebappLoader : initialization starting."); 47 48 Object o = rsvc.getApplicationAttribute(KEY); 49 50 if (o instanceof WebappLoaderAppContext) { 51 servletContext = ((WebappLoaderAppContext) o).getServletContext(); 52 } 53 else 54 rsvc.error("WebappLoader : unable to retrieve ServletContext"); 55 56 rsvc.info("WebappLoader : initialization complete."); 57 } 58 59 69 public synchronized InputStream getResourceStream(String name) 70 throws ResourceNotFoundException { 71 72 if (name == null || name.length() == 0) { 73 throw new ResourceNotFoundException("No template name provided"); 74 } 75 76 try { 77 if (!name.startsWith("/")) 78 name = "/" + name; 79 80 return servletContext.getResourceAsStream(name); 81 } 82 catch (Exception fnfe) { 83 86 87 throw new ResourceNotFoundException(fnfe.getMessage()); 88 } 89 } 90 91 94 public boolean isSourceModified(Resource resource) { 95 return false; 96 } 97 98 101 public long getLastModified(Resource resource) { 102 return 0; 103 } 104 105 public interface WebappLoaderAppContext { 106 107 public ServletContext getServletContext(); 108 109 } 110 } 111 112 | Popular Tags |