Commits

Anonymous committed 45134af

resolves WW-259 and also fixes up unit test (for reals this time) to run in a single suite

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@47573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (2)

src/java/com/opensymphony/webwork/views/velocity/VelocityManager.java

 import com.opensymphony.webwork.config.Configuration;
 import com.opensymphony.webwork.views.jsp.ui.OgnlTool;
 import com.opensymphony.webwork.views.velocity.ui.JSPTagAdapterFactory;
-
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.util.OgnlValueStack;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.velocity.app.Velocity;
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.context.Context;
 
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-
 import java.util.Iterator;
 import java.util.Properties;
 
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
 
 /**
  * @author Matt Ho <matt@indigoegg.com>
     //~ Methods ////////////////////////////////////////////////////////////////
 
     /**
-    * return  a reference to the VelocityEngine used by <b>all</b> webwork velocity thingies with the exception of
-    * directly accessed *.vm pages
-    * @return
-    */
+     * return  a reference to the VelocityEngine used by <b>all</b> webwork velocity thingies with the exception of
+     * directly accessed *.vm pages
+     * @return
+     */
     public static VelocityEngine getVelocityEngine() {
         return velocityEngine;
     }
 
     /**
-    * This method is responsible for creating the standard VelocityContext used by all WW2 velocity views.  The
-    * following context parameters are defined:
-    *
-    * <ul>
-    *   <li><strong>req</strong> - the current HttpServletRequest</li>
-    *   <li><strong>res</strong> - the current HttpServletResponse</li>
-    *   <li><strong>stack</strong> - the current OgnlValueStack</li>
-    *   <li><strong>ui</strong> - a singleton JSPTagAdapter that provides access to the WW2 UI Tags</li>
-    * </ul>
-    *
-    * @return a new WebWorkVelocityContext
-    */
+     * This method is responsible for creating the standard VelocityContext used by all WW2 velocity views.  The
+     * following context parameters are defined:
+     *
+     * <ul>
+     *   <li><strong>req</strong> - the current HttpServletRequest</li>
+     *   <li><strong>res</strong> - the current HttpServletResponse</li>
+     *   <li><strong>stack</strong> - the current OgnlValueStack</li>
+     *   <li><strong>ui</strong> - a singleton JSPTagAdapter that provides access to the WW2 UI Tags</li>
+     * </ul>
+     *
+     * @return a new WebWorkVelocityContext
+     */
     public static Context createContext(ServletConfig config, ServletRequest servletRequest, ServletResponse servletResponse) {
         OgnlValueStack stack = ActionContext.getContext().getValueStack();
 
     }
 
     /**
-    * initializes the VelocityManager.  this should be called during the initialization process, say by
-    * ServletDispatcher.  this may be called multiple times safely although calls beyond the first won't do anything
-    * @param context the current servlet context
-    */
+     * initializes the VelocityManager.  this should be called during the initialization process, say by
+     * ServletDispatcher.  this may be called multiple times safely although calls beyond the first won't do anything
+     * @param context the current servlet context
+     */
     public synchronized static void init(ServletContext context) {
         if (velocityEngine == null) {
             velocityEngine = newVelocityEngine(context);
     }
 
     /**
-    * load optional velocity properties using the following loading strategy
-    * <ul>
-    *  <li>relative to the servlet context path</li>
-    *  <li>relative to the WEB-INF directory</li>
-    *  <li>on the classpath</li>
-    * </ul>
-    * @param context the current ServletContext.  may <b>not</b> be null
-    * @return the optional properties if webwork.velocity.configfile was specified, an empty Properties file otherwise
-    */
+     * load optional velocity properties using the following loading strategy
+     * <ul>
+     *  <li>relative to the servlet context path</li>
+     *  <li>relative to the WEB-INF directory</li>
+     *  <li>on the classpath</li>
+     * </ul>
+     * @param context the current ServletContext.  may <b>not</b> be null
+     * @return the optional properties if webwork.velocity.configfile was specified, an empty Properties file otherwise
+     */
     public static Properties loadConfiguration(ServletContext context) {
         if (context == null) {
             String gripe = "Error attempting to create a loadConfiguration from a null ServletContext!";
         Properties properties = new Properties();
 
         /**
-        * if the user has specified an external velocity configuration file, we'll want to search for it in the
-        * following order
-        *
-        * 1. relative to the context path
-        * 2. relative to /WEB-INF
-        * 3. in the class path
-        */
+         * if the user has specified an external velocity configuration file, we'll want to search for it in the
+         * following order
+         *
+         * 1. relative to the context path
+         * 2. relative to /WEB-INF
+         * 3. in the class path
+         */
         String configfile;
 
         if (Configuration.isSet("webwork.velocity.configfile")) {
             log.debug("Initializing Velocity with the following properties ...");
 
             for (Iterator iter = properties.keySet().iterator();
-                    iter.hasNext();) {
+                 iter.hasNext();) {
                 String key = (String) iter.next();
                 String value = properties.getProperty(key);
 
     }
 
     /**
-    * <p>
-    * instantiate a new VelocityEngine
-    * </p>
-    * <p>
-    * the following is the default Velocity configuration
-    * </p>
-    * <pre>
-    *  resource.loader = file, class
-    *  file.resource.loader.path = real path of webapp
-    *  class.resource.loader.description = Velocity Classpath Resource Loader
-    *  class.resource.loader.class = com.opensymphony.webwork.views.velocity.WebWorkResourceLoader
-    * </pre>
-    * <p>
-    * this default configuration can be overridden by specifying a webwork.velocity.configfile property in the
-    * webwork.properties file.  the specified config file will be searched for in the following order:
-    * </p>
-    * <ul>
-    *  <li>relative to the servlet context path</li>
-    *  <li>relative to the WEB-INF directory</li>
-    *  <li>on the classpath</li>
-    * </ul>
-    * @param context the current ServletContext.  may <b>not</b> be null
-    */
+     * <p>
+     * instantiate a new VelocityEngine
+     * </p>
+     * <p>
+     * the following is the default Velocity configuration
+     * </p>
+     * <pre>
+     *  resource.loader = file, class
+     *  file.resource.loader.path = real path of webapp
+     *  class.resource.loader.description = Velocity Classpath Resource Loader
+     *  class.resource.loader.class = com.opensymphony.webwork.views.velocity.WebWorkResourceLoader
+     * </pre>
+     * <p>
+     * this default configuration can be overridden by specifying a webwork.velocity.configfile property in the
+     * webwork.properties file.  the specified config file will be searched for in the following order:
+     * </p>
+     * <ul>
+     *  <li>relative to the servlet context path</li>
+     *  <li>relative to the WEB-INF directory</li>
+     *  <li>on the classpath</li>
+     * </ul>
+     * @param context the current ServletContext.  may <b>not</b> be null
+     */
     protected static VelocityEngine newVelocityEngine(ServletContext context) {
         if (context == null) {
             String gripe = "Error attempting to create a new VelocityEngine from a null ServletContext!";
      */
     private static void applyDefaultConfiguration(ServletContext context, Properties p) {
         /**
-        * now let's load up the basic properties we really want the VelocityEngine to have
-        * @todo does it make sense to allow the user to override these features?
-        */
+         * Load a default resource loader definition if there isn't one present.
+         * Ben Hall (22/08/2003)
+         */
         if (p.getProperty(Velocity.RESOURCE_LOADER) == null) {
-            if (context.getRealPath("") != null) {
-                p.setProperty(Velocity.RESOURCE_LOADER, "file, class");
-                p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, context.getRealPath(""));
-            } else {
-                p.setProperty(Velocity.RESOURCE_LOADER, "class");
-            }
+            p.setProperty(Velocity.RESOURCE_LOADER, "wwfile, wwclass");
+        }
 
-            /**
-            * Refactored the Velocity templates for the WebWork taglib into the classpath from the web path.  This will
-            * enable WebWork projects to have access to the templates by simply including the WebWork jar file.
-            * Unfortunately, there does not appear to be a macro for the class loader keywords
-            * Matt Ho - Mon Mar 17 00:21:46 PST 2003
-            */
-            p.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
-            p.setProperty("class.resource.loader.class", "com.opensymphony.webwork.views.velocity.WebWorkResourceLoader");
+        /**
+         * If there's a "real" path add it for the wwfile resource loader.
+         * If there's no real path and they haven't configured a loader then we change
+         * resource loader property to just use the wwclass loader
+         * Ben Hall (22/08/2003)
+         */
+        if (context.getRealPath("") != null) {
+            p.setProperty("wwfile.resource.loader.description", "Velocity File Resource Loader");
+            p.setProperty("wwfile.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
+            p.setProperty("wwfile.resource.loader.path", context.getRealPath(""));
+        } else if (p.getProperty(Velocity.RESOURCE_LOADER) == null) {
+            p.setProperty(Velocity.RESOURCE_LOADER, "wwclass");
         }
 
         /**
-        * the TagDirective and BodyTagDirective must be added to the userdirective
-        * @todo there must be a better place for this
-        */
+         * Refactored the Velocity templates for the WebWork taglib into the classpath from the web path.  This will
+         * enable WebWork projects to have access to the templates by simply including the WebWork jar file.
+         * Unfortunately, there does not appear to be a macro for the class loader keywords
+         * Matt Ho - Mon Mar 17 00:21:46 PST 2003
+         */
+        p.setProperty("wwclass.resource.loader.description", "Velocity Classpath Resource Loader");
+        p.setProperty("wwclass.resource.loader.class", "com.opensymphony.webwork.views.velocity.WebWorkResourceLoader");
+
+        /**
+         * the TagDirective and BodyTagDirective must be added to the userdirective
+         * TODO: there must be a better place for this
+         */
         String userdirective = p.getProperty("userdirective");
         String directives = "com.opensymphony.webwork.views.velocity.ParamDirective" + "," + "com.opensymphony.webwork.views.velocity.TagDirective" + "," + "com.opensymphony.webwork.views.velocity.BodyTagDirective";
 
 
         p.setProperty("userdirective", userdirective);
     }
+
 }

src/test/com/opensymphony/webwork/views/velocity/TagDirectiveTest.java

 import com.mockobjects.dynamic.Mock;
 import com.opensymphony.webwork.views.jsp.WebWorkMockServletContext;
 import com.opensymphony.webwork.views.velocity.ui.MockTag;
+import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.config.ConfigurationManager;
+import com.opensymphony.xwork.util.OgnlValueStack;
 import junit.framework.Assert;
 import junit.framework.TestCase;
 import org.apache.velocity.Template;
     protected void setUp() throws Exception {
         super.setUp();
 
+        ConfigurationManager.destroyConfiguration();
+        OgnlValueStack stack = new OgnlValueStack();
+        ActionContext.setContext(new ActionContext(stack.getContext()));
+
         /**
          * construct our sandbox VelocityEngine
          */