Hi all, 
I'm going to writing some directives to extend Velocity.  now I'm in lacking
of documents. 
I've read the PPT 《Hacking Velocity》by Will Glass-Husain, and some souce
code of system directive such as "literal", "execute", but I don't
understand "foreach" till now. 
I've written the following code(Mydd.java) and it can work as coded now:
-------------------file begin ------------------------------
import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;

import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.directive.Directive;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.parser.node.Node;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.log4j.Logger;

public class Mydd extends Directive {

        private static Logger logger = Logger.getLogger(Mydd.class);
        
    public void init(RuntimeServices rs, InternalContextAdapter context,
Node node)
        throws TemplateInitException
    {
        super.init(rs, context, node);

    }
        @Override
        public String getName() {
                return "mydd";
        }

        @Override
        public int getType() {

                return LINE;
        }

    public boolean render(InternalContextAdapter context,
                           Writer writer, Node node) throws IOException
    {
        for (int i = 0; i < node.jjtGetNumChildren(); i ++) {
                logger.debug("debug mydd parameter: " + node.jjtGetChild(i).
toString() + " (" + node.jjtGetChild(i).literal() + ")");
        }
        writer.write("Hello, world!");
        return true;
    }
}
-------------------file end ----------------------------------

What I want to know is:
1, the above directive's syntax in template is 
#mydd(arg1 arg2 arg3 ...)
but system directives like "foreach" and "set" have COOL syntax like
"#foreach ($a in $set)", how to let my directive support syntax like this?
2, does the directive mechanism provided Velocity has other convenience or
power that I don't know ? what I know about  is all in the above code :-)

Thanks in advance, any hint will be appreciated!


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to