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


Java TemplateCompiler.compileTemplate方法代码示例

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


在下文中一共展示了TemplateCompiler.compileTemplate方法的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: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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