You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by sm...@apache.org on 2006/12/01 11:05:19 UTC

svn commit: r481213 - /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedVelocityViewServlet.java

Author: smilek
Date: Fri Dec  1 02:05:17 2006
New Revision: 481213

URL: http://svn.apache.org/viewvc?view=rev&rev=481213
Log:
changed initVelocity overridden method to be conisistent with velocity-tools 1.2

Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedVelocityViewServlet.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedVelocityViewServlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedVelocityViewServlet.java?view=diff&rev=481213&r1=481212&r2=481213
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedVelocityViewServlet.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/JetspeedVelocityViewServlet.java Fri Dec  1 02:05:17 2006
@@ -54,7 +54,10 @@
 import org.apache.velocity.Template;
 import org.apache.velocity.app.Velocity;
 import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.context.Context;
+import org.apache.velocity.tools.generic.log.LogSystemCommonsLog;
+import org.apache.velocity.tools.view.servlet.WebappLoader;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
 
@@ -168,21 +171,46 @@
      */
     protected void initVelocity(ServletConfig config) throws ServletException
     {
+        VelocityEngine velocity = new VelocityEngine();
+        setVelocityEngine(velocity);
+
+        // register this engine to be the default handler of log messages
+        // if the user points commons-logging to the LogSystemCommonsLog
+        LogSystemCommonsLog.setVelocityEngine(velocity);
+
+        velocity.setApplicationAttribute(SERVLET_CONTEXT_KEY, getServletContext());
+
+        // default to servletlogger, which logs to the servlet engines log
+        velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.tools.view.servlet.ServletLogger");
+
+        // by default, load resources with webapp resource loader
+        velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
+        velocity.setProperty("webapp.resource.loader.class", 
+                             WebappLoader.class.getName());
+
+        // Try reading an overriding Velocity configuration
         try
         {
-            Velocity.setApplicationAttribute(SERVLET_CONTEXT_KEY, getServletContext());
-            Velocity.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.tools.view.servlet.ServletLogger");
-            ExtendedProperties configuration = loadConfiguration(getServletConfig());
-            configuration.addProperty("velocimacro.library", "/WEB-INF/jetspeed_macros.vm");
-            configuration.setProperty("file.resource.loader.path", getServletContext().getRealPath("/"));
-            Velocity.setExtendedProperties(configuration);
+            ExtendedProperties p = loadConfiguration(config);
+            p.addProperty("velocimacro.library", "/WEB-INF/jetspeed_macros.vm");
+            p.setProperty("file.resource.loader.path", getServletContext().getRealPath("/"));
+            velocity.setExtendedProperties(p);
+        }
+        catch(Exception e)
+        {
+            getServletContext().log("VelocityViewServlet: Unable to read Velocity configuration file: "+e);
+            getServletContext().log("VelocityViewServlet: Using default Velocity configuration.");
+        }   
 
-            // initialize and return velocity engine
-            Velocity.init();
+        // now all is ready - init Velocity
+        try
+        {
+            velocity.init();
         }
-        catch (Exception e)
+        catch(Exception e)
         {
-            log.error("initVelocity(): unable to initialize default Velocity engine", e);
+            getServletContext().log("VelocityViewServlet: PANIC! unable to init() - "+e);
+            throw new ServletException(e);
         }
     }
     



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org