@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { Node escapeTypeNode = node.jjtGetChild(0); Object escapeTypeObject = escapeTypeNode.value(context); String escapeTypeString = escapeTypeObject == null ? null : escapeTypeObject.toString(); EscapeType escapeType = EscapeType.getEscapeType(escapeTypeString); if (escapeType == null) { throw new ParseErrorException("Invalid escape type: " + escapeTypeObject + " at " + new Info(escapeTypeNode.getTemplateName(), escapeTypeNode.getColumn(), escapeTypeNode.getLine()) + ". Available escape types: " + EscapeType.getNames()); } return renderWithEscape(escapeType, context, writer, node.jjtGetChild(1)); } }
private void writeFile(File file, String template, VelocityContext context) { String templatePath; if(config.getTemplateFolder() == null) { templatePath = template; } else { templatePath = config.getTemplateFolder()+ System.getProperty("file.separator") + template; } Writer writer = null; try { log.info("Writing " + file); Template velocityTemplate = engine.getTemplate(templatePath); writer = new FileWriter(file); velocityTemplate.merge(context, writer); } catch (IOException e) { log.error(e.getMessage(), e); } catch (ResourceNotFoundException e) { log.error(e.getMessage(), e); } catch (ParseErrorException e) { log.error(e.getMessage(), e); } catch (Exception e) { log.error(e.getMessage(), e); } finally { FileUtils.close(writer); } }
private Template getTemplate(String path) { Template template = (Template) templateMap.get(path); if (template == null) { try { template = engine.getTemplate(path, ENCODING); } catch (ResourceNotFoundException e) { e.printStackTrace(); } catch (ParseErrorException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } return template; } }
throw new ParseErrorException( pex.getMessage(), info ); throw new ParseErrorException( pex.getMessage(), info ); throw new ParseErrorException( pex.getMessage(), info ); throw new ParseErrorException( pex.getMessage(), info );
rnfe.printStackTrace(); } catch (ParseErrorException pee) { System.err.println(pee.getMessage()); pee.printStackTrace(); } catch (Exception e) { System.err.println(e.getMessage());
public String evaluate(Map<String, Object> context, TemplatePack templatePack, Template template) throws IOException { StringWriter sw = new StringWriter(); try { engine.evaluate(new VelocityContext(context), sw, template.getName(), template.getTemplate()); return sw.toString(); } catch (ParseErrorException parseException) { handleStopFileGeneration(parseException); log.error("In " + templatePack.getName() + ":" + template.getName() + " template, parse exception " + parseException.getMessage(), parseException.getCause()); displayLinesInError(parseException, templatePack, template); throw new IllegalStateException(); } catch (MethodInvocationException mie) { handleStopFileGeneration(mie); log.error("In " + templatePack.getName() + ":" + mie.getTemplateName() + " method [" + mie.getMethodName() + "] has not been set", mie.getCause()); displayLinesInError(mie, templatePack, template); throw mie; } finally { closeQuietly(sw); } }
logsevere("Velocity Parsing error in " + templateName + ": " + pe.getMessage() + "\n" + pe.getInvalidSyntax()); throw new ActivityException(-1, pe.getMessage(), pe);
throw new ParseErrorException( pex.getMessage(), info ); throw new ParseErrorException( pex.getMessage(), info ); throw new ParseErrorException( pex.getMessage(), info );
public String evaluate(Map<String, Object> context, TemplatePack templatePack, Template template) throws IOException { StringWriter sw = new StringWriter(); try { engine.evaluate(new VelocityContext(context), sw, template.getName(), template.getTemplate()); return sw.toString(); } catch (ParseErrorException parseException) { handleStopFileGeneration(parseException); log.error("In " + templatePack.getName() + ":" + template.getName() + " template, parse exception " + parseException.getMessage(), parseException.getCause()); displayLinesInError(parseException, templatePack, template); throw new IllegalStateException(); } catch (MethodInvocationException mie) { handleStopFileGeneration(mie); log.error("In " + templatePack.getName() + ":" + mie.getTemplateName() + " method [" + mie.getMethodName() + "] has not been set", mie.getCause()); displayLinesInError(mie, templatePack, template); throw mie; } finally { closeQuietly(sw); } }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { Node escapeTypeNode = node.jjtGetChild(0); Object escapeTypeObject = escapeTypeNode.value(context); String escapeTypeString = escapeTypeObject == null ? null : escapeTypeObject.toString(); EscapeType escapeType = EscapeType.getEscapeType(escapeTypeString); if (escapeType == null) { throw new ParseErrorException("Invalid escape type: " + escapeTypeObject + " at " + new Info(escapeTypeNode.getTemplateName(), escapeTypeNode.getColumn(), escapeTypeNode.getLine()) + ". Available escape types: " + EscapeType.getNames()); } return renderWithEscape(escapeType, context, writer, node.jjtGetChild(1)); } }
throw new ParseErrorException( pex.getMessage(), info ); throw new ParseErrorException( pex.getMessage(), info ); throw new ParseErrorException( pex.getMessage(), info ); throw new ParseErrorException( pex.getMessage(), info );
+ " template: " + e.getMessage(), e );
protected String merge(Template template, VelocityContext context) { if (template == null) { return ""; } StringWriter writer = new StringWriter(); try { template.merge(context, writer); } catch (ResourceNotFoundException e) { e.printStackTrace(); } catch (ParseErrorException e) { e.printStackTrace(); } catch (MethodInvocationException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } String ret = writer.toString(); writer.flush(); return ret; }
static String getRequiredArgument(InternalContextAdapter context,Node node,int argumentIndex,String directive) throws ParseErrorException { SimpleNode sn_value = (SimpleNode)node.jjtGetChild(argumentIndex); if ( sn_value == null){ throw new ParseErrorException("required argument is null with directive:#"+directive+"(),argumentIndex="+argumentIndex); } String value = (String)sn_value.value(context); if ( value == null){ throw new ParseErrorException("required argument is null with directive:#"+directive+"(),argumentIndex="+argumentIndex); } return value; }
+ " template: " + e.getMessage(), e );
public String CcdaToHtml(ArrayList<CCDAValidationReportItem> ccdaItem) { String res = ""; // first, get and initialize an engine try { VelocityEngine ve = VelocitySingleton.getVelocityEngine(); Template t2 = ve.getTemplate("CCDAValidationReport.vm"); VelocityContext context = new VelocityContext(); context.put("validationReport", ccdaItem); StringWriter writer = new StringWriter(); t2.merge( context, writer ); res = writer.toString(); } catch (ResourceNotFoundException e) { e.printStackTrace(); } catch (ParseErrorException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return res; }
@Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException,MethodInvocationException { OverrideNodeWrapper current = (OverrideNodeWrapper)context.get(Utils.OVERRIDE_CURRENT_NODE); if(current == null) { throw new ParseErrorException("#super direction must be child of override"); } OverrideNodeWrapper parent = current.parentNode; if(parent == null) { throw new ParseErrorException("not found parent block for #super "); } return parent.render(context,writer); }
+ " template: " + e.getMessage(), e );
public String XdmToHtml(ArrayList<XDMValidationReportItem> xdmItem) { String res = ""; // first, get and initialize an engine try { VelocityEngine ve = VelocitySingleton.getVelocityEngine(); Template t2 = ve.getTemplate("XDMValidationReport.vm"); VelocityContext context = new VelocityContext(); context.put("validationReport", xdmItem); StringWriter writer = new StringWriter(); t2.merge( context, writer ); res = writer.toString(); } catch (ResourceNotFoundException e) { e.printStackTrace(); } catch (ParseErrorException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return res; }
/** * adds a given Node's key/value pair to the propertyMap. For example, if this Node contained the value "rows=20", * then the key, rows, would be added to the propertyMap with the String value, 20. * * @param propertyMap a params containing all the properties that we wish to set * @param node the parameter to set expressed in "name=value" format */ protected void putProperty(Map propertyMap, InternalContextAdapter contextAdapter, Node node) throws ParseErrorException, MethodInvocationException { // node.value uses the WebWorkValueStack to evaluate the directive's value parameter String param = node.value(contextAdapter).toString(); int idx = param.indexOf("="); if (idx != -1) { String property = param.substring(0, idx); String value = param.substring(idx + 1); propertyMap.put(property, value); } else { throw new ParseErrorException("#" + this.getName() + " arguments must include an assignment operator! For example #tag( Component \"template=mytemplate\" ). #tag( TextField \"mytemplate\" ) is illegal!"); } } }