@Override public SimpleNode parse(Reader reader, String templateName, boolean dumpNamespace) throws ParseException { SimpleNode node = super.parse(reader, templateName, dumpNamespace); if (interpolationHack) { node = traversNode(node); } return node; }
@Override public synchronized void init() { super.init(); interpolationHack = getConfiguration().getBoolean(INTERPOLATION_HACK_KEY, INTERPOLATION_HACK_DEFAULT); }
@Inject public VelocityViewFactory(Argo argo) { String viewFolder = viewFolderPath(argo); Properties ps = new Properties(); ps.setProperty("resource.loader", "file"); ps.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); ps.setProperty("file.resource.loader.path", viewFolder); ps.setProperty("file.resource.loader.cache", "false"); ps.setProperty("file.resource.loader.modificationCheckInterval", "2"); ps.setProperty("input.encoding", "UTF-8"); ps.setProperty("output.encoding", "UTF-8"); ps.setProperty("default.contentType", "text/html; charset=UTF-8"); ps.setProperty("velocimarco.library.autoreload", "true"); ps.setProperty("runtime.log.error.stacktrace", "false"); ps.setProperty("runtime.log.warn.stacktrace", "false"); ps.setProperty("runtime.log.info.stacktrace", "false"); ps.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.SimpleLog4JLogSystem"); ps.setProperty("runtime.log.logsystem.log4j.category", "velocity_log"); rtInstance = new RuntimeInstance(); try { rtInstance.init(ps); } catch (Exception e) { throw ArgoException.raise(e); } }
private void execute0() throws IOException, MojoExecutionException { velocity = new RuntimeInstance(); final ExtProperties p = new ExtProperties(); velocity.setConfiguration(p);
public VelocitySQLTemplateProcessor() { this.renderingUtils = new SQLTemplateRenderingUtils(); this.velocityRuntime = new RuntimeInstance(); // set null logger velocityRuntime.addProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new NullLogChute()); velocityRuntime .addProperty(RuntimeConstants.RESOURCE_MANAGER_CLASS, SQLTemplateResourceManager.class.getName()); velocityRuntime.addProperty("userdirective", BindDirective.class.getName()); velocityRuntime.addProperty("userdirective", BindEqualDirective.class.getName()); velocityRuntime.addProperty("userdirective", BindNotEqualDirective.class.getName()); velocityRuntime.addProperty("userdirective", BindObjectEqualDirective.class.getName()); velocityRuntime.addProperty("userdirective", BindObjectNotEqualDirective.class.getName()); velocityRuntime.addProperty("userdirective", ResultDirective.class.getName()); velocityRuntime.addProperty("userdirective", ChainDirective.class.getName()); velocityRuntime.addProperty("userdirective", ChunkDirective.class.getName()); try { velocityRuntime.init(); } catch (Exception ex) { throw new CayenneRuntimeException("Error setting up Velocity RuntimeInstance.", ex); } }
RuntimeInstance runtimeInstance = new RuntimeInstance(); runtimeInstance.init(); SimpleNode simpleNode = runtimeInstance.parse(reader, "nameOfYourTemplateResource"); Template template = new Template(); simpleNode.init(new InternalContextAdapterImpl(new VelocityContext()), runtimeInstance); template.setData(simpleNode); template.merge(...); ...
RuntimeInstance ri = new RuntimeInstance(); SimpleNode node = ri.parse( reader, "templateName" );
/** * Initialize the Velocity Runtime with a Properties * object. * * @param p Velocity properties for initialization */ public void init(Properties p) { setConfiguration(ExtProperties.convertProperties(p)); init(); }
/** * Add a Velocity Runtime property. * * @param key * @param value */ public void addProperty(String key, Object value) { ri.addProperty(key, value); }
Template getTemplate(String viewName) { return rtInstance.getTemplate(viewName + suffix); }
/** * Apply velocity to the input. */ private String filterVelocity(TemplateFile f, String template, TemplateOptions options) { final VelocityContext ctx = new VelocityContext(); ctx.put("TemplateOptions", options); ctx.put("true", true); ctx.put("templateOnly", false); ctx.put("false", false); StringWriter sw = new StringWriter(); velocity.evaluate(ctx, sw, f.getFileName(), template); return sw.toString(); }
getLog().error(msg); throw new NullPointerException(msg); if (!isVelocimacro(vmName, logTag)) getLog().error(msg); throw new VelocityException(msg); return evaluate(context, writer, logTag, template.toString());
/** * Directly set the ExtProperties configuration object * * @see RuntimeInstance#setConfiguration(ExtProperties) */ public static void setConfiguration(ExtProperties configuration) { ri.setConfiguration(configuration); }
/** * Returns the result of substituting the variables defined by the fields of this class * (a concrete subclass of TemplateVars) into the template returned by {@link #parsedTemplate()}. */ String toText() { VelocityContext velocityContext = toVelocityContext(); StringWriter writer = new StringWriter(); SimpleNode parsedTemplate = parsedTemplate(); boolean rendered = velocityRuntimeInstance.render( velocityContext, writer, parsedTemplate.getTemplateName(), parsedTemplate); if (!rendered) { // I don't know when this happens. Usually you get an exception during rendering. throw new IllegalArgumentException("Template rendering failed"); } return writer.toString(); }
private RuntimeInstance ri = new RuntimeInstance(); encoding = ri.getString(INPUT_ENCODING,ENCODING_DEFAULT); br = new BufferedReader( new InputStreamReader( instream, encoding));
/** * Returns a <code>Template</code> from the resource manager. * This method assumes that the character encoding of the * template is set by the <code>input.encoding</code> * property. The default is "ISO-8859-1" * * @param name The file name of the desired template. * @return The 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 if an error occurs in template initialization */ public Template getTemplate(String name) throws ResourceNotFoundException, ParseErrorException, Exception { return getTemplate( name, getString( INPUT_ENCODING, ENCODING_DEFAULT) ); }
/** * Returns a <code>Template</code> from the resource manager. * This method assumes that the character encoding of the * template is set by the <code>input.encoding</code> * property. The default is "ISO-8859-1" * * @param name The file name of the desired template. * @return The template. * @throws ResourceNotFoundException if template not found * from any available source. * @throws ParseErrorException if template cannot be parsed due * to syntax (or other) error. */ public Template getTemplate(String name) throws ResourceNotFoundException, ParseErrorException { return getTemplate(name, getDefaultEncoding()); }
if (!isVelocimacro(vmName, null)) return evaluate(context, writer, logTag, template.toString());
private static void initVelocityRuntime() { // init static velocity engine sharedRuntime = new RuntimeInstance(); // set null logger sharedRuntime.addProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new NullLogSystem()); sharedRuntime.addProperty( RuntimeConstants.RESOURCE_MANAGER_CLASS, SQLTemplateResourceManager.class.getName()); sharedRuntime.addProperty("userdirective", BindDirective.class.getName()); sharedRuntime.addProperty("userdirective", BindEqualDirective.class.getName()); sharedRuntime.addProperty("userdirective", BindNotEqualDirective.class.getName()); sharedRuntime.addProperty("userdirective", ResultDirective.class.getName()); sharedRuntime.addProperty("userdirective", ChainDirective.class.getName()); sharedRuntime.addProperty("userdirective", ChunkDirective.class.getName()); try { sharedRuntime.init(); } catch (Exception ex) { throw new CayenneRuntimeException( "Error setting up Velocity RuntimeInstance.", ex); } }