Java Code Examples for org.apache.velocity.runtime.RuntimeSingleton#getRuntimeServices()
The following examples show how to use
org.apache.velocity.runtime.RuntimeSingleton#getRuntimeServices() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomVelocityResponseTransformer.java From AuTe-Framework with Apache License 2.0 | 6 votes |
private String getRenderedBodyFromFile(final ResponseDefinition response) throws ParseException { RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices(); StringReader reader = new StringReader(response.getBody()); SimpleNode node = runtimeServices.parse(reader, "Template name"); Template template = new Template(); template.setEncoding("UTF-8"); template.setRuntimeServices(runtimeServices); template.setData(node); template.initDocument(); StringWriter writer = new StringWriter(); template.merge(context, writer); return String.valueOf(writer.getBuffer()); }
Example 2
Source File: OTPService.java From sunbird-lms-service with MIT License | 6 votes |
public static String getSmsBody(String templateFile, Map<String, String> smsTemplate) { try { String sms = getOTPSMSTemplate(templateFile); RuntimeServices rs = RuntimeSingleton.getRuntimeServices(); SimpleNode sn = rs.parse(sms, "Sms Information"); Template t = new Template(); t.setRuntimeServices(rs); t.setData(sn); t.initDocument(); VelocityContext context = new VelocityContext(); context.put(JsonKey.OTP, smsTemplate.get(JsonKey.OTP)); context.put( JsonKey.OTP_EXPIRATION_IN_MINUTES, smsTemplate.get(JsonKey.OTP_EXPIRATION_IN_MINUTES)); context.put( JsonKey.INSTALLATION_NAME, ProjectUtil.getConfigValue(JsonKey.SUNBIRD_INSTALLATION_DISPLAY_NAME)); StringWriter writer = new StringWriter(); t.merge(context, writer); return writer.toString(); } catch (Exception ex) { ProjectLogger.log( "OTPService:getSmsBody: Exception occurred with error message = " + ex.getMessage(), ex); } return ""; }
Example 3
Source File: VelocityTemplateEngine.java From pippo with Apache License 2.0 | 6 votes |
@Override public void renderString(String templateContent, Map<String, Object> model, Writer writer) { // create the velocity context VelocityContext context = createVelocityContext(model); // merge the template try { RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices(); StringReader reader = new StringReader(templateContent); SimpleNode node = runtimeServices.parse(reader, "StringTemplate"); Template template = new Template(); template.setRuntimeServices(runtimeServices); template.setData(node); template.initDocument(); template.merge(context, writer); } catch (Exception e) { throw new PippoRuntimeException(e); } }
Example 4
Source File: VelocityTransformer.java From AuTe-Framework with Apache License 2.0 | 5 votes |
private String render(final String stringTemplate) throws ParseException { RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices(); runtimeServices.setProperty("userdirective", GroovyDirective.class.getName()); StringReader reader = new StringReader(stringTemplate); SimpleNode node = runtimeServices.parse(reader, "Template name"); Template template = new Template(); template.setEncoding("UTF-8"); template.setRuntimeServices(runtimeServices); template.setData(node); template.initDocument(); StringWriter writer = new StringWriter(); template.merge(velocityContext, writer); return String.valueOf(writer.getBuffer()); }
Example 5
Source File: VelocityUtils.java From iotplatform with Apache License 2.0 | 5 votes |
public static Template create(String source, String templateName) throws ParseException { RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices(); StringReader reader = new StringReader(source); SimpleNode node = runtimeServices.parse(reader, templateName); Template template = new Template(); template.setRuntimeServices(runtimeServices); template.setData(node); template.initDocument(); return template; }
Example 6
Source File: VelocitySqlSource.java From mybaties with Apache License 2.0 | 5 votes |
public VelocitySqlSource(Configuration configuration, String scriptText) { this.configuration = configuration; try { RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices(); StringReader reader = new StringReader(scriptText); SimpleNode node = runtimeServices.parse(reader, "Template name"); script = new Template(); script.setRuntimeServices(runtimeServices); script.setData(node); script.initDocument(); } catch (Exception ex) { throw new BuilderException("Error parsing velocity script", ex); } }
Example 7
Source File: VelocitySqlSource.java From mybatis with Apache License 2.0 | 5 votes |
public VelocitySqlSource(Configuration configuration, String scriptText) { this.configuration = configuration; try { RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices(); StringReader reader = new StringReader(scriptText); SimpleNode node = runtimeServices.parse(reader, "Template name"); script = new Template(); script.setRuntimeServices(runtimeServices); script.setData(node); script.initDocument(); } catch (Exception ex) { throw new BuilderException("Error parsing velocity script", ex); } }