velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1769774 - /velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/
Date Tue, 15 Nov 2016 10:52:36 GMT
Author: cbrisson
Date: Tue Nov 15 10:52:36 2016
New Revision: 1769774

URL: http://svn.apache.org/viewvc?rev=1769774&view=rev
Log:
[tools] same treatment for view tools (which should all inherit from SafeConfig)


Modified:
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/CookieTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportSupport.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/IncludeTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/PagerTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UiDependencyTool.java

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java?rev=1769774&r1=1769773&r2=1769774&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/AbstractSearchTool.java
Tue Nov 15 10:52:36 2016
@@ -132,8 +132,6 @@ public abstract class AbstractSearchTool
     protected static final String STORED_RESULTS_KEY =
         StoredResults.class.getName();
 
-    protected static Logger LOG = LoggerFactory.getLogger(AbstractSearchTool.class);
-
     private String criteriaKey = DEFAULT_CRITERIA_KEY;
     private Object criteria;
 
@@ -232,7 +230,7 @@ public abstract class AbstractSearchTool
             }
             catch (Throwable t)
             {
-                LOG.error("executeQuery({}) failed", findMe, t);
+                getLog().error("executeQuery({}) failed", findMe, t);
             }
 
             /* because we can't trust executeQuery() not to return null

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java?rev=1769774&r1=1769773&r2=1769774&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
Tue Nov 15 10:52:36 2016
@@ -26,9 +26,6 @@ import java.util.*;
 import org.apache.velocity.tools.ConversionUtils;
 import static org.apache.velocity.tools.view.UAParser.*;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.InvalidScope;
@@ -572,7 +569,7 @@ public class BrowserTool extends Browser
                     }
                     else
                     {
-                        log.error("BrowserTool: could not parse language quality value: {}",
language);
+                        getLog().error("BrowserTool: could not parse language quality value:
{}", language);
                     }
                 }
             }

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/CookieTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/CookieTool.java?rev=1769774&r1=1769773&r2=1769774&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/CookieTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/CookieTool.java
Tue Nov 15 10:52:36 2016
@@ -25,6 +25,7 @@ import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.velocity.tools.generic.SafeConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,7 +58,7 @@ import org.apache.velocity.tools.Scope;
  */
 @DefaultKey("cookies")
 @ValidScope(Scope.REQUEST)
-public class CookieTool
+public class CookieTool extends SafeConfig
 {
     protected static Logger log = LoggerFactory.getLogger(CookieTool.class);
 
@@ -212,7 +213,7 @@ public class CookieTool
         }
         catch (IllegalArgumentException iae)
         {
-            log.error("Could not create cookie with name \"{}\"", name, iae);
+            getLog().error("Could not create cookie with name \"{}\"", name, iae);
             return null;
         }
     }

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportSupport.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportSupport.java?rev=1769774&r1=1769773&r2=1769774&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportSupport.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportSupport.java
Tue Nov 15 10:52:36 2016
@@ -40,6 +40,7 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponseWrapper;
 
+import org.apache.velocity.tools.generic.SafeConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,7 +52,7 @@ import org.slf4j.LoggerFactory;
  * @since VelocityTools 2.0
  * @version $Revision$ $Date$
  */
-public abstract class ImportSupport
+public abstract class ImportSupport extends SafeConfig
 {
     protected static final String VALID_SCHEME_CHARS =
         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-";
@@ -59,8 +60,6 @@ public abstract class ImportSupport
     /** Default character encoding for response. */
     protected static final String DEFAULT_ENCODING = "UTF-8";
 
-    protected static Logger LOG = LoggerFactory.getLogger(ImportSupport.class);
-    
     protected ServletContext application;
     protected HttpServletRequest request;
     protected HttpServletResponse response;
@@ -165,7 +164,7 @@ public abstract class ImportSupport
                     }
                     catch (IOException ioe)
                     {
-                        LOG.error("Could not close reader.", ioe);
+                        getLog().error("Could not close reader.", ioe);
                     }
                 }
 	        }
@@ -316,7 +315,7 @@ public abstract class ImportSupport
                     }
                     catch (IOException ioe)
                     {
-                        LOG.error("Could not close InputStream", ioe);
+                        getLog().error("Could not close InputStream", ioe);
                     }
                 }
 
@@ -337,7 +336,7 @@ public abstract class ImportSupport
                     }
                     catch (IOException ioe)
                     {
-                        LOG.error("Could not close InputStream", ioe);
+                        getLog().error("Could not close InputStream", ioe);
                     }
                 }
 

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java?rev=1769774&r1=1769773&r2=1769774&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ImportTool.java
Tue Nov 15 10:52:36 2016
@@ -57,13 +57,13 @@ public class ImportTool extends ImportSu
     public String read(Object obj) {
         if (obj == null)
         {
-            LOG.warn("ImportTool.read(): url is null!");
+            getLog().warn("ImportTool.read(): url is null!");
             return null;
         }
         String url = String.valueOf(obj).trim();
         if (url.length() == 0)
         {
-            LOG.warn("ImportTool.read(): url is empty string!");
+            getLog().warn("ImportTool.read(): url is empty string!");
             return null;
         }
         try
@@ -72,7 +72,7 @@ public class ImportTool extends ImportSu
         }
         catch (Exception ex)
         {
-            LOG.error("ImportTool.read(): Exception while aquiring '{}'", url, ex);
+            getLog().error("ImportTool.read(): Exception while aquiring '{}'", url, ex);
             return null;
         }
     }

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/IncludeTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/IncludeTool.java?rev=1769774&r1=1769773&r2=1769774&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/IncludeTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/IncludeTool.java
Tue Nov 15 10:52:36 2016
@@ -28,7 +28,7 @@ import org.apache.velocity.exception.Res
 import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.InvalidScope;
-import org.apache.velocity.tools.view.ViewToolContext;
+import org.apache.velocity.tools.generic.SafeConfig;
 
 /**
  * Allows for transparent content negotiation in a manner mimicking
@@ -52,7 +52,7 @@ import org.apache.velocity.tools.view.Vi
 
 @DefaultKey("include")
 @InvalidScope(Scope.APPLICATION)
-public class IncludeTool implements Serializable
+public class IncludeTool extends SafeConfig implements Serializable
 {
     /**
      * The key used to search initialization, context, and JVM

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/PagerTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/PagerTool.java?rev=1769774&r1=1769773&r2=1769774&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/PagerTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/PagerTool.java
Tue Nov 15 10:52:36 2016
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpSession;
 import org.apache.velocity.tools.Scope;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.InvalidScope;
+import org.apache.velocity.tools.generic.SafeConfig;
 
 /**
  * <p>View tool for doing request-based pagination of
@@ -100,7 +101,7 @@ import org.apache.velocity.tools.config.
  */
 @DefaultKey("pager")
 @InvalidScope({Scope.APPLICATION,Scope.SESSION})
-public class PagerTool
+public class PagerTool extends SafeConfig
 {
     public static final String DEFAULT_NEW_ITEMS_KEY = "new.items";
     public static final String DEFAULT_INDEX_KEY = "index";

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UiDependencyTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UiDependencyTool.java?rev=1769774&r1=1769773&r2=1769774&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UiDependencyTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UiDependencyTool.java
Tue Nov 15 10:52:36 2016
@@ -19,7 +19,6 @@ package org.apache.velocity.tools.view;
  * under the License.    
  */
 
-import java.io.InputStream;
 import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -30,6 +29,7 @@ import java.util.Map;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.velocity.tools.generic.SafeConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,9 +39,7 @@ import org.xml.sax.SAXException;
 import org.apache.commons.digester3.Digester;
 import org.apache.commons.digester3.Rule;
 import org.apache.velocity.tools.ClassUtils;
-import org.apache.velocity.tools.view.ViewContext;
 import org.apache.velocity.tools.Scope;
-import org.apache.velocity.tools.ToolContext;
 import org.apache.velocity.tools.config.DefaultKey;
 import org.apache.velocity.tools.config.ValidScope;
 
@@ -118,7 +116,8 @@ import org.apache.velocity.tools.config.
 
 @DefaultKey("depends")
 @ValidScope(Scope.REQUEST)
-public class UiDependencyTool {
+public class UiDependencyTool extends SafeConfig
+{
 
     public static final String GROUPS_KEY_SPACE = UiDependencyTool.class.getName() + ":";
     public static final String TYPES_KEY_SPACE = UiDependencyTool.class.getName() + ":types:";
@@ -149,7 +148,7 @@ public class UiDependencyTool {
         if (file == null) {
             file = DEFAULT_SOURCE_FILE;
         } else {
-            LOG.debug("UiDependencyTool: Loading file: {}", file);
+            getLog().debug("UiDependencyTool: Loading file: {}", file);
         }
 
         synchronized (app) {
@@ -370,15 +369,15 @@ public class UiDependencyTool {
      * wrapped as {@link RuntimeException}s.
      */
     protected void read(String file, boolean required) {
-        LOG.debug("UiDependencyTool: Reading file from {}", file);
+        getLog().debug("UiDependencyTool: Reading file from {}", file);
         URL url = toURL(file);
         if (url == null) {
             String msg = "UiDependencyTool: Could not read file from '"+file+"'";
             if (required) {
-                LOG.error(msg);
+                getLog().error(msg);
                 throw new IllegalArgumentException(msg);
             } else {
-                LOG.debug(msg);
+                getLog().debug(msg);
             }
         } else {
             Digester digester = createDigester();
@@ -388,12 +387,12 @@ public class UiDependencyTool {
             }
             catch (SAXException saxe)
             {
-                LOG.error("UiDependencyTool: Failed to parse '{}'", file, saxe);
+                getLog().error("UiDependencyTool: Failed to parse '{}'", file, saxe);
                 throw new RuntimeException("While parsing the InputStream", saxe);
             }
             catch (IOException ioe)
             {
-                LOG.error("UiDependencyTool: Failed to read '{}'", file, ioe);
+                getLog().error("UiDependencyTool: Failed to read '{}'", file, ioe);
                 throw new RuntimeException("While handling the InputStream", ioe);
             }
         }
@@ -443,7 +442,7 @@ public class UiDependencyTool {
      * on it unless you're willing to update your code whenever this changes.
      */
     protected Group makeGroup(String name) {
-        LOG.trace("UiDependencyTool: Creating group '{}'", name);
+        getLog().trace("UiDependencyTool: Creating group '{}'", name);
         Group group = new Group(name);
         groups.put(name, group);
         return group;
@@ -460,7 +459,7 @@ public class UiDependencyTool {
         for (Map.Entry<String,List<String>> entry : fbt.entrySet()) {
             String type = entry.getKey();
             if (getType(type) == null) {
-                LOG.error("UiDependencyTool: Type '{}' is unknown and will not be printed
unless defined.", type);
+                getLog().error("UiDependencyTool: Type '{}' is unknown and will not be printed
unless defined.", type);
             }
             List<String> existing = dependencies.get(type);
             if (existing == null) {
@@ -469,7 +468,7 @@ public class UiDependencyTool {
             }
             for (String file : entry.getValue()) {
                 if (!existing.contains(file)) {
-                    LOG.trace("UiDependencyTool: Adding {}: {}", type, file);
+                    getLog().trace("UiDependencyTool: Adding {}: {}", type, file);
                     existing.add(file);
                 }
             }
@@ -491,7 +490,7 @@ public class UiDependencyTool {
             dependencies.put(type, files);
         }
         if (!files.contains(file)) {
-            LOG.trace("UiDependencyTool: Adding {}: {}", type, file);
+            getLog().trace("UiDependencyTool: Adding {}: {}", type, file);
             files.add(file);
         }
     }
@@ -526,7 +525,7 @@ public class UiDependencyTool {
      * NOTE: This class may change or disappear w/o warning; don't depend
      * on it unless you're willing to update your code whenever this changes.
      */
-    protected static class Group {
+    protected class Group {
 
         private volatile boolean resolved = true;
         private String name;
@@ -545,7 +544,7 @@ public class UiDependencyTool {
                 dependencies.put(type, files);
             }
             if (!files.contains(value)) {
-                LOG.trace("Group {}: Adding {}: {}", name, type, value);
+                getLog().trace("Group {}: Adding {}: {}", name, type, value);
                 files.add(value);
             }
         }
@@ -556,7 +555,7 @@ public class UiDependencyTool {
                 this.groups = new ArrayList<String>();
             }
             if (!this.groups.contains(group)) {
-                LOG.trace("Group {}: Adding group {}", name, group);
+                getLog().trace("Group {}: Adding group {}", name, group);
                 this.groups.add(group);
             }
         }
@@ -570,7 +569,7 @@ public class UiDependencyTool {
             if (!resolved)  {
                 // mark first to keep circular from becoming infinite
                 resolved = true;
-                LOG.trace("Group {}: resolving...", name);
+                getLog().trace("Group {}: resolving...", name);
                 for (String name : groups) {
                     Group group = parent.getGroup(name);
                     if (group == null) {
@@ -583,7 +582,7 @@ public class UiDependencyTool {
                         }
                     }
                 }
-                LOG.trace("Group {}: is resolved.", name);
+                getLog().trace("Group {}: is resolved.", name);
             }
         }
 
@@ -592,7 +591,7 @@ public class UiDependencyTool {
             if (files == null) {
                 files = new ArrayList<String>();
                 files.add(value);
-                LOG.trace("Group {}: adding {} '{}' first", name, type, value);
+                getLog().trace("Group {}: adding {} '{}' first", name, type, value);
                 dependencies.put(type, files);
                 typeCounts.put(type, 1);
             } else if (!files.contains(value)) {
@@ -601,7 +600,7 @@ public class UiDependencyTool {
                     count = 0;
                 }
                 files.add(count, value);
-                LOG.trace("Group {}: adding {} '{}' at {}", name, type, value, count);
+                getLog().trace("Group {}: adding {} '{}' at {}", name, type, value, count);
                 typeCounts.put(type, ++count);
             }
         }



Mime
View raw message