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/12/09 19:56:07 UTC
svn commit: r724825 - in
/velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime:
directive/Directive.java directive/Include.java directive/Parse.java
log/Log.java parser/node/ASTDirective.java
Author: nbubna
Date: Tue Dec 9 10:56:06 2008
New Revision: 724825
URL: http://svn.apache.org/viewvc?rev=724825&view=rev
Log:
merge fix for VELOCITY-654 from trunk
Modified:
velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Directive.java
velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Include.java
velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Parse.java
velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/log/Log.java
velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
Modified: velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Directive.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Directive.java?rev=724825&r1=724824&r2=724825&view=diff
==============================================================================
--- velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Directive.java (original)
+++ velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Directive.java Tue Dec 9 10:56:06 2008
@@ -43,6 +43,7 @@
{
private int line = 0;
private int column = 0;
+ private String templateName;
/**
*
@@ -73,6 +74,17 @@
}
/**
+ * Allows the template location to be set.
+ * @param line
+ * @param column
+ */
+ public void setLocation(int line, int column, String templateName)
+ {
+ setLocation(line, column);
+ this.templateName = templateName;
+ }
+
+ /**
* for log msg purposes
* @return The current line for log msg purposes.
*/
@@ -89,6 +101,15 @@
{
return column;
}
+
+ /**
+ * @return The template file name this directive was defined in, or null if not
+ * defined in a file.
+ */
+ public String getTemplateName()
+ {
+ return templateName;
+ }
/**
* How this directive is to be initialized.
Modified: velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Include.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Include.java?rev=724825&r1=724824&r2=724825&view=diff
==============================================================================
--- velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Include.java (original)
+++ velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Include.java Tue Dec 9 10:56:06 2008
@@ -30,6 +30,7 @@
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.parser.ParserTreeConstants;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.resource.Resource;
@@ -157,9 +158,8 @@
}
else
{
- String msg = "invalid #include() argument type [line "+getLine()+
- ", column "+getColumn()+", template "+
- context.getCurrentTemplateName()+"]: "+n.toString();
+ String msg = "invalid #include() argument '"
+ + n.toString() + "' at " + Log.formatFileString(this);
rsvc.getLog().error(msg);
outputErrorToStream( writer, "error with arg " + i
+ " please see log.");
@@ -198,7 +198,7 @@
Object value = node.value( context );
if ( value == null)
{
- rsvc.getLog().error("#include() null argument");
+ rsvc.getLog().error("#include() null argument");
return false;
}
@@ -234,9 +234,7 @@
* the arg wasn't found. Note it and throw
*/
rsvc.getLog().error("#include(): cannot find resource '" + arg +
- "', called from template " +
- context.getCurrentTemplateName() + " at (" +
- getLine() + ", " + getColumn() + ")" );
+ "', called at " + Log.formatFileString(this));
throw rnfe;
}
@@ -245,14 +243,14 @@
*/
catch( RuntimeException e )
{
+ rsvc.getLog().error("#include(): arg = '" + arg +
+ "', called at " + Log.formatFileString(this));
throw e;
}
catch (Exception e)
{
String msg = "#include(): arg = '" + arg +
- "', called from template " +
- context.getCurrentTemplateName() + " at (" +
- getLine() + ", " + getColumn() + ')';
+ "', called at " + Log.formatFileString(this);
rsvc.getLog().error(msg, e);
throw new VelocityException(msg, e);
}
Modified: velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Parse.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Parse.java?rev=724825&r1=724824&r2=724825&view=diff
==============================================================================
--- velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Parse.java (original)
+++ velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/directive/Parse.java Tue Dec 9 10:56:06 2008
@@ -34,6 +34,7 @@
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.log.Log;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.runtime.parser.node.SimpleNode;
@@ -202,9 +203,7 @@
* the arg wasn't found. Note it and throw
*/
rsvc.getLog().error("#parse(): cannot find template '" + arg +
- "', called from template " +
- context.getCurrentTemplateName() + " at (" +
- getLine() + ", " + getColumn() + ")" );
+ "', called at " + Log.formatFileString(this));
throw rnfe;
}
catch ( ParseErrorException pee )
@@ -213,12 +212,8 @@
* the arg was found, but didn't parse - syntax error
* note it and throw
*/
-
rsvc.getLog().error("#parse(): syntax error in #parse()-ed template '"
- + arg + "', called from template " +
- context.getCurrentTemplateName() + " at (" +
- getLine() + ", " + getColumn() + ")" );
-
+ + arg + "', called at " + Log.formatFileString(this));
throw pee;
}
/**
@@ -226,11 +221,14 @@
*/
catch( RuntimeException e )
{
+ rsvc.getLog().error("Exception rendering #parse(" + arg + ") at " +
+ Log.formatFileString(this));
throw e;
}
catch ( Exception e)
{
- String msg = "#parse() : arg = " + arg + '.';
+ String msg = "Exception rendering #parse(" + arg + ") at " +
+ Log.formatFileString(this);
rsvc.getLog().error(msg, e);
throw new VelocityException(msg, e);
}
@@ -262,27 +260,22 @@
((SimpleNode) t.getData()).render( context, writer );
}
}
-
- /*
- * if it's a MIE, it came from the render.... throw it...
- */
- catch( MethodInvocationException e )
- {
- throw e;
- }
-
/**
* pass through application level runtime exceptions
*/
catch( RuntimeException e )
{
+ /**
+ * Log #parse errors so the user can track which file called which.
+ */
+ rsvc.getLog().error("Exception rendering #parse(" + arg + ") at " +
+ Log.formatFileString(this));
throw e;
}
-
-
catch ( Exception e )
{
- String msg = "Exception rendering #parse(" + arg + ')';
+ String msg = "Exception rendering #parse(" + arg + ") at " +
+ Log.formatFileString(this);
rsvc.getLog().error(msg, e);
throw new VelocityException(msg, e);
}
Modified: velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/log/Log.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/log/Log.java?rev=724825&r1=724824&r2=724825&view=diff
==============================================================================
--- velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/log/Log.java (original)
+++ velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/log/Log.java Tue Dec 9 10:56:06 2008
@@ -1,5 +1,6 @@
package org.apache.velocity.runtime.log;
+import org.apache.velocity.runtime.directive.Directive;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.util.introspection.Info;
@@ -227,6 +228,16 @@
/**
* Creates a string that formats the template filename with line number
+ * and column of the given Directive. We use this routine to provide a cosistent format for displaying
+ * file errors.
+ */
+ public static final String formatFileString(Directive directive)
+ {
+ return formatFileString(directive.getTemplateName(), directive.getLine(), directive.getColumn());
+ }
+
+ /**
+ * Creates a string that formats the template filename with line number
* and column of the given Node. We use this routine to provide a cosistent format for displaying
* file errors.
*/
Modified: velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java?rev=724825&r1=724824&r2=724825&view=diff
==============================================================================
--- velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java (original)
+++ velocity/engine/branches/1.6.x/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java Tue Dec 9 10:56:06 2008
@@ -120,9 +120,8 @@
parser.getDirective(directiveName).getClass().getName(),
e);
}
-
-
- directive.setLocation( getLine(), getColumn() );
+
+ directive.setLocation(getLine(), getColumn(), getTemplateName());
directive.init(rsvc, context,this);
}
else
@@ -131,7 +130,7 @@
* Create a new RuntimeMacro
*/
directive = new RuntimeMacro(directiveName, getTemplateName());
- directive.setLocation( getLine(), getColumn() );
+ directive.setLocation(getLine(), getColumn(), getTemplateName());
/**
* Initialize it