velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r534266 - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools: struts/ view/ view/tools/
Date Tue, 01 May 2007 22:40:24 GMT
Author: nbubna
Date: Tue May  1 15:40:23 2007
New Revision: 534266

URL: http://svn.apache.org/viewvc?view=rev&rev=534266
Log:
use injected Velocity Log instead of static commons-logging

Modified:
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ActionMessagesTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageResourcesTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/TilesTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportSupport.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ActionMessagesTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ActionMessagesTool.java?view=diff&rev=534266&r1=534265&r2=534266
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ActionMessagesTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ActionMessagesTool.java
Tue May  1 15:40:23 2007
@@ -23,13 +23,12 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.struts.action.ActionMessage;
 import org.apache.struts.action.ActionMessages;
 import org.apache.struts.util.MessageResources;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
+import org.apache.velocity.runtime.log.Log;
 
 /**
  * <p>View tool to work with the Struts action messages.</p>
@@ -61,8 +60,7 @@
 @ValidScope("request")
 public class ActionMessagesTool extends MessageResourcesTool
 {
-
-    protected static final Log LOG = LogFactory.getLog(ActionMessagesTool.class);
+    protected Log LOG;
 
     /** A reference to the queued action messages. */
     protected ActionMessages actionMsgs;
@@ -86,6 +84,7 @@
         //setup superclass instance members
         super.setup(params);
 
+        this.LOG = (Log)params.get("log");
         this.actionMsgs = StrutsUtils.getMessages(this.request);
     }
 
@@ -262,7 +261,7 @@
 
                 if (message == null)
                 {
-                    LOG.warn("Message for key " + msg.getKey() +
+                    LOG.warn("ActionMessagesTool : Message for key " + msg.getKey() +
                              " could not be found in message resources.");
                 }
             }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageResourcesTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageResourcesTool.java?view=diff&rev=534266&r1=534265&r2=534266
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageResourcesTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageResourcesTool.java
Tue May  1 15:40:23 2007
@@ -23,9 +23,8 @@
 import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.ServletContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.struts.util.MessageResources;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.tools.view.ViewContext;
 
 /**
@@ -37,9 +36,7 @@
  */
 public abstract class MessageResourcesTool
 {
-
-    protected static final Log LOG = LogFactory.getLog(MessageResourcesTool.class);
-
+    protected Log LOG;
     protected ServletContext application;
     protected HttpServletRequest request;
     protected Locale locale;
@@ -56,6 +53,7 @@
     {
         this.request = (HttpServletRequest)params.get(ViewContext.REQUEST);
         this.application = (ServletContext)params.get(ViewContext.SERVLET_CONTEXT_KEY);
+        this.LOG = (Log)params.get("log");
 
         this.resources =
             StrutsUtils.getMessageResources(request, application);
@@ -75,7 +73,7 @@
         {
             if (resources == null)
             {
-                LOG.error("Message resources are not available.");
+                LOG.error("MessageResourcesTool : Message resources are not available.");
             }
             return resources;
         }
@@ -84,7 +82,7 @@
             StrutsUtils.getMessageResources(request, application, bundle);
         if (res == null)
         {
-            LOG.error("MessageResources bundle '" + bundle + "' is not available.");
+            LOG.error("MessageResourcesTool : MessageResources bundle '" + bundle + "' is
not available.");
         }
         return res;
     }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java?view=diff&rev=534266&r1=534265&r2=534266
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsLinkTool.java
Tue May  1 15:40:23 2007
@@ -19,9 +19,8 @@
  * under the License.
  */
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.velocity.tools.view.tools.LinkTool;
+import org.apache.velocity.runtime.log.Log;
 
 /**
  * <p>View tool to work with URI links in Struts.</p>
@@ -49,8 +48,6 @@
  */
 public class StrutsLinkTool extends LinkTool
 {
-    protected static final Log LOG = LogFactory.getLog(StrutsLinkTool.class);
-
     private String get;
 
     /**
@@ -102,7 +99,7 @@
             StrutsUtils.getActionMappingURL(application, request, action);
         if (url == null)
         {
-            LOG.warn("In method setAction("+action+
+            LOG.warn("StrutsLinkTool : In method setAction("+action+
                      "): Parameter does not map to a valid action.");
             return null;
         }
@@ -126,7 +123,7 @@
         String url = StrutsUtils.getForwardURL(request, application, forward);
         if (url == null)
         {
-            LOG.warn("In method setForward(" + forward +
+            LOG.warn("StrutsLinkTool : In method setForward(" + forward +
                      "): Parameter does not map to a valid forward.");
             return null;
         }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/TilesTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/TilesTool.java?view=diff&rev=534266&r1=534265&r2=534266
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/TilesTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/TilesTool.java
Tue May  1 15:40:23 2007
@@ -23,8 +23,6 @@
 import java.util.Map;
 import java.util.Stack;
 import javax.servlet.http.HttpSession;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.struts.tiles.AttributeDefinition;
 import org.apache.struts.tiles.ComponentContext;
 import org.apache.struts.tiles.ComponentDefinition;
@@ -71,8 +69,6 @@
 @ValidScope("request")
 public class TilesTool extends ImportSupport
 {
-    protected static final Log LOG = LogFactory.getLog(TilesTool.class);
-
     static final String PAGE_SCOPE = "page";
     static final String REQUEST_SCOPE = "request";
     static final String SESSION_SCOPE = "session";
@@ -138,7 +134,7 @@
         }
         catch (Exception e)
         {
-            LOG.error("Exeption while rendering Tile " + obj + ": ", e);
+            LOG.error("TilesTool : Exeption while rendering Tile " + obj, e);
             return null;
         }
     }
@@ -157,7 +153,7 @@
         Object value = getCurrentContext().getAttribute(name);
         if (value == null)
         {
-            LOG.warn("Tile attribute '" + name + "' wasn't found in context.");
+            LOG.warn("TilesTool : Tile attribute '" + name + "' wasn't found in context.");
         }
         return value;
     }
@@ -191,7 +187,7 @@
         Object value = getCurrentContext().getAttribute(name);
         if (value == null)
         {
-            LOG.warn("Tile attribute '" + name + "' wasn't found in context.");
+            LOG.warn("TilesTool : Tile attribute '" + name + "' wasn't found in context.");
         }
 
         if (scope.equals(PAGE_SCOPE))

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportSupport.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportSupport.java?view=diff&rev=534266&r1=534265&r2=534266
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportSupport.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ImportSupport.java
Tue May  1 15:40:23 2007
@@ -33,16 +33,13 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Locale;
-
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponseWrapper;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.runtime.log.Log;
 
 /**
  * <p>Provides methods to import arbitrary local or remote resources as strings.</p>
@@ -52,16 +49,15 @@
  * @since VelocityTools 1.1
  * @version $Revision$ $Date$
  */
-public abstract class ImportSupport {
-
-    protected static final Log LOG = LogFactory.getLog(ImportSupport.class);
-
+public abstract class ImportSupport
+{
     protected static final String VALID_SCHEME_CHARS =
         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-";
 
     /** Default character encoding for response. */
     protected static final String DEFAULT_ENCODING = "ISO-8859-1";
 
+    protected Log LOG;
     protected ServletContext application;
     protected HttpServletRequest request;
     protected HttpServletResponse response;
@@ -69,6 +65,15 @@
 
     // --------------------------------------- Setup Methods -------------
 
+    public void setLog(Log log)
+    {
+        if (log == null)
+        {
+            throw new NullPointerException("log should not be set to null");
+        }
+        this.LOG = log;
+    }
+
     /**
      * Sets the current {@link HttpServletRequest}. This is required
      * for this tool to operate and will throw a NullPointerException
@@ -166,7 +171,7 @@
                     }
                     catch (IOException ioe)
                     {
-                        LOG.error("Could not close reader.", ioe);
+                        LOG.error("ImportSupport : Could not close reader.", ioe);
                     }
                 }
 	        }
@@ -317,7 +322,7 @@
                     }
                     catch (IOException ioe)
                     {
-                        LOG.error("Could not close InputStream", ioe);
+                        LOG.error("ImportSupport : Could not close InputStream", ioe);
                     }
                 }
 
@@ -338,7 +343,7 @@
                     }
                     catch (IOException ioe)
                     {
-                        LOG.error("Could not close InputStream", ioe);
+                        LOG.error("ImportSupport : Could not close InputStream", ioe);
                     }
                 }
 

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java?view=diff&rev=534266&r1=534265&r2=534266
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/ImportTool.java
Tue May  1 15:40:23 2007
@@ -19,8 +19,6 @@
  * under the License.
  */
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
 import org.apache.velocity.tools.view.ImportSupport;
@@ -49,9 +47,6 @@
 @ValidScope("request")
 public class ImportTool extends ImportSupport
 {
-
-    protected static final Log LOG = LogFactory.getLog(ImportTool.class);
-
     /**
      * Default constructor. Tool must be initialized before use.
      */
@@ -67,14 +62,14 @@
         try {
             // check the URL
             if (url == null || url.equals("")) {
-                LOG.warn("Import URL is null or empty");
+                LOG.warn("ImportTool : Import URL is null or empty");
                 return null;
             }
 
             return acquireString(url);
         }
         catch (Exception ex) {
-            LOG.error("Exception while importing URL: " + ex.getMessage());
+            LOG.error("ImportTool : Exception while importing URL", ex);
             return null;
         }
     }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java?view=diff&rev=534266&r1=534265&r2=534266
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/tools/LinkTool.java
Tue May  1 15:40:23 2007
@@ -29,8 +29,7 @@
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
 import org.apache.velocity.tools.generic.ValueParser;
@@ -64,8 +63,6 @@
 @ValidScope("request")
 public class LinkTool implements Cloneable
 {
-    protected static final Log LOG = LogFactory.getLog(LinkTool.class);
-
     /**
      * Parameter key for configuring {@link #setSelfAbsolute} state
      * @since VelocityTools 1.3
@@ -94,6 +91,9 @@
     /** A reference to the HttpServletResponse. */
     protected HttpServletResponse response;
 
+    /** A reference to the Velocity runtime's {@link Log}. */
+    protected Log LOG;
+
 
     /** The URI reference set for this link. */
     private String uri;
@@ -129,7 +129,8 @@
         }
         catch (NoSuchMethodException e)
         {
-            LOG.debug("Can't find JDK 1.4 encode method. Using JDK 1.3 version.");
+            //TODO: drop JDK 1.3 support in separate commit
+            //LOG.debug("LinkTool : Can't find JDK 1.4 encode method. Using JDK 1.3 version.");
         }
     }
 
@@ -187,6 +188,15 @@
         this.application = application;
     }
 
+    public void setLog(Log log)
+    {
+        if (log == null)
+        {
+            throw new NullPointerException("log should not be null");
+        }
+        this.LOG = log;
+    }
+
     @Deprecated
     public void setXhtml(boolean useXhtml)
     {
@@ -341,7 +351,7 @@
         }
         catch (CloneNotSupportedException e)
         {
-            LOG.warn("Could not properly clone " + getClass() + " - " + e);
+            LOG.warn("LinkTool : Could not properly clone " + getClass(), e);
 
             // "clone" manually
             LinkTool copy;
@@ -825,13 +835,13 @@
                 // don't keep trying if we get one of these
                 encode = null;
 
-                LOG.debug("Can't access JDK 1.4 encode method ("
-                          + e + "). Using deprecated version from now on.");
+                LOG.debug("LinkTool : Can't access JDK 1.4 encode method."
+                          + " Using deprecated version from now on.", e);
             }
             catch (InvocationTargetException e)
             {
-                LOG.debug("Error using JDK 1.4 encode method ("
-                          + e + "). Using deprecated version.");
+                LOG.debug("LinkTool : Error using JDK 1.4 encode method."
+                          + " Using deprecated version.", e);
             }
         }
         return URLEncoder.encode(url);



Mime
View raw message