You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@locus.apache.org on 2000/11/07 22:31:29 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node ASTDirective.java ASTElseIfStatement.java ASTElseStatement.java ASTIfStatement.java ASTReference.java ASTSetDirective.java NodeUtils.java
geirm 00/11/07 13:31:26
Modified: src/java/org/apache/velocity/runtime/parser/node
ASTDirective.java ASTElseIfStatement.java
ASTElseStatement.java ASTIfStatement.java
ASTReference.java ASTSetDirective.java
NodeUtils.java
Log:
Changes to support escape handling. An upside is that all control AST nodes are touched on a render, if we wish to use that for something...
Revision Changes Path
1.6 +46 -11 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
Index: ASTDirective.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ASTDirective.java 2000/11/05 23:19:51 1.5
+++ ASTDirective.java 2000/11/07 21:30:52 1.6
@@ -64,7 +64,7 @@
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
- * @version $Id: ASTDirective.java,v 1.5 2000/11/05 23:19:51 jvanzyl Exp $
+ * @version $Id: ASTDirective.java,v 1.6 2000/11/07 21:30:52 geirm Exp $
*/
package org.apache.velocity.runtime.parser.node;
@@ -82,6 +82,7 @@
private String directiveName;
private boolean isDirective;
private boolean bIsEscaped_ = false;
+ private String strPrefix_ = "";
public ASTDirective(int id)
{
@@ -107,18 +108,37 @@
*/
bIsEscaped_ = false;
+ isDirective = false;
+ directiveName = getFirstToken().image.substring(1);
+
if ( getFirstToken().image.startsWith("\\") )
{
- bIsEscaped_ = true;
- return data;
- }
+ /*
+ * count the escapes : even # -> not escaped, odd -> escaped
+ */
+
+ int i = 0;
+ int iLen = getFirstToken().image.length();
+
+ while( i < iLen && getFirstToken().image.charAt(i) == '\\' )
+ i++;
+
+ if ( (i % 2) != 0 )
+ bIsEscaped_ = true;
+
+ if (i > 0)
+ strPrefix_ = getFirstToken().image.substring(0, i / 2 );
+
+ directiveName = getFirstToken().image.substring(i+1);
+
+ if (bIsEscaped_)
+ return data;
+ }
/*
- * otherwise, normal processing
+ * normal processing
*/
-
- directiveName = getFirstToken().image.substring(1);
if (parser.isDirective(directiveName))
{
@@ -152,10 +172,16 @@
* write it is \#foo
*/
- if ( parser.isDirective( getFirstToken().image.substring(2) ) )
- writer.write( getFirstToken().image.substring(1));
+ if ( parser.isDirective( directiveName ) )
+ writer.write( strPrefix_ + "#" + directiveName );
else
- writer.write( getFirstToken().image );
+ {
+ /*
+ * do two strPrefix_, because if this is not a directive, it's schmoo, and therefore
+ * the \ have no magic binding properties
+ */
+ writer.write( strPrefix_ + strPrefix_ + "\\#" + directiveName );
+ }
return true;
}
@@ -165,10 +191,19 @@
*/
if (isDirective)
+ {
+ if (strPrefix_.length() > 0)
+ writer.write( strPrefix_ );
directive.render(context, writer, this);
+
+ }
else
{
- writer.write( "#" + directiveName);
+ /*
+ * do two strPrefix_, because if this is not a directive, it's schmoo, and therefore
+ * the \ have no magic binding properties
+ */
+ writer.write( strPrefix_ + strPrefix_ + "#" + directiveName);
}
return true;
1.2 +115 -0 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java
Index: ASTElseIfStatement.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ASTElseIfStatement.java 2000/10/20 19:14:02 1.1
+++ ASTElseIfStatement.java 2000/11/07 21:30:56 1.2
@@ -1,11 +1,82 @@
/* Generated By:JJTree: Do not edit this line. ASTElseIfStatement.java */
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+
+/**
+ * This class is responsible for handling the ElseIf VTL control statement.
+ *
+ * Please look at the Parser.jjt file which is
+ * what controls the generation of this class.
+ *
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: ASTElseIfStatement.java,v 1.2 2000/11/07 21:30:56 geirm Exp $
+*/
+
package org.apache.velocity.runtime.parser.node;
+import java.io.Writer;
+import java.io.IOException;
+
+import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTElseIfStatement extends SimpleNode
{
+ public String strPrefix_ = "";
+
public ASTElseIfStatement(int id)
{
super(id);
@@ -14,6 +85,50 @@
public ASTElseIfStatement(Parser p, int id)
{
super(p, id);
+ }
+
+ public Object init(Context context, Object data) throws Exception
+ {
+ /*
+ * init our tree correctly
+ */
+
+ super.init( context, data );
+
+ /*
+ * see if we have any escape shmoo attached...
+ */
+
+ Token t = getFirstToken();
+
+ strPrefix_ = "";
+
+ if (t.image.startsWith("\\"))
+ {
+ int i = 0;
+ int iLen = t.image.length();
+
+ while( i < iLen && t.image.charAt(i) == '\\' )
+ i++;
+
+ if (i > 0)
+ strPrefix_ = t.image.substring(0, i / 2 );
+ }
+
+ return data;
+ }
+
+ public boolean render(Context context, Writer writer)
+ throws IOException
+ {
+ /*
+ * always write out the prefix.
+ */
+
+ if ( strPrefix_.length() > 0)
+ writer.write( strPrefix_);
+
+ return true;
}
/** Accept the visitor. **/
1.2 +116 -0 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTElseStatement.java
Index: ASTElseStatement.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTElseStatement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ASTElseStatement.java 2000/10/20 19:14:02 1.1
+++ ASTElseStatement.java 2000/11/07 21:30:58 1.2
@@ -1,11 +1,82 @@
/* Generated By:JJTree: Do not edit this line. ASTElseStatement.java */
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+
+/**
+ * This class is responsible for handling the Else VTL control statement.
+ *
+ * Please look at the Parser.jjt file which is
+ * what controls the generation of this class.
+ *
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: ASTElseStatement.java,v 1.2 2000/11/07 21:30:58 geirm Exp $
+*/
+
package org.apache.velocity.runtime.parser.node;
+import java.io.Writer;
+import java.io.IOException;
+
+import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTElseStatement extends SimpleNode
{
+ public String strPrefix_ = "";
+
public ASTElseStatement(int id)
{
super(id);
@@ -16,9 +87,54 @@
super(p, id);
}
+ public Object init(Context context, Object data) throws Exception
+ {
+ /*
+ * init our tree correctly
+ */
+
+ super.init( context, data );
+
+ /*
+ * see if we have any escape shmoo attached...
+ */
+
+ Token t = getFirstToken();
+
+ strPrefix_ = "";
+
+ if (t.image.startsWith("\\"))
+ {
+ int i = 0;
+ int iLen = t.image.length();
+
+ while( i < iLen && t.image.charAt(i) == '\\' )
+ i++;
+
+ if (i > 0)
+ strPrefix_ = t.image.substring(0, i / 2 );
+ }
+
+ return data;
+ }
+
+ public boolean render(Context context, Writer writer)
+ throws IOException
+ {
+ /*
+ * always write out the prefix.
+ */
+
+ if ( strPrefix_.length() > 0)
+ writer.write(strPrefix_);
+
+ return true;
+ }
+
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
}
+
1.3 +174 -6 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java
Index: ASTIfStatement.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ASTIfStatement.java 2000/10/21 01:36:49 1.2
+++ ASTIfStatement.java 2000/11/07 21:31:00 1.3
@@ -1,4 +1,70 @@
/* Generated By:JJTree: Do not edit this line. ASTIfStatement.java */
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+
+/**
+ * Handles the VTL EndStatements. Right now, this is only needed for
+ * proper handling of escape output
+ *
+ * Please look at the Parser.jjt file which is
+ * what controls the generation of this class.
+ *
+ * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: ASTIfStatement.java,v 1.3 2000/11/07 21:31:00 geirm Exp $
+*/
package org.apache.velocity.runtime.parser.node;
@@ -10,26 +76,70 @@
public class ASTIfStatement extends SimpleNode
{
-
+ public String strPrefix_ = "";
+
public ASTIfStatement(int id)
{
super(id);
}
-
+
public ASTIfStatement(Parser p, int id)
{
super(p, id);
}
-
+
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
+
+ public Object init(Context context, Object data) throws Exception
+ {
+ /*
+ * init our tree correctly
+ */
+
+ super.init( context, data );
+
+ /*
+ * see if we have any escape shmoo attached...
+ */
+
+ Token t = getFirstToken();
+
+ strPrefix_ = "";
+
+ if (t.image.startsWith("\\"))
+ {
+ int i = 0;
+ int iLen = t.image.length();
+
+ while( i < iLen && t.image.charAt(i) == '\\' )
+ i++;
+
+ if (i > 0)
+ strPrefix_ = t.image.substring(0, i / 2 );
+ }
+
+ return data;
+ }
+
public boolean render(Context context, Writer writer)
throws IOException
{
+ /*
+ * always write out the prefix.
+ */
+
+ if ( strPrefix_.length() > 0)
+ writer.write( strPrefix_ );
+
+ /*
+ * and the regular processing
+ */
+
Object data = null;
Node expression;
@@ -38,10 +148,40 @@
// the presence of an else block and process that
// if the expression doesn't evaluate to true.
//if (evaluateExpression(expression))
+
+ /*
+ * $$$ gmj
+ * This is a mess (the logic so we are sure to render each control node...must revisit)
+ */
+
expression = jjtGetChild(0);
+
if (expression.evaluate(context))
{
+ /*
+ * this is the block following the if
+ */
+
jjtGetChild(1).render(context, writer);
+
+ /*
+ * if there is an #else or #elseif, we need to render that beause of the strange way escaping works
+ */
+
+ int iChildren = jjtGetNumChildren();
+
+ for (int i = 2; i < iChildren; i++)
+ {
+ Node child = jjtGetChild(i);
+
+ if (child.getType() == ParserTreeConstants.JJTELSESTATEMENT
+ || child.getType() == ParserTreeConstants.JJTELSEIFSTATEMENT
+ || child.getType() == ParserTreeConstants.JJTENDSTATEMENT )
+ {
+ child.render(context, writer);
+ }
+ }
+
}
else
{
@@ -55,19 +195,33 @@
for (int i = 2; i < children; i++)
{
Node child = jjtGetChild(i);
+
+ /*
+ * so we get the \\#else and \\#elseif and \\#end
+ */
+
+ if (child.getType() == ParserTreeConstants.JJTELSESTATEMENT
+ || child.getType() == ParserTreeConstants.JJTELSEIFSTATEMENT
+ || child.getType() == ParserTreeConstants.JJTENDSTATEMENT )
+ {
+ child.render(context, writer);
+ }
+
if (child.getType() == ParserTreeConstants.JJTELSEIFSTATEMENT)
{
expression = child.jjtGetChild(0);
+
if (expression.evaluate(context))
{
child.jjtGetChild(1).render(context, writer);
- break;
+ // break;
}
}
else
- child.jjtGetChild(0).render(context, writer);
+ if (child.getType() != ParserTreeConstants.JJTENDSTATEMENT )
+ child.jjtGetChild(0).render(context, writer);
}
- }
+ }
return true;
}
@@ -76,3 +230,17 @@
{
}
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1.9 +30 -14 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
Index: ASTReference.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ASTReference.java 2000/11/03 03:27:05 1.8
+++ ASTReference.java 2000/11/07 21:31:01 1.9
@@ -64,7 +64,7 @@
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
- * @version $Id: ASTReference.java,v 1.8 2000/11/03 03:27:05 geirm Exp $
+ * @version $Id: ASTReference.java,v 1.9 2000/11/07 21:31:01 geirm Exp $
*/
package org.apache.velocity.runtime.parser.node;
@@ -92,7 +92,8 @@
private Object value;
private String rootString;
private boolean bIsEscaped_ = false;
-
+ private String strPrefix_ = "";
+
public ASTReference(int id)
{
super(id);
@@ -156,15 +157,14 @@
* 1) if this is a reference in the context, then we want to print $foo
* 2) if not, then \$foo (its considered shmoo, not VTL)
*
- * I am not wild about this specialText() stuff...
*/
if (bIsEscaped_)
{
if ( value == null )
- writer.write( NodeUtils.specialText(getFirstToken()) + "\\" + nullString );
+ writer.write( NodeUtils.specialText(getFirstToken()) + strPrefix_ + "\\" + nullString );
else
- writer.write( NodeUtils.specialText(getFirstToken()) + nullString );
+ writer.write( NodeUtils.specialText(getFirstToken()) + strPrefix_ + nullString );
return true;
}
@@ -175,18 +175,18 @@
if (value == null)
{
- writer.write(NodeUtils
- .specialText(getFirstToken()) +
- nullString);
+ /*
+ * write prefix twice, because it's shmoo, so the \ don't escape each other...
+ */
+
+ writer.write(NodeUtils.specialText(getFirstToken()) + strPrefix_ + strPrefix_ + nullString);
if (referenceType != QUIET_REFERENCE)
Runtime.error(new ReferenceException("reference", this));
}
else
{
- writer.write(NodeUtils
- .specialText(getFirstToken()) +
- value.toString());
+ writer.write(NodeUtils.specialText(getFirstToken()) + strPrefix_ + value.toString());
}
return true;
@@ -279,7 +279,7 @@
/*
* we need to see if this reference is escaped. if so
- * we will clean off the leading \ and let the
+ * we will clean off the leading \'s and let the
* regular behavior determine if we should output this
* as \$foo or $foo later on in render(). Lazyness..
*/
@@ -288,9 +288,25 @@
if ( t.image.startsWith("\\"))
{
- bIsEscaped_ = true;
+ /*
+ * count the escapes : even # -> not escaped, odd -> escaped
+ */
+
+ int i = 0;
+ int iLen = t.image.length();
+
+ while( i < iLen && t.image.charAt(i) == '\\' )
+ i++;
+
+ if ( (i % 2) != 0 )
+ bIsEscaped_ = true;
+
+ if (i > 0)
+ strPrefix_ = t.image.substring(0, i / 2 );
+
+ //System.out.println( t.image + " " + i + " " + strPrefix_ );
- t.image = t.image.substring(1);
+ t.image = t.image.substring(i);
}
/*
1.6 +33 -1 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
Index: ASTSetDirective.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ASTSetDirective.java 2000/10/31 20:32:55 1.5
+++ ASTSetDirective.java 2000/11/07 21:31:03 1.6
@@ -59,7 +59,7 @@
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
- * @version $Id: ASTSetDirective.java,v 1.5 2000/10/31 20:32:55 jvanzyl Exp $
+ * @version $Id: ASTSetDirective.java,v 1.6 2000/11/07 21:31:03 geirm Exp $
*/
package org.apache.velocity.runtime.parser.node;
@@ -77,6 +77,7 @@
private Node right;
private ASTReference left;
private Object value;
+ public String strPrefix_ = "";
public ASTSetDirective(int id)
{
@@ -117,6 +118,26 @@
super.init( context, data );
+ /*
+ * see if we have any escape shmoo attached...
+ */
+
+ Token t = getFirstToken();
+
+ strPrefix_ = "";
+
+ if (t.image.startsWith("\\"))
+ {
+ int i = 0;
+ int iLen = t.image.length();
+
+ while( i < iLen && t.image.charAt(i) == '\\' )
+ i++;
+
+ if (i > 0)
+ strPrefix_ = t.image.substring(0, i / 2 );
+ }
+
/**
* We need to place all RHS objects into the context
* so that subsequent introspection is performed
@@ -163,6 +184,17 @@
public boolean render(Context context, Writer writer)
throws IOException
{
+ /*
+ * write any output we need to do (should be just escapes now)
+ */
+
+ if ( strPrefix_.length() > 0)
+ writer.write( strPrefix_ );
+
+ /*
+ * regular processing
+ */
+
right = getRightHandSide();
if (right.value(context) == null)
1.4 +3 -1 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/NodeUtils.java
Index: NodeUtils.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/NodeUtils.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NodeUtils.java 2000/11/05 03:18:24 1.3
+++ NodeUtils.java 2000/11/07 21:31:05 1.4
@@ -57,7 +57,7 @@
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
- * @version $Id: NodeUtils.java,v 1.3 2000/11/05 03:18:24 geirm Exp $
+ * @version $Id: NodeUtils.java,v 1.4 2000/11/07 21:31:05 geirm Exp $
*/
package org.apache.velocity.runtime.parser.node;
@@ -86,4 +86,6 @@
return specialText;
}
+
}
+