org.mvel2.templates.TemplateCompiler Java Examples
The following examples show how to use
org.mvel2.templates.TemplateCompiler.
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: JavaRuleBuilderHelper.java From kogito-runtimes with Apache License 2.0 | 7 votes |
public static synchronized TemplateRegistry getInvokerTemplateRegistry(ClassLoader cl) { if ( !INVOKER_REGISTRY.contains( "invokers" ) ) { InputStream javaInvokersMvelStream = JavaRuleBuilderHelper.class.getResourceAsStream( JAVA_INVOKERS_MVEL ); INVOKER_REGISTRY.addNamedTemplate( "invokers", TemplateCompiler.compileTemplate( javaInvokersMvelStream ) ); try { javaInvokersMvelStream.close(); } catch ( IOException ex ) { logger.debug( "Failed to close stream!", ex ); } TemplateRuntime.execute( INVOKER_REGISTRY.getNamedTemplate( "invokers" ), null, INVOKER_REGISTRY ); } return INVOKER_REGISTRY; }
Example #2
Source File: JavaRuleBuilderHelper.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public static synchronized TemplateRegistry getRuleTemplateRegistry(ClassLoader cl) { if ( !RULE_REGISTRY.contains( "rules" ) ) { InputStream javaRuleMvelStream = JavaRuleBuilderHelper.class.getResourceAsStream( JAVA_RULE_MVEL ); RULE_REGISTRY.addNamedTemplate( "rules", TemplateCompiler.compileTemplate( javaRuleMvelStream ) ); try { javaRuleMvelStream.close(); } catch ( IOException ex ) { logger.debug( "Failed to close stream!", ex ); } TemplateRuntime.execute( RULE_REGISTRY.getNamedTemplate( "rules" ), null, RULE_REGISTRY ); } return RULE_REGISTRY; }
Example #3
Source File: DrlDumper.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public DrlDumper() { REPORT_REGISTRY.addNamedTemplate( "drl", TemplateCompiler.compileTemplate( DrlDumper.class.getResourceAsStream( "drl.mvel" ), (Map<String, Class< ? extends Node>>) null ) ); /** * Process these templates */ TemplateRuntime.execute( REPORT_REGISTRY.getNamedTemplate( "drl" ), null, REPORT_REGISTRY ); }
Example #4
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 #5
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 #6
Source File: SessionReporter.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public static void addNamedTemplate(String name, InputStream template) { REPORT_REGISTRY.addNamedTemplate( name, TemplateCompiler.compileTemplate( template, (Map<String, Class<? extends Node>>) null ) ); /* * Process these templates */ TemplateRuntime.execute( REPORT_REGISTRY.getNamedTemplate( name ), null, REPORT_REGISTRY ); }
Example #7
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 #8
Source File: PayloadExpressionEvaluator.java From chancery with Apache License 2.0 | 5 votes |
PayloadExpressionEvaluator(@Nonnull String template) { if (template == null) { System.err.println("wuuut"); } final ParserContext parserContext = new ParserContext(); parserContext.addImport("iso", ISODateTimeFormat.class); parserContext.addImport("dtf", DateTimeFormat.class); compiledTemplate = TemplateCompiler.compileTemplate(template, parserContext); }
Example #9
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()); } }