velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r590893 - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools: generic/ struts/ view/
Date Thu, 01 Nov 2007 04:40:22 GMT
Author: nbubna
Date: Wed Oct 31 21:40:21 2007
New Revision: 590893

URL: http://svn.apache.org/viewvc?rev=590893&view=rev
Log:
s/StringBuffer/StringBuilder and other String usage fixes suggested by PMD

Modified:
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/IteratorTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsUtils.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.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/LinkTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/PagerTool.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java
Wed Oct 31 21:40:21 2007
@@ -660,7 +660,7 @@
      */
     protected Locale parseLocale(String value)
     {
-        if (value.indexOf("_") < 0)
+        if (value.indexOf('_') < 0)
         {
             return new Locale(value);
         }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
Wed Oct 31 21:40:21 2007
@@ -151,10 +151,10 @@
      * https://svn.apache.org/repos/asf/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java
      */
     protected String dumpString(String string, boolean key) {
-        StringBuffer buffer = new StringBuffer();
+        StringBuilder builder = new StringBuilder();
         int i = 0;
         if (!key && i < string.length() && string.charAt(i) == ' ') {
-            buffer.append("\\ "); //$NON-NLS-1$
+            builder.append("\\ "); //$NON-NLS-1$
             i++;
         }
 
@@ -162,34 +162,34 @@
             char ch = string.charAt(i);
             switch (ch) {
                 case '\t':
-                    buffer.append("\\t"); //$NON-NLS-1$
+                    builder.append("\\t"); //$NON-NLS-1$
                     break;
                 case '\n':
-                    buffer.append("\\n"); //$NON-NLS-1$
+                    builder.append("\\n"); //$NON-NLS-1$
                     break;
                 case '\f':
-                    buffer.append("\\f"); //$NON-NLS-1$
+                    builder.append("\\f"); //$NON-NLS-1$
                     break;
                 case '\r':
-                    buffer.append("\\r"); //$NON-NLS-1$
+                    builder.append("\\r"); //$NON-NLS-1$
                     break;
                 default:
                     if ("\\#!=:".indexOf(ch) >= 0 || (key && ch == ' ')) {
-                        buffer.append('\\');
+                        builder.append('\\');
                     }
                     if (ch >= ' ' && ch <= '~') {
-                        buffer.append(ch);
+                        builder.append(ch);
                     } else {
                         String hex = Integer.toHexString(ch);
-                        buffer.append("\\u"); //$NON-NLS-1$
+                        builder.append("\\u"); //$NON-NLS-1$
                         for (int j = 0; j < 4 - hex.length(); j++) {
-                            buffer.append("0"); //$NON-NLS-1$
+                            builder.append("0"); //$NON-NLS-1$
                         }
-                        buffer.append(hex);
+                        builder.append(hex);
                 }
             }
         }
-        return buffer.toString();
+        return builder.toString();
     } 
 
     /**

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/IteratorTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/IteratorTool.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/IteratorTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/IteratorTool.java
Wed Oct 31 21:40:21 2007
@@ -364,7 +364,7 @@
      */
     public String toString()
     {
-        StringBuffer out = new StringBuffer(this.getClass().getName());
+        StringBuilder out = new StringBuilder(this.getClass().getName());
         if (this.wrapped != null)
         {
             out.append('(');

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageTool.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/MessageTool.java
Wed Oct 31 21:40:21 2007
@@ -296,7 +296,7 @@
          */
         public TextKey get(String appendme)
         {
-            StringBuffer sb = new StringBuffer(this.key);
+            StringBuilder sb = new StringBuilder(this.key);
             sb.append('.');
             sb.append(appendme);
             return new TextKey(sb.toString(), this.bundle, this.args, this.locale);

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/SecureLinkTool.java
Wed Oct 31 21:40:21 2007
@@ -114,7 +114,7 @@
     public String computeURL(HttpServletRequest request,
                              ServletContext app, String link)
     {
-        StringBuffer url = new StringBuffer(link);
+        StringBuilder url = new StringBuilder(link);
 
         String contextPath = request.getContextPath();
 
@@ -156,7 +156,7 @@
                     if (securePlugin.getSslExtAddSession() && url.toString().indexOf(";jsessionid=")
< 0)
                     {
                         // Add the session identifier
-                        url = new StringBuffer(toEncoded(url.toString(),
+                        url = new StringBuilder(toEncoded(url.toString(),
                                                request.getSession().getId()));
                     }
                 }
@@ -211,14 +211,14 @@
 
             // Strip off the query string, if any
             // (differs from the SSL Ext. version - query string before anchor)
-            int question = linkString.indexOf("?");
+            int question = linkString.indexOf('?');
             if (question >= 0)
             {
                 linkString = linkString.substring(0, question);
             }
 
             // Strip off the anchor, if any
-            int anchor = linkString.indexOf("#");
+            int anchor = linkString.indexOf('#');
             if (anchor >= 0)
             {
                 linkString = linkString.substring(0, anchor);
@@ -255,13 +255,13 @@
      * @param request The current request
      * @param desiredScheme  The scheme (http or https) to be used in the new URL
      * @param desiredPort The port number to be used in th enew URL
-     * @return The new URL as a StringBuffer
+     * @return The new URL as a StringBuilder
      */
-    private static StringBuffer startNewUrlString(HttpServletRequest request,
+    private static StringBuilder startNewUrlString(HttpServletRequest request,
                                                   String desiredScheme,
                                                   String desiredPort)
     {
-        StringBuffer url = new StringBuffer();
+        StringBuilder url = new StringBuilder();
         String serverName = request.getServerName();
         url.append(desiredScheme).append("://").append(serverName);
 
@@ -305,7 +305,7 @@
             query = path.substring(question);
             path = path.substring(0, question);
         }
-        StringBuffer sb = new StringBuffer(path);
+        StringBuilder sb = new StringBuilder(path);
         // jsessionid can't be first.
         if (sb.length() > 0)
         {

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsUtils.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsUtils.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsUtils.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/StrutsUtils.java
Wed Oct 31 21:40:21 2007
@@ -307,13 +307,13 @@
     public static String getActionMappingName(String action) {
 
         String value = action;
-        int question = action.indexOf("?");
+        int question = action.indexOf('?');
         if (question >= 0) {
             value = value.substring(0, question);
         }
 
-        int slash = value.lastIndexOf("/");
-        int period = value.lastIndexOf(".");
+        int slash = value.lastIndexOf('/');
+        int period = value.lastIndexOf('.');
         if ((period >= 0) && (period > slash)) {
             value = value.substring(0, period);
         }
@@ -333,7 +333,7 @@
                                              HttpServletRequest request,
                                              String action)
     {
-        StringBuffer value = new StringBuffer(request.getContextPath());
+        StringBuilder value = new StringBuilder(request.getContextPath());
         ModuleConfig config =
             (ModuleConfig)request.getAttribute(Globals.MODULE_KEY);
         if (config != null)
@@ -348,7 +348,7 @@
         if (servletMapping != null)
         {
             String queryString = null;
-            int question = action.indexOf("?");
+            int question = action.indexOf('?');
 
             if (question >= 0)
             {
@@ -428,7 +428,7 @@
             }
         }
 
-        StringBuffer url = new StringBuffer();
+        StringBuilder url = new StringBuilder();
         if (fc.getPath().startsWith("/"))
         {
             url.append(request.getContextPath());
@@ -511,7 +511,7 @@
         }
 
         /* Render the error messages appropriately if errors have been queued */
-        StringBuffer results = new StringBuffer();
+        StringBuilder results = new StringBuilder();
         String header = null;
         String footer = null;
         String prefix = null;

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/struts/ValidatorTool.java
Wed Oct 31 21:40:21 2007
@@ -375,7 +375,7 @@
      */
     public String getStaticJavascript() throws Exception
     {
-        StringBuffer results = new StringBuffer();
+        StringBuilder results = new StringBuilder();
 
         results.append(getStartElement());
         if (this.htmlComment)
@@ -415,7 +415,7 @@
      */
     protected String getJavascript(String formName, boolean getStatic) throws Exception
     {
-        StringBuffer results = new StringBuffer();
+        StringBuilder results = new StringBuilder();
 
         Locale locale = StrutsUtils.getLocale(request, session);
 
@@ -452,7 +452,7 @@
                                           Locale locale,
                                           Form form)
     {
-        StringBuffer results = new StringBuffer();
+        StringBuilder results = new StringBuilder();
 
         MessageResources messages =
             StrutsUtils.getMessageResources(request, app);
@@ -525,8 +525,7 @@
                 results.append(field.getKey()); // TODO: escape?
                 results.append("\", \"");
                 results.append(escapeJavascript(message));
-                results.append("\", ");
-                results.append("new Function (\"varName\", \"");
+                results.append("\", new Function (\"varName\", \"");
 
                 Map<String,Var> vars = (Map<String,Var>)field.getVars();
                 // Loop through the field's variables.
@@ -617,7 +616,7 @@
         }
 
         // guess at how many chars we'll be adding...
-        StringBuffer out = new StringBuffer(length + 4);
+        StringBuilder out = new StringBuilder(length + 4);
         // run through the string escaping sensitive chars
         for (int i=0; i < length; i++)
         {
@@ -645,13 +644,13 @@
     {
         String methodOperator = " && ";
 
-        StringBuffer methods = null;
+        StringBuilder methods = null;
         for (Iterator i = actions.iterator(); i.hasNext();)
         {
             ValidatorAction va = (ValidatorAction)i.next();
             if (methods == null)
             {
-                methods = new StringBuffer(va.getMethod());
+                methods = new StringBuilder(va.getMethod());
             }
             else
             {
@@ -728,7 +727,7 @@
      */
     protected String getJavascriptBegin(String methods)
     {
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         String name = jsFormName.replace('/', '_'); // remove any '/' characters
         name = jsFormName.substring(0, 1).toUpperCase() +
                       jsFormName.substring(1, jsFormName.length());
@@ -756,12 +755,10 @@
             sb.append("    function ");
             sb.append(methodName);
         }
-        sb.append("(form) {");
-        //FIXME? anyone know why all these spaces need to be here?
-        sb.append("                                                                   \n");
-        sb.append("        if (bCancel) \n");
-        sb.append("      return true; \n");
-        sb.append("        else \n");
+        sb.append("(form) {\n");
+        sb.append("      if (bCancel) \n");
+        sb.append("          return true; \n");
+        sb.append("      else \n");
 
         // Always return true if there aren't any Javascript validation methods
         if (methods == null || methods.length() == 0)
@@ -788,7 +785,7 @@
      */
     protected String getJavascriptStaticMethods(ValidatorResources resources)
     {
-        StringBuffer sb = new StringBuffer("\n\n");
+        StringBuilder sb = new StringBuilder("\n\n");
 
         Iterator actions = resources.getValidatorActions().values().iterator();
         while (actions.hasNext())
@@ -799,7 +796,8 @@
                 String javascript = va.getJavascript();
                 if (javascript != null && javascript.length() > 0)
                 {
-                    sb.append(javascript + "\n");
+                    sb.append(javascript);
+                    sb.append("\n");
                 }
             }
         }
@@ -814,7 +812,7 @@
      */
     protected String getJavascriptEnd()
     {
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append("\n");
 
         if (!this.xhtml && this.htmlComment)
@@ -839,7 +837,7 @@
      */
     private String getStartElement()
     {
-        StringBuffer start = new StringBuffer("<script type=\"text/javascript\"");
+        StringBuilder start = new StringBuilder("<script type=\"text/javascript\"");
 
         // there is no language attribute in xhtml
         if (!this.xhtml)

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?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- 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
Wed Oct 31 21:40:21 2007
@@ -151,7 +151,7 @@
             try
             {
                 r = new BufferedReader(acquireReader(url));
-                StringBuffer sb = new StringBuffer();
+                StringBuilder sb = new StringBuilder();
                 int i;
                 // under JIT, testing seems to show this simple loop is as fast
                 // as any of the alternatives
@@ -586,7 +586,7 @@
 
         // do a fast, simple check first
         int colonPos;
-        if ((colonPos = url.indexOf(":")) == -1)
+        if ((colonPos = url.indexOf(':')) == -1)
         {
             return false;
         }
@@ -615,7 +615,7 @@
      */
     public static String stripSession(String url)
     {
-        StringBuffer u = new StringBuffer(url);
+        StringBuilder u = new StringBuilder(url);
         int sessionStart;
         while ((sessionStart = u.toString().indexOf(";jsessionid=")) != -1)
         {

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/LinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/LinkTool.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/LinkTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/LinkTool.java
Wed Oct 31 21:40:21 2007
@@ -627,7 +627,7 @@
         if (queryData != null && !queryData.isEmpty())
         {
 
-            StringBuffer out = new StringBuffer();
+            StringBuilder out = new StringBuilder();
             for(int i=0; i < queryData.size(); i++)
             {
                 out.append(queryData.get(i));
@@ -721,7 +721,7 @@
         String scheme = request.getScheme();
         int port = request.getServerPort();
 
-        StringBuffer out = new StringBuffer();
+        StringBuilder out = new StringBuilder();
         out.append(request.getScheme());
         out.append("://");
         out.append(request.getServerName());
@@ -774,7 +774,7 @@
      */
     public String getBaseRef()
     {
-        StringBuffer out = new StringBuffer();
+        StringBuilder out = new StringBuilder();
         out.append(getContextURL());
         out.append(getRequestPath());
         return out.toString();
@@ -828,7 +828,7 @@
      */
     public String toString()
     {
-        StringBuffer out = new StringBuffer();
+        StringBuilder out = new StringBuilder();
 
         if (uri != null)
         {
@@ -929,7 +929,7 @@
          */
         public String toString()
         {
-            StringBuffer out = new StringBuffer();
+            StringBuilder out = new StringBuilder();
             if (value == null)
             {
                 out.append(encodeURL(key));
@@ -954,7 +954,7 @@
         }
 
         /* Utility method to avoid logic duplication in toString() */
-        private void appendAsArray(StringBuffer out, String key, Object[] arr)
+        private void appendAsArray(StringBuilder out, String key, Object[] arr)
         {
             String encKey = encodeURL(key);
             for (int i=0; i < arr.length; i++)

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/PagerTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/PagerTool.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/PagerTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/PagerTool.java
Wed Oct 31 21:40:21 2007
@@ -527,7 +527,7 @@
             return "0 of 0";
         }
 
-        StringBuffer out = new StringBuffer();
+        StringBuilder out = new StringBuilder();
         int first = getFirstIndex().intValue() + 1;
         int total = getTotal();
         if (first >= total)

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java?rev=590893&r1=590892&r2=590893&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
Wed Oct 31 21:40:21 2007
@@ -282,7 +282,7 @@
     {
         try
         {
-            StringBuffer html = new StringBuffer();
+            StringBuilder html = new StringBuilder();
             html.append("<html>\n");
             html.append("<head><title>Error</title></head>\n");
             html.append("<body>\n");
@@ -293,7 +293,7 @@
             Throwable cause = e;
 
             String why = cause.getMessage();
-            if (why != null && why.trim().length() > 0)
+            if (why != null && why.length() > 0)
             {
                 html.append(StringEscapeUtils.escapeHtml(why));
                 html.append("\n<br>\n");



Mime
View raw message