org.mvel2.templates.CompiledTemplate Java Examples
The following examples show how to use
org.mvel2.templates.CompiledTemplate.
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: AccumulateTemplateTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private TemplateRegistry getRuleTemplateRegistry() { TemplateRegistry ruleRegistry = new SimpleTemplateRegistry(); CompiledTemplate compiled = TemplateCompiler.compileTemplate( JavaRuleBuilderHelper.class.getResourceAsStream( "javaRule.mvel" ), (Map<String, Class<? extends Node>>) null ); TemplateRuntime.execute( compiled, null, ruleRegistry ); return ruleRegistry; }
Example #2
Source File: AccumulateTemplateTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private TemplateRegistry getInvokerTemplateRegistry() { TemplateRegistry invokerRegistry = new SimpleTemplateRegistry(); CompiledTemplate compiled = TemplateCompiler.compileTemplate( JavaRuleBuilderHelper.class.getResourceAsStream( "javaInvokers.mvel" ), (Map<String, Class<? extends Node>>) null ); TemplateRuntime.execute( compiled, null, invokerRegistry ); return invokerRegistry; }
Example #3
Source File: MvelTemplateEngine.java From spark-template-engines with Apache License 2.0 | 5 votes |
public CompiledTemplate loadTemplate(String resourceName) { final String fullPath = prefix + resourceName; CompiledTemplate compiledTemplate = templateCache.get(fullPath); if (compiledTemplate == null) { // use the Stupid scanner trick in order not to rely on external libs // https://community.oracle.com/blogs/pat/2004/10/23/stupid-scanner-tricks compiledTemplate = TemplateCompiler .compileTemplate(Thread.currentThread().getContextClassLoader().getResourceAsStream(fullPath)); templateCache.putIfAbsent(fullPath, compiledTemplate); } return compiledTemplate; }
Example #4
Source File: PolicyTemplateUtil.java From apiman with Apache License 2.0 | 5 votes |
/** * Generates a dynamic description for the given policy and stores the * result on the policy bean instance. This should be done prior * to returning the policybean back to the user for a REST call to the * management API. * @param policy the policy * @throws Exception any exception */ public static void generatePolicyDescription(PolicyBean policy) throws Exception { PolicyDefinitionBean def = policy.getDefinition(); PolicyDefinitionTemplateBean templateBean = getTemplateBean(def); if (templateBean == null) { return; } String cacheKey = def.getId() + "::" + templateBean.getLanguage(); //$NON-NLS-1$ CompiledTemplate template = templateCache.get(cacheKey); if (template == null) { template = TemplateCompiler.compileTemplate(templateBean.getTemplate()); templateCache.put(cacheKey, template); } try { // TODO hack to fix broken descriptions - this util should probably not know about encrypted data String jsonConfig = policy.getConfiguration(); if (CurrentDataEncrypter.instance != null) { EntityType entityType = EntityType.Api; if (policy.getType() == PolicyType.Client) { entityType = EntityType.ClientApp; } else if (policy.getType() == PolicyType.Plan) { entityType = EntityType.Plan; } DataEncryptionContext ctx = new DataEncryptionContext(policy.getOrganizationId(), policy.getEntityId(), policy.getEntityVersion(), entityType); jsonConfig = CurrentDataEncrypter.instance.decrypt(jsonConfig, ctx); } Map<String, Object> configMap = mapper.readValue(jsonConfig, Map.class); configMap = new PolicyConfigMap(configMap); String desc = (String) TemplateRuntime.execute(template, configMap); policy.setDescription(desc); } catch (Exception e) { e.printStackTrace(); // TODO properly log the error policy.setDescription(templateBean.getTemplate()); } }
Example #5
Source File: MvelTemplateEngine.java From spark-template-engines with Apache License 2.0 | 4 votes |
@Override public String render(final ModelAndView modelAndView) { final CompiledTemplate compiledTemplate = loadTemplate(modelAndView.getViewName()); return (String) TemplateRuntime.execute(compiledTemplate, modelAndView.getModel()); }