You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2008/10/10 20:15:53 UTC

svn commit: r703544 - in /velocity/engine/trunk/src/java/org/apache/velocity: exception/ runtime/directive/ runtime/log/ runtime/parser/ runtime/parser/node/

Author: nbubna
Date: Fri Oct 10 11:15:53 2008
New Revision: 703544

URL: http://svn.apache.org/viewvc?rev=703544&view=rev
Log:
VELOCITY-622 format template and line/column numbers consistently in error and log messages (thx to Byron Foster)

Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java
    velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java?rev=703544&r1=703543&r2=703544&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java Fri Oct 10 11:15:53 2008
@@ -1,6 +1,7 @@
 package org.apache.velocity.exception;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.velocity.runtime.log.Log;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -135,9 +136,8 @@
     {
         StringBuffer message = new StringBuffer();
         message.append(super.getMessage());
-        message.append(" @ ");
-        message.append(StringUtils.isNotEmpty(templateName) ? templateName : "<unknown template>");
-        message.append("[").append(lineNumber).append(",").append(columnNumber).append("]");
+        message.append(" at ");
+        message.append(Log.formatFileString(templateName, lineNumber, columnNumber));
         return message.toString();
     }
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java?rev=703544&r1=703543&r2=703544&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/MacroParseException.java Fri Oct 10 11:15:53 2008
@@ -20,6 +20,7 @@
  */
 
 import org.apache.velocity.exception.ExtendedParseException;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.ParseException;
 import org.apache.velocity.runtime.parser.Token;
 
@@ -187,17 +188,7 @@
      */
     protected void appendTemplateInfo(final StringBuffer sb)
     {
-        sb.append(" at line ").append(getLineNumber())
-          .append(", column ").append(getColumnNumber());
-
-        if (getTemplateName() != null)
-        {
-            sb.append(" of ").append(getTemplateName());
-        }
-        else
-        {
-            sb.append(".");
-        }
+        sb.append(Log.formatFileString(getTemplateName(), getLineNumber(), getColumnNumber()));
         sb.append(eol);
     }
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java?rev=703544&r1=703543&r2=703544&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java Fri Oct 10 11:15:53 2008
@@ -22,6 +22,7 @@
 import org.apache.commons.lang.text.StrBuilder;
 
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.node.Node;
 import org.apache.velocity.runtime.parser.Token;
 import org.apache.velocity.runtime.RuntimeConstants;
@@ -238,18 +239,18 @@
             {
               Info info = new Info(sourceTemplate, node.getLine(), node.getColumn());
 
-                throw new ParseErrorException(die.getMessage() + " at " + info.getTemplateName()
-                    + "[" + info.getLine() + "," + info.getColumn() + "]", info);
+                throw new ParseErrorException(die.getMessage() + " at "
+                    + Log.formatFileString(info), info);
             }
             return vmProxy.render(context, writer, node);
         }
         else if (strictRef)
         {
             Info info = new Info(sourceTemplate, node.getLine(), node.getColumn());
-            throw new ParseErrorException("Macro '#" + macroName + "' is not defined at "+
-                info.getTemplateName() + "[" + info.getLine() + "," + info.getColumn() + "]", info);
+            throw new ParseErrorException("Macro '#" + macroName + "' is not defined at "
+                + Log.formatFileString(info), info);
         }
-
+        
         /**
          * If we cannot find an implementation write the literal text
          */

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java?rev=703544&r1=703543&r2=703544&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/Log.java Fri Oct 10 11:15:53 2008
@@ -1,5 +1,7 @@
 package org.apache.velocity.runtime.log;
 
+import org.apache.velocity.util.introspection.Info;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -221,5 +223,31 @@
     {
         log(LogChute.ERROR_ID, message, t);
     }
-
+    
+    /**
+     * Simply creates a string that formats the template filename allowing with line number
+     * and column. We use this routine to provide a cosistent format for displaying 
+     * file errors.
+     */
+    public static final String formatFileString(Info info)
+    {
+        return formatFileString(info.getTemplateName(), info.getLine(), info.getColumn());
+    }
+    
+    /**
+     * Simply creates a string that formats the template filename allowing with line number
+     * and column. We use this routine to provide a cosistent format for displaying 
+     * file errors.
+     * @param template File name of template, can be null
+     * @param linenum Line number within the file
+     * @param colnum Column number withing the file at linenum
+     */
+    public static final String formatFileString(String template, int linenum, int colnum)
+    {
+        if (template == null || template.equals(""))
+        {
+            template = "<unknown template>";
+        }
+        return template + "[line " + linenum + ", column " + colnum + "]";
+    }
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java?rev=703544&r1=703543&r2=703544&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/TemplateParseException.java Fri Oct 10 11:15:53 2008
@@ -20,6 +20,7 @@
  */
 
 import org.apache.velocity.exception.ExtendedParseException;
+import org.apache.velocity.runtime.log.Log;
 
 
 /**
@@ -211,7 +212,7 @@
             tok = tok.next;
         }
 
-        retval.append("\"");
+        retval.append("\" at ");
         appendTemplateInfo(retval);
 
         if (expectedTokenSequences.length == 1)
@@ -233,17 +234,7 @@
      */
     protected void appendTemplateInfo(final StringBuffer sb)
     {
-        sb.append(" at line ").append(getLineNumber())
-          .append(", column ").append(getColumnNumber());
-
-        if (getTemplateName() != null)
-        {
-            sb.append(" of ").append(getTemplateName());
-        }
-        else
-        {
-            sb.append(".");
-        }
+        sb.append(Log.formatFileString(getTemplateName(), getLineNumber(), getColumnNumber()));
         sb.append(eol);
     }
 }

Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java?rev=703544&r1=703543&r2=703544&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java Fri Oct 10 11:15:53 2008
@@ -31,6 +31,7 @@
 import org.apache.velocity.exception.VelocityException;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.Renderable;
+import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.Token;
 import org.apache.velocity.util.introspection.Info;
@@ -635,8 +636,7 @@
              *  maybe a security exception?
              */
             String msg = "ASTReference setValue() : exception : " + e
-                          + " template = " + context.getCurrentTemplateName()
-                          + " [" + this.getLine() + "," + this.getColumn() + "]";
+                          + " template at " + Log.formatFileString(uberInfo);
             log.error(msg, e);
             throw new VelocityException(msg, e);
          }