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


Java VelocityEngine.mergeTemplate方法代码示例

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


在下文中一共展示了VelocityEngine.mergeTemplate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeTo

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Override
public void writeTo(String templateReference, Viewable viewable, MediaType mediaType,
		MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException {

	// 获取 模板引擎
	VelocityEngine velocityEngine = getVelocityEngine();

	// 实例化一个VelocityContext
	VelocityContext context = (VelocityContext) viewable.getModel();
	Enumeration<String> enums = request.getParameterNames();
	while (enums.hasMoreElements()) {
		String key = enums.nextElement();
		context.put(key, request.getParameter(key));
	}
	// 把request放进模板上下文里
	context.put("request", request);

	// 渲染并输出
	OutputStreamWriter outputStreamWriter = new OutputStreamWriter(out);
	velocityEngine.mergeTemplate(templateReference, "utf8", context, outputStreamWriter);
	outputStreamWriter.flush();
	outputStreamWriter.close(); // 有必要关闭吗? 关闭了是否对jax-rs拦截器,servlet有影响,需要继续学习,参考jsp模板实现
}
 
开发者ID:xixifeng,项目名称:fastquery,代码行数:24,代码来源:VelocityTemplateProcessor.java

示例2: renderTemplate

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Return the String representation of the template rendered using Velocity.
 *
 * @param context context use to render the template
 * @param templateFileName file name of the template in the classpath
 * @throws TemplateRenderException if there is an error with the template
 */
public static String renderTemplate(String templateFileName,
                                    VelocityContext context)
    throws TemplateRenderException {
  VelocityEngine ve = new VelocityEngine();
  ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
  ve.setProperty("classpath.resource.loader.class",
      ClasspathResourceLoader.class.getName());

  StringWriter sw = new StringWriter();

  try {
    ve.mergeTemplate(templateFileName, "UTF-8", context, sw);
  } catch (ResourceNotFoundException
      | ParseErrorException
      | MethodInvocationException e) {
    throw new TemplateRenderException("Error rendering template file: " + templateFileName, e);
  }

  return sw.toString();
}
 
开发者ID:airbnb,项目名称:reair,代码行数:28,代码来源:VelocityUtils.java

示例3: renderFile

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * 渲染模板文件.
 * 
 * @param velocityEngine velocityEngine, 需经过VelocityEngineFactory处理, 绑定Spring的ResourceLoader.
 * @param templateContent 模板文件名, loader会自动在前面加上velocityEngine的resourceLoaderPath.
 * @param context 变量Map.
 */
public static String renderFile(String templateFilePName, VelocityEngine velocityEngine, String encoding,
		Map<String, ?> context) {
	VelocityContext velocityContext = new VelocityContext(context);

	StringWriter result = new StringWriter();
	velocityEngine.mergeTemplate(templateFilePName, encoding, velocityContext, result);
	return result.toString();
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:16,代码来源:VelocityUtils.java

示例4: doHandleRequest

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Override
protected ModelAndView doHandleRequest(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
	Properties properties=new Properties();
       properties.setProperty("resource.loader", "file");
       properties.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
       String contextPath=request.getContextPath();
       if(!contextPath.endsWith("/")){
       	contextPath+="/";
       }
       VelocityEngine velocityEngine=new VelocityEngine(properties);
       VelocityContext context=new VelocityContext();
       StringBuffer sb=new StringBuffer();
       sb.append("\r");
       sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\""+contextPath+"dorado/res/dorado/resources/jquery.contextMenu.css\" />");
       sb.append("\r");
       sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\""+contextPath+"dorado/res/dorado/resources/jquery-ui-1.8.19.custom.css\" />");
       sb.append("\r");
       sb.append("<script type=\"text/javascript\" src=\""+contextPath+"dorado/res/dorado/scripts/jbpm4-designer-all-in-one.js\"></script>");
       sb.append("\r");
       
       String serverUrl=this.buildServerUrl(request.getScheme(),request.getServerName(),request.getServerPort());
       if(contextPath.endsWith("/")){
       	serverUrl+=contextPath.substring(0,contextPath.length()-1);
       }
       context.put("cssandscript", sb.toString());
       context.put("baseIconsDir", contextPath+"dorado/res/dorado/resources");
       context.put("serverUrl", serverUrl);
       StringWriter writer=new StringWriter();
       velocityEngine.mergeTemplate("dorado/resources/jbpm4-designer.html","utf-8", context, writer);
       response.setContentType("text/html; charset=utf-8");
       PrintWriter out=response.getWriter();
       out.write(writer.toString());
       out.flush();
       out.close();
	return null;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:38,代码来源:DesignerController.java

示例5: renderTemplate

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Render a template and return the result
 *
 * @param templateName the template name only without the .vm extension
 * @param context the context
 * @return string
 */
public static String renderTemplate(String templateName, VelocityContext context) {
  StringWriter stringWriter = new StringWriter();
  VelocityEngine engine = new VelocityEngine();
  engine.init("src/test/resources/velocity.properties");

  engine.mergeTemplate(TEMPLATE_BASE_DIR + templateName + ".vm", "UTF-8", context, stringWriter);
  return stringWriter.getBuffer().toString();
}
 
开发者ID:JasonBian,项目名称:azkaban,代码行数:16,代码来源:VelocityTemplateTestUtil.java

示例6: mergeTemplate

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Merge the specified Velocity template with the given model and write
 * the result to the given Writer.
 * @param velocityEngine VelocityEngine to work with
 * @param templateLocation the location of template, relative to Velocity's resource loader path
 * @param model the Map that contains model names as keys and model objects as values
 * @param writer the Writer to write the result to
 * @throws VelocityException if the template wasn't found or rendering failed
 * @deprecated Use {@link #mergeTemplate(VelocityEngine, String, String, Map, Writer)}
 * instead, following Velocity 1.6's corresponding deprecation in its own API.
 */
@Deprecated
public static void mergeTemplate(
		VelocityEngine velocityEngine, String templateLocation, Map<String, Object> model, Writer writer)
		throws VelocityException {

	VelocityContext velocityContext = new VelocityContext(model);
	velocityEngine.mergeTemplate(templateLocation, velocityContext, writer);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:VelocityEngineUtils.java

示例7: mergeTemplate

import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
 * Merge the specified Velocity template with the given model and write
 * the result to the given Writer.
 * @param velocityEngine VelocityEngine to work with
 * @param templateLocation the location of template, relative to Velocity's resource loader path
 * @param model the Map that contains model names as keys and model objects as values
 * @param writer the Writer to write the result to
 * @throws org.apache.velocity.exception.VelocityException if the template wasn't found or rendering failed
 * @deprecated Use {@link #mergeTemplate(org.apache.velocity.app.VelocityEngine, String, String, java.util.Map, java.io.Writer)}
 * instead, following Velocity 1.6's corresponding deprecation in its own API.
 */
@Deprecated
public static void mergeTemplate(
		VelocityEngine velocityEngine, String templateLocation, Map<String, Object> model, Writer writer)
		throws VelocityException {

	VelocityContext velocityContext = new VelocityContext(model);
	velocityEngine.mergeTemplate(templateLocation, velocityContext, writer);
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:20,代码来源:VelocityEngineUtils.java


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