org.apache.velocity.app.Velocity.evaluate()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(187)

本文整理了Java中org.apache.velocity.app.Velocity.evaluate()方法的一些代码示例,展示了Velocity.evaluate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Velocity.evaluate()方法的具体详情如下:
包路径:org.apache.velocity.app.Velocity
类名称:Velocity
方法名:evaluate

Velocity.evaluate介绍

[英]Renders the input stream using the context into the output writer. To be used when a template is dynamically constructed, or want to use Velocity as a token replacer.
[中]使用上下文将输入流呈现到输出编写器中。在动态构造模板时使用,或希望使用Velocity作为令牌替换程序时使用。

代码示例

代码示例来源:origin: looly/hutool

/**
 * 融合模板和内容
 * 
 * @param templateContent 模板的内容字符串
 * @param context 上下文
 * @return 模板和内容匹配后的内容
 */
public static String merge(String templateContent, VelocityContext context) {
  final StringWriter writer = new StringWriter();
  try {
    Velocity.evaluate(context, writer, IdUtil.randomUUID(), templateContent);
  } catch (Exception e) {
    throw new UtilException(e);
  }
  return writer.toString();
}

代码示例来源:origin: looly/hutool

/**
 * 融合模板和内容
 * 
 * @param templateContent 模板的内容字符串
 * @param context 上下文
 * @return 模板和内容匹配后的内容
 */
public static String merge(String templateContent, VelocityContext context) {
  final StringWriter writer = new StringWriter();
  try {
    Velocity.evaluate(context, writer, IdUtil.randomUUID(), templateContent);
  } catch (Exception e) {
    throw new UtilException(e);
  }
  return writer.toString();
}

代码示例来源:origin: com.github.yroffin/jbehaviour-engine

@Override
public String asString(String value) throws JBehaviourParsingError {
  writer = new StringWriter();
  Velocity.evaluate( context, writer, "", value);
  return writer.toString();
}

代码示例来源:origin: webwork/webwork-jira

public String evaluate(String expression) throws IOException, ResourceNotFoundException, MethodInvocationException, ParseErrorException
{
  CharArrayWriter writer = new CharArrayWriter();
  Velocity.evaluate(ctx, writer, "Error parsing " + expression,  expression);
  return writer.toString();
}

代码示例来源:origin: com.intoverflow.booster/booster-core

public static void write(Context context, Writer writer, Reader reader) {
  try {
    Velocity.evaluate(context, writer, "", reader);
  } catch (Exception e) {
    log.warn(e.getMessage(), e);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.github.yroffin/jbehaviour-engine

/**
 * render this template
 * @param ctx
 * @param template
 * @return
 */
public String render(IBehaviourReflexion ctx, String template) {
  context.put("context", ctx);
  writer  = new StringWriter();
  Velocity.evaluate(context, writer, "", template);
  return writer.toString();
}

代码示例来源:origin: org.renci.jlrm.jlrm-lsf/jlrm-lsf-ssh

/**
 * Generates a new job file which is used to setup and start the glidein
 */
private void writeTemplate(VelocityContext velocityContext, File file, String template) throws IOException {
  StringWriter sw = new StringWriter();
  Velocity.evaluate(velocityContext, sw, "glidein", template);
  file.setReadable(true);
  file.setExecutable(true);
  file.setWritable(true, true);
  FileUtils.writeStringToFile(file, sw.toString());
}

代码示例来源:origin: org.renci.jlrm.jlrm-sge/jlrm-sge-ssh

/**
 * Generates a new job file which is used to setup and start the glidein
 */
private void writeTemplate(VelocityContext velocityContext, File file, String template) throws IOException {
  StringWriter sw = new StringWriter();
  Velocity.evaluate(velocityContext, sw, "glidein", template);
  file.setReadable(true);
  file.setExecutable(true);
  file.setWritable(true, true);
  FileUtils.writeStringToFile(file, sw.toString());
}

代码示例来源:origin: net.oschina.durcframework/easyopen

public static void generate(VelocityContext context, InputStream inputStream, Writer writer) {
  Reader reader = new InputStreamReader(inputStream);
  Velocity.evaluate(context, writer, LOG_TAG, reader);
  try {
    writer.close();
    reader.close();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: net.oschina.durcframework/easyopen

public static String generateToString(VelocityContext context, Reader reader) {
  StringWriter writer = new StringWriter();
  // 不用vm文件
  Velocity.evaluate(context, writer, LOG_TAG, reader);
  try {
    reader.close();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  return writer.toString();
}

代码示例来源:origin: org.renci.jlrm.jlrm-slurm/jlrm-slurm-ssh

/**
 * Generates a new job file which is used to setup and start the glidein
 */
private void writeTemplate(VelocityContext velocityContext, File file, String template) throws IOException {
  StringWriter sw = new StringWriter();
  Velocity.evaluate(velocityContext, sw, "glidein", template);
  file.setReadable(true);
  file.setExecutable(true);
  file.setWritable(true, true);
  FileUtils.writeStringToFile(file, sw.toString());
}

代码示例来源:origin: net.oschina.durcframework/easymybatis

public static String generate(VelocityContext context, Reader reader) {
  StringWriter writer = new StringWriter();
  // 不用vm文件
  Velocity.evaluate(context, writer, LOG_TAG, reader);
  try {
    writer.close();
    reader.close();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  return writer.toString();
}

代码示例来源:origin: org.renci.jlrm.jlrm-pbs/jlrm-pbs-ssh

/**
 * Generates a new job file which is used to setup and start the glidein
 */
private void writeTemplate(VelocityContext velocityContext, File file, String template) throws IOException {
  StringWriter sw = new StringWriter();
  Velocity.evaluate(velocityContext, sw, "glideins", template);
  file.setReadable(true);
  file.setExecutable(true);
  file.setWritable(true, true);
  FileUtils.writeStringToFile(file, sw.toString());
}

代码示例来源:origin: org.ojbc.bundles.intermediaries/subscription-notification-service-intermediary-common

private String applyTemplate(EmailNotification emailNotification, String template) {
  VelocityContext context = new VelocityContext();
  context.put("emailNotification", emailNotification);
  String subscribingSystemId = systemIdentifierToDescriptorMap.get(emailNotification.getSubscribingSystemIdentifier());
  context.put("subscribingSystemDescriptor", subscribingSystemId == null ? "Unknown system" : subscribingSystemId);
  StringWriter w = new StringWriter();
  Velocity.evaluate(context, w, "applyTemplates", template);
  return w.toString();
}

代码示例来源:origin: laiweiwei/eweb4j-framework

public String render(Map<String, Object> datas, String template) {
    Velocity.init();
    VelocityContext context = new VelocityContext();
    for (Iterator<Entry<String, Object>> it = datas.entrySet().iterator(); it.hasNext(); ){
      Entry<String, Object> e = it.next();
      context.put(e.getKey(), e.getValue());
    }
    StringWriter writer = new StringWriter();
    Velocity.evaluate(context, writer, "", template);
    
    return writer.toString();
  }
}

代码示例来源:origin: org.apache.ace/org.apache.ace.client.repository.helper.base

private byte[] process(byte[] input, PropertyResolver props) throws IOException {
  try {
    VelocityContext context = new VelocityContext();
    context.put("context", props);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(baos);
    Velocity.evaluate(context, writer, "", new InputStreamReader(new ByteArrayInputStream(input)));
    writer.flush();
    return baos.toByteArray();
  }
  catch (IOException ioe) {
    throw new IOException("Error processing the artifact: " + ioe.getMessage());
  }
}

代码示例来源:origin: com.moomanow/moomanow-core

public String evaluate(String inString , Map<String,Object> values){
    Context context = convertToContext(values);
    StringWriter sw = new StringWriter();
    Velocity.evaluate(context, sw, "LOG" , inString);
    return sw.toString();
  }
}

代码示例来源:origin: brucexx/heisenberg

public static void main(String[] args) {
  // System.out.println(substring(crc32("123123123123123"), -3, -1));
  String s = "<person>121212:/aaa/bbb";
  VelocityContext context = new VelocityContext();
  Writer writer = new StringWriter();
  // //Pattern.compile("^[0-9a-fA-F]+$")
  Velocity.evaluate(context, writer, StringUtil.EMPTY, "$!Pattern.compile(\"^[0-9a-fA-F]+$\")");
  System.out.println(writer.toString());
  System.out.println(substring(s, s.indexOf(">") + 1, s.indexOf(":")));
  // $!stringUtil.substring($PARENT_PATH, $!stringUtil.indexOf($PARENT_PATH,">") + 1,
  // $!stringUtil.indexOf($PARENT_PATH,":"))
  // $!stringUtil.substring
}

代码示例来源:origin: org.compass-project/compass

protected Object evaluate(Object o, ResourcePropertyMapping resourcePropertyMapping) throws ConversionException {
    VelocityContext ctx = new VelocityContext();
    ctx.put(DATA_CONTEXT_KEY, o);

    StringBuilderWriter sw = StringBuilderWriter.Cached.cached();
    try {
      Velocity.evaluate(ctx, sw, "", vtl);
    } catch (Exception e) {
      throw new ConversionException("Failed to evaluate [" + o + "] with expression [" + vtl + "]", e);
    }
    return sw.toString();
  }
}

代码示例来源:origin: net.bpelunit/framework

protected String expandTemplateToString(VelocityContextProvider context, String template) throws DataSourceException {
  Context velocityCtx = CLONER.deepClone(context.createVelocityContext());
  velocityCtx.put("xpath", new XPathTool(getNamespaceContext()));
  velocityCtx.put("printer", new XMLPrinterTool());
  // Expand the template as a regular string
  StringWriter writer = new StringWriter();
  Velocity.evaluate(velocityCtx, writer, "expandTemplate", template);
  return writer.toString();
}

相关文章