• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TemplateCompiler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.mvel2.templates.TemplateCompiler的典型用法代码示例。如果您正苦于以下问题:Java TemplateCompiler类的具体用法?Java TemplateCompiler怎么用?Java TemplateCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TemplateCompiler类属于org.mvel2.templates包,在下文中一共展示了TemplateCompiler类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: parseTemplate

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
public Object parseTemplate(
		String template, 
		Object context, 
		Map<String, Object> variables,
		FormatterHelper formatter) {
	
	defineFormatter(variables, formatter);
	if (templateCompiledCache != null) {
		
		CompiledTemplate compiledTemplate = templateCompiledCache.get(template);
		if (compiledTemplate == null) {
			compiledTemplate = TemplateCompiler.compileTemplate(template);
			templateCompiledCache.put(template, compiledTemplate);
		}
		return TemplateRuntime.execute(compiledTemplate, context, variables); 
		
	} else {
		return TemplateRuntime.eval(template, context, variables);
	}
	
}
 
开发者ID:utluiz,项目名称:t-rex,代码行数:22,代码来源:MVEL2Interpreter.java


示例2: loadCompiled

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
/**
 * Load a template given its {@code source}.
 *
 * @param source the template source
 * @return the compiled template
 */
public static CompiledTemplate loadCompiled(InputStream source) {
  // Load the template
  String template;
  try (Scanner scanner = new Scanner(source, "UTF-8").useDelimiter("\\A")) {
    template = scanner.next();
  }
  // MVEL preserves all whitespace therefore, so we can have readable templates we remove all line breaks
  // and replace all occurrences of "\n" with a line break
  // "\n" signifies we want an actual line break in the output
  // We use actual tab characters in the template so we can see indentation, but we strip these out
  // before parsing.
  // So use tabs for indentation that YOU want to see in the template but won't be in the final output
  // And use spaces for indentation that WILL be in the final output
  template = template.replace("\n", "").replace("\r", "").replace("\\n", System.getProperty("line.separator")).replace("\t", "");

  // Be sure to have mvel classloader as parent during evaluation as it will need mvel classes
  // when generating code
  ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
  Thread.currentThread().setContextClassLoader(TemplateRuntime.class.getClassLoader());
  try {
    return TemplateCompiler.compileTemplate(template);
  } finally {
    Thread.currentThread().setContextClassLoader(currentCL);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-codegen,代码行数:32,代码来源:Template.java


示例3: compileTemplate

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
/**
 * Interprets the supplied {@code template} as the source code of a
 * template and compiles it into an implementation-specific
 * representation that can subsequently be executed efficiently.
 *
 * <p>This method may return {@code null}.</p>
 *
 * @param template the source code of the template to be compiled;
 * may be {@code null} in which case {@code null} will be returned
 *
 * @return an {@link Object} representing the compilation of the
 * source code, or {@code null}
 *
 * @exception IllegalStateException if there was a problem compiling
 * the template
 */
protected Object compileTemplate(final String template) {
  final Object returnValue;
  if (template == null) {
    returnValue = null;
  } else {
    Object temp = null;
    try {
      temp = TemplateCompiler.compileTemplate(template);
    } catch (final CompileException wrapMe) {
      throw new IllegalStateException(wrapMe);
    } finally {
      returnValue = temp;
    }
  }
  return returnValue;
}
 
开发者ID:ljnelson,项目名称:nomen,代码行数:33,代码来源:Name.java


示例4: getContent

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
@Override
public String getContent() {
    String template = TemplateRepo.INSTANCE.getTemplate("functionNode");
    CompiledTemplate compiled = TemplateCompiler.compileTemplate(template);
    Map<String, Object> vars = new HashMap<>();
    vars.put("title", getTitle());
    vars.put("descriptionNode", getDescriptionNode());
    vars.put("codeNode", getCodeWrapperNode());
    return TemplateRuntime.execute(compiled, vars).toString();

}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:12,代码来源:FunctionNode.java


示例5: getContent

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
@Override
public String getContent() {
    String template = TemplateRepo.INSTANCE.getTemplate("apiNode");
    CompiledTemplate compiled = TemplateCompiler.compileTemplate(template);
    Map<String, Object> vars = new HashMap<>();
    vars.put("title", getTitle());
    vars.put("descriptionNode", getDescriptionNode());
    vars.put("codeNode", getCodeWrapperNode());
    vars.put("functionNodes", functions);
    return StringUtils.trim(TemplateRuntime.execute(compiled, vars).toString());
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:12,代码来源:ApiNode.java


示例6: getContent

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
@Override
public String getContent() {
    String template = TemplateRepo.INSTANCE.getTemplate("indexNode");
    CompiledTemplate compiled = TemplateCompiler.compileTemplate(template);
    Map<String, Object> vars = new HashMap<>();
    vars.put("title", getTitle());
    vars.put("languages", languages);
    vars.put("tocFooters", tocFooters);
    vars.put("includeFiles", createIncludeFilesList());
    vars.put("isSearchable", isSearchable);
    return StringUtils.trim(TemplateRuntime.execute(compiled, vars).toString());
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:13,代码来源:IndexNode.java


示例7: getContent

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
@Override
public String getContent() {
    String template = TemplateRepo.INSTANCE.getTemplate("tableNode");
    CompiledTemplate compiled = TemplateCompiler.compileTemplate(template);
    Map<String, Object> vars = new HashMap<>();
    vars.put("header", tableHeaderNode);
    vars.put("separator", new TableSeparatorNode(tableHeaderNode));
    vars.put("rows", rows);
    return TemplateRuntime.execute(compiled, vars).toString();

}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:12,代码来源:TableNode.java


示例8: readFile

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
private String readFile(String fileName, Object ctx, VariableResolverFactory factory) {
    File file = getFile(fileName);
    if (fileDateStamp == 0 || fileDateStamp != file.lastModified()) {
        fileDateStamp = file.lastModified();
        cFileCache = TemplateCompiler.compileTemplate(readInFile(file));
    }
    return String.valueOf(TemplateRuntime.execute(cFileCache, ctx, factory));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:9,代码来源:CompiledIncludeNode.java


示例9: testPluginNode

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
public void testPluginNode() {
    Map<String, Class<? extends Node>> plugins = new HashMap<String, Class<? extends Node>>();
    plugins.put("testNode", TestPluginNode.class);

    TemplateCompiler compiler = new TemplateCompiler("Foo:@testNode{}!!", plugins);
    CompiledTemplate compiled = compiler.compile();

    assertEquals("Foo:THIS_IS_A_TEST!!", TemplateRuntime.execute(compiled));
}
 
开发者ID:codehaus,项目名称:mvel,代码行数:10,代码来源:TemplateTests.java


示例10: loadTemplate

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
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;
}
 
开发者ID:perwendel,项目名称:spark-template-engines,代码行数:13,代码来源:MvelTemplateEngine.java


示例11: generate

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
public void generate() {
    try {
        Map<String, Object> vars = new HashMap<String, Object>();
        
        ParserContext context = new ParserContext();
        CompiledTemplate templ = TemplateCompiler.compileTemplate(getClass().getResourceAsStream("/sequenceDiag.mvel"), context);
        FileOutputStream out = new FileOutputStream("target/" + title + ".svg");
        TemplateRuntime.execute(templ, this, vars, out);
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:bckfnn,项目名称:react-streams,代码行数:14,代码来源:Diagram.java


示例12: readFile

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
private String readFile(TemplateRuntime runtime, String fileName, Object ctx, VariableResolverFactory factory) {
  File file = new File(String.valueOf(runtime.getRelPath().peek()) + "/" + fileName);
  if (fileDateStamp == 0 || fileDateStamp != file.lastModified()) {
    fileDateStamp = file.lastModified();
    cFileCache = TemplateCompiler.compileTemplate(readInFile(runtime, file), context);
  }
  return String.valueOf(TemplateRuntime.execute(cFileCache, ctx, factory));
}
 
开发者ID:osswangxining,项目名称:mvel-jsr223,代码行数:9,代码来源:CompiledIncludeNode.java


示例13: render

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
@Override
public void render(RoutingContext context, String templateDirectory, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
  try {
    templateFileName = templateDirectory + templateFileName;
    CompiledTemplate template = isCachingEnabled() ? cache.get(templateFileName) : null;
    if (template == null) {
      // real compile
      String loc = adjustLocation(templateFileName);
      String templateText = Utils.readFileToString(context.vertx(), loc);
      if (templateText == null) {
        throw new IllegalArgumentException("Cannot find template " + loc);
      }
      template = TemplateCompiler.compileTemplate(templateText);
      if (isCachingEnabled()) {
        cache.put(templateFileName, template);
      }
    }
    Map<String, RoutingContext> variables = new HashMap<>(1);
    variables.put("context", context);
    final VertxInternal vertxInternal = (VertxInternal) context.vertx();
    String directoryName = vertxInternal.resolveFile(templateFileName).getParent();
    handler.handle(Future.succeededFuture(
      Buffer.buffer(
        (String) new TemplateRuntime(template.getTemplate(), null, template.getRoot(), directoryName)
          .execute(new StringAppender(), variables, new ImmutableDefaultFactory())
      )
    ));
  } catch (Exception ex) {
    handler.handle(Future.failedFuture(ex));
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:32,代码来源:MVELTemplateEngineImpl.java


示例14: before

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
@Before
public void before() throws Exception {
    tempReg.addNamedTemplate("tempReg", TemplateCompiler.compileTemplate(getClass().getResourceAsStream(dataformat + ".mvt"), (Map<String, Class<? extends Node>>)null));
    TemplateRuntime.execute(tempReg.getNamedTemplate("tempReg"), null, tempReg);

    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreAttributeOrder(true);
    XMLUnit.setNormalizeWhitespace(true);
    XMLUnit.setNormalize(true);

    if (!StringUtils.isEmpty(copyToDataFormat)) {
        writer = new PrintWriter(new BufferedWriter(new FileWriter(copyToDataFormat + ".mvt", true)));
    }
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:16,代码来源:BatchTest.java


示例15: PayloadExpressionEvaluator

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
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);
}
 
开发者ID:airbnb,项目名称:chancery,代码行数:10,代码来源:PayloadExpressionEvaluator.java


示例16: generatePolicyDescription

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:45,代码来源:PolicyTemplateUtil.java


示例17: onExchange

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
    String path = getResourceUri();
    ObjectHelper.notNull(path, "resourceUri");

    String newResourceUri = exchange.getIn().getHeader(MvelConstants.MVEL_RESOURCE_URI, String.class);
    if (newResourceUri != null) {
        exchange.getIn().removeHeader(MvelConstants.MVEL_RESOURCE_URI);

        log.debug("{} set to {} creating new endpoint to handle exchange", MvelConstants.MVEL_RESOURCE_URI, newResourceUri);
        MvelEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri);
        newEndpoint.onExchange(exchange);
        return;
    }

    CompiledTemplate compiled;
    ParserContext mvelContext = ParserContext.create();
    Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange);

    String content = exchange.getIn().getHeader(MvelConstants.MVEL_TEMPLATE, String.class);
    if (content != null) {
        // use content from header
        if (log.isDebugEnabled()) {
            log.debug("Mvel content read from header {} for endpoint {}", MvelConstants.MVEL_TEMPLATE, getEndpointUri());
        }
        // remove the header to avoid it being propagated in the routing
        exchange.getIn().removeHeader(MvelConstants.MVEL_TEMPLATE);
        compiled = TemplateCompiler.compileTemplate(content, mvelContext);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Mvel content read from resource {} with resourceUri: {} for endpoint {}", new Object[]{getResourceUri(), path, getEndpointUri()});
        }
        // getResourceAsInputStream also considers the content cache
        Reader reader = getEncoding() != null ? new InputStreamReader(getResourceAsInputStream(), getEncoding()) : new InputStreamReader(getResourceAsInputStream());
        String template = IOConverter.toString(reader);
        if (!template.equals(this.template)) {
            this.template = template;
            this.compiled = TemplateCompiler.compileTemplate(template, mvelContext);
        }
        compiled = this.compiled;
    }

    // let mvel parse and execute the template
    log.debug("Mvel is evaluating using mvel context: {}", variableMap);
    Object result = TemplateRuntime.execute(compiled, mvelContext, variableMap);

    // now lets output the results to the exchange
    Message out = exchange.getOut();
    out.setBody(result.toString());
    out.setHeaders(exchange.getIn().getHeaders());
    out.setAttachments(exchange.getIn().getAttachments());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:53,代码来源:MvelEndpoint.java


示例18: initialize

import org.mvel2.templates.TemplateCompiler; //导入依赖的package包/类
private void initialize() {
    TemplateCompiler compiler = new TemplateCompiler(this.getTemplate());
    compiledTemplate = compiler.compile();
}
 
开发者ID:jub77,项目名称:grafikon,代码行数:5,代码来源:TextTemplateMvel.java



注:本文中的org.mvel2.templates.TemplateCompiler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CommandException类代码示例发布时间:2022-05-21
下一篇:
Java User类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap