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/12/04 03:07:42 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/directive Parse.java
geirm 00/12/03 18:07:41
Modified: src/java/org/apache/velocity/runtime/directive Parse.java
Log:
Removed all init-time context dependant stuff, and moved to render, where it belongs.
Revision Changes Path
1.8 +49 -54 jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Parse.java
Index: Parse.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Parse.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Parse.java 2000/11/28 04:16:22 1.7
+++ Parse.java 2000/12/04 02:07:41 1.8
@@ -83,7 +83,7 @@
*
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: Parse.java,v 1.7 2000/11/28 04:16:22 jvanzyl Exp $
+ * @version $Id: Parse.java,v 1.8 2000/12/04 02:07:41 geirm Exp $
*/
public class Parse extends Directive
{
@@ -107,28 +107,25 @@
int iParseDepth_ = 1;
boolean bReady_ = false;
+
/**
- * Initializes the trees
+ * iterates through the argument list and renders every
+ * argument that is appropriate. Any non appropriate
+ * arguments are logged, but render() continues.
*/
- public void init(Context context, Node node)
- throws Exception
+ public boolean render(Context context, Writer writer, Node node)
+ throws IOException
{
/*
- * init my bretheren. I am not in the tree, so I don't get called twice :)
- */
-
- super.init(context, node );
-
- /*
* did we get an argument?
*/
-
+
if ( node.jjtGetChild(0) == null)
{
Runtime.error( new String("#parse() error : null argument") );
- return;
+ return false;
}
-
+
/*
* does it have a value? If you have a null reference, then no.
*/
@@ -138,7 +135,7 @@
if ( value == null)
{
Runtime.error( new String("#parse() error : null argument") );
- return ;
+ return false;
}
/*
@@ -146,21 +143,16 @@
*/
String strArg = value.toString();
-
+
/*
- * everything must be under the template root TEMPLATE_PATH
- */
-
- //String strTemplatePath = Runtime.getString(Runtime.TEMPLATE_PATH);
-
- /*
* for security, we will not accept anything with .. in the path
*/
if ( strArg.indexOf("..") != -1)
{
- Runtime.error( new String("#parse() error : argument " + strArg + " contains .. and may be trying to access content outside of template root. Rejected.") );
- return;
+ Runtime.error( new String("#parse() error : argument "
+ + strArg + " contains .. and may be trying to access content outside of template root. Rejected.") );
+ return false;
}
/*
@@ -174,43 +166,46 @@
* we will put caching here in the future...
*/
- Template t = Runtime.getTemplate(strArg);
-
- if (t != null)
+ Template t = null;
+
+ try
+ {
+ t = Runtime.getTemplate(strArg);
+ }
+ catch ( Exception e)
{
- try
- {
- nodeTree_ = t.getDocument();
-
- ParseDirectiveVisitor v = new ParseDirectiveVisitor();
- v.setDepth( iParseDepth_ );
- v.setContext( null );
- v.setWriter( null );
- nodeTree_.jjtAccept( v, null );
- nodeTree_.init( context, null );
- }
- catch ( ParseDirectiveException pde )
- {
- pde.addFile( strArg );
- throw pde;
- }
+ Runtime.error("#parse : cannot find " + strArg + " template!");
}
- else
- throw new Exception("#parse : cannot find " + strArg + " template!");
+
+ if ( t == null )
+ return false;
- bReady_ = true;
- }
+ try
+ {
+ nodeTree_ = t.getDocument();
+
+ ParseDirectiveVisitor v = new ParseDirectiveVisitor();
+ v.setDepth( iParseDepth_ );
+ v.setContext( null );
+ v.setWriter( null );
+ nodeTree_.jjtAccept( v, null );
+ nodeTree_.init( context, null );
+
+ bReady_ = true;
+ }
+ catch ( ParseDirectiveException pde )
+ {
+ pde.addFile( strArg );
+ Runtime.error( "Parse.render() : " + pde );
+ }
+ catch ( Exception e )
+ {
+ Runtime.error( "Parse.render() : " + e );
+ }
- /**
- * iterates through the argument list and renders every
- * argument that is appropriate. Any non appropriate
- * arguments are logged, but render() continues.
- */
- public boolean render(Context context, Writer writer, Node node)
- throws IOException
- {
if (bReady_)
nodeTree_.render(context, writer);
+
return true;
}