当前位置: 首页>>代码示例>>Java>>正文


Java TemplateCompiler类代码示例

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


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


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