I've attached some possible enhancements for the "view" piece of velocity-tools. It's mainly modified servlet and webapp loader classes. The modified servlet allows the webapp loader which is used to be configurable based on a servlet <init-param> in web.xml. The webapp loader looks for an <init-param> named "loader.page.prefix" to be used as a default root for velocity templates. I've attached a web.xml file which has those two parameters set.
To run the "simple" example: - drop the source files in the view/src/java/org/apache/velocity/tools/view/servlet directory - rebuild the velocity-tools-view .jar file - drop the web.xml in the view/examples/simple/WEB-INF directory (rename the existing one if desired) - move (or copy) view/examples/simple/index.vm to a new "pages" directory under WEB-INF (as specified in the <init-param> of the new web.xml file) - re-war the simple example and redeploy it (or redeploy it however you choose for your environment) That example failed for me when "index.vm" was in its original location (as expected) and succeeded when I moved it to the new "pages" directory. Issues: - The webapp loader is still not as decoupled from the servlet as I'd like. Geir - I think it would be a better approach if the servletConfig parameter could be passed to the webapp loader's init() method in the ExtendedProperties object that's passed to it rather than in an "application attribute"; maybe that's just me. In any case, the servlet and the loader need to agree on a property/attribute name for the servletConfig which isn't related to either the webapp loader's classname or the servlet's classname. Unfortunately, until the webapp loader gets that servletConfig object, it has no way to find out any other parameterable values. - The WebappLoaderAppContext interface isn't used in this implementation, as it exposes the ServletContext and it's really the ServletConfig that needs exposed. You can get from ServletConfig to ServletContext, but not vice versa; and you need ServletConfig to read <init-param>s for the servlet. Anyway, I didn't want to change that interface for this; but it's easy enough to do that if desired. - I took the opportunity to use "init()" in the servlet rather than "init(config)" just to make sure that things worked as expected given all the recent discussions about this issue on the user list. Let me know if there are any question. I hope the line terminators are right and that I followed the coding standards. ;) Donnie
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app> <!-- Define Velocity template rendererr --> <servlet> <servlet-name>velocity</servlet-name> <servlet-class>org.apache.velocity.tools.view.servlet.ConfigurableViewServlet</servlet-class> <init-param> <param-name>toolbox</param-name> <param-value>/WEB-INF/toolbox.xml</param-value> </init-param> <init-param> <param-name>loader.classname</param-name> <param-value>org.apache.velocity.tools.view.servlet.ConfigurableWebappLoader</param-value> </init-param> <init-param> <param-name>loader.page.prefix</param-name> <param-value>/WEB-INF/pages</param-value> </init-param> <load-on-startup>10</load-on-startup> </servlet> <!-- Map *.vm files to Velocity --> <servlet-mapping> <servlet-name>velocity</servlet-name> <url-pattern>*.vm</url-pattern> </servlet-mapping> </web-app>
ConfigurableViewServlet.java
Description: Binary data
ConfigurableWebappLoader.java
Description: Binary data
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
