public void dump(String prefix) { System.out.println(toString(prefix)); if (children != null) { for (int i = 0; i < children.length; ++i) { SimpleNode n = (SimpleNode) children[i]; if (n != null) { n.dump(prefix + " "); } } } }
/** * initializes the document. init() is not longer dependant upon context, but we need to let the * init() carry the template name down throught for VM namespace features */ public void initDocument() throws Exception { /* * send an empty InternalContextAdapter down into the AST to initialize it */ InternalContextAdapterImpl ica = new InternalContextAdapterImpl(new VelocityContext()); try { /* * put the current template name on the stack */ ica.pushCurrentTemplateName(name); /* * init the AST */ ((SimpleNode) data).init(ica, rsvc); } finally { /* * in case something blows up... * pull it off for completeness */ ica.popCurrentTemplateName(); } }
/** * The AST node structure is merged with the context to produce the final output. * * <p>Throws IOException if failure is due to a file related issue, and Exception otherwise * * @param context Conext with data elements accessed by template * @param writer output writer for rendered template * @throws ResourceNotFoundException if template not found from any available source. * @throws ParseErrorException if template cannot be parsed due to syntax (or other) error. * @throws Exception anything else. */ public void merge(Context context, Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception { /* * we shouldn't have to do this, as if there is an error condition, * the application code should never get a reference to the * Template */ if (errorCondition != null) { throw errorCondition; } if (data != null) { /* * create an InternalContextAdapter to carry the user Context down * into the rendering engine. Set the template name and render() */ InternalContextAdapterImpl ica = new InternalContextAdapterImpl(context); try { ica.pushCurrentTemplateName(name); ica.setCurrentResource(this); ((SimpleNode) data).render(ica, writer); } finally { /* * lets make sure that we always clean up the context */ ica.popCurrentTemplateName(); ica.setCurrentResource(null); } } else { /* * this shouldn't happen either, but just in case. */ String msg = "Template.merge() failure. The document is null, " + "most likely due to parsing error."; rsvc.error(msg); throw new Exception(msg); } }