當前位置: 首頁>>代碼示例>>Java>>正文


Java Template類代碼示例

本文整理匯總了Java中org.apache.velocity.Template的典型用法代碼示例。如果您正苦於以下問題:Java Template類的具體用法?Java Template怎麽用?Java Template使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Template類屬於org.apache.velocity包,在下文中一共展示了Template類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendEmail

import org.apache.velocity.Template; //導入依賴的package包/類
private void sendEmail(final String fromEmail, final IUser to, final String inSubject, final String inTemplate, final Map<String, Object> values) {
    final Properties props = new Properties();
    props.setProperty("resource.loader", "class");
    props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    final VelocityEngine engine = new VelocityEngine(props);
    final VelocityContext context = new VelocityContext();

    engine.init();

    for(final String key : values.keySet()) {
        LOGGER.debug(() -> String.format("\t -- %s=%s", key, values.get(key)));
        context.put(key, values.get(key));
    }

    final StringWriter writer = new StringWriter();
    final Template template = engine.getTemplate("templates/" + inTemplate);

    template.merge(context, writer);

    final String inBody = writer.toString();

    sendEmail(fromEmail, to.getEmail(), inSubject, inBody);
}
 
開發者ID:howma03,項目名稱:sporticus,代碼行數:25,代碼來源:ServiceMailAbstract.java

示例2: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		String file=req.getParameter("file");
		String project = buildProjectNameFromFile(file);
		if(project!=null){
			context.put("project", project);
		}
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/decisiontable-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:22,代碼來源:DecisiontableEditorServletHandler.java

示例3: generate

import org.apache.velocity.Template; //導入依賴的package包/類
/**
 * 根據模板生成文件
 * @param inputVmFilePath 模板路徑
 * @param outputFilePath 輸出文件路徑
 * @param context
 * @throws Exception
 */
public static void generate(String inputVmFilePath, String outputFilePath, VelocityContext context) throws Exception {
	try {
		Properties properties = new Properties();
		properties.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, getPath(inputVmFilePath));
		Velocity.init(properties);
		//VelocityEngine engine = new VelocityEngine();
		Template template = Velocity.getTemplate(getFile(inputVmFilePath), "utf-8");
		File outputFile = new File(outputFilePath);
		FileWriterWithEncoding writer = new FileWriterWithEncoding(outputFile, "utf-8");
		template.merge(context, writer);
		writer.close();
	} catch (Exception ex) {
		throw ex;
	}
}
 
開發者ID:ChangyiHuang,項目名稱:shuzheng,代碼行數:23,代碼來源:VelocityUtil.java

示例4: testTemplate1

import org.apache.velocity.Template; //導入依賴的package包/類
public void testTemplate1() throws Exception {
    VelocityContext context = new VelocityContext();
    MyBean bean = createBean();
    context.put("bean", bean);
    Yaml yaml = new Yaml();
    context.put("list", yaml.dump(bean.getList()));
    VelocityEngine ve = new VelocityEngine();
    ve.setProperty("file.resource.loader.class", ClasspathResourceLoader.class.getName());
    ve.init();
    Template t = ve.getTemplate("template/mybean1.vm");
    StringWriter writer = new StringWriter();
    t.merge(context, writer);
    String output = writer.toString().trim().replaceAll("\\r\\n", "\n");
    // System.out.println(output);
    String etalon = Util.getLocalResource("template/etalon2-template.yaml").trim();
    assertEquals(etalon.length(), output.length());
    assertEquals(etalon, output);
    // parse the YAML document
    Yaml loader = new Yaml();
    MyBean parsedBean = loader.loadAs(output, MyBean.class);
    assertEquals(bean, parsedBean);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:23,代碼來源:VelocityTest.java

示例5: testApp

import org.apache.velocity.Template; //導入依賴的package包/類
@Test
@Ignore
public void testApp() throws IOException {

    Properties props = new Properties();
    props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("velocity.properties"));
    VelocityEngine ve = new VelocityEngine(props);
    ve.init();

    Template t = ve.getTemplate("/templates/registry.vm");
    VelocityContext context = new VelocityContext();

    context.put("username", "ricky");
    context.put("url", "http://www.thymeleaf.org");
    context.put("email", "[email protected]");

    StringWriter writer = new StringWriter(1024);
    t.merge(context, writer);

    String output = writer.toString();
    System.out.println(output);
}
 
開發者ID:TFdream,項目名稱:okmail,代碼行數:23,代碼來源:VelocityTest.java

示例6: buildStringWriter

import org.apache.velocity.Template; //導入依賴的package包/類
private static StringWriter buildStringWriter(List<Node> nodes, List<Edge> edges, Map<EVMEnvironment, SymExecutor> executions) throws ReportException {

        VelocityEngine velocityEngine = new VelocityEngine();
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        velocityEngine.init(p);
        Template template = velocityEngine.getTemplate(TEMPLATE_FILE);
        VelocityContext velocityContext = new VelocityContext();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            velocityContext.put("nodes", objectMapper.writeValueAsString(nodes));
            velocityContext.put("edges", objectMapper.writeValueAsString(edges));
            velocityContext.put("executions", executions);
        } catch (IOException e) {
            logger.error("Error building the report: " + e);
            throw new ReportException("Failed creating ReportItem");
        }
        StringWriter stringWriter = new StringWriter();
        template.merge(velocityContext, stringWriter);
        return stringWriter;
    }
 
開發者ID:fergarrui,項目名稱:ethereum-bytecode-analyzer,代碼行數:23,代碼來源:Report.java

示例7: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/constant-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:17,代碼來源:ConstantServletHandler.java

示例8: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		String file=req.getParameter("file");
		String project = buildProjectNameFromFile(file);
		if(project!=null){
			context.put("project", project);
		}
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/scriptdecisiontable-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:22,代碼來源:ScriptDecisiontableEditorServletHandler.java

示例9: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	if(!((PermissionService)permissionStore).isAdmin()){
		throw new NoPermissionException();
	}
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/permission-config-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:20,代碼來源:PermissionConfigServletHandler.java

示例10: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		String file=req.getParameter("file");
		String project = buildProjectNameFromFile(file);
		if(project!=null){
			context.put("project", project);
		}
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/decisiontree-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:22,代碼來源:DecisionTreeEditorServletHandler.java

示例11: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/variable-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:17,代碼來源:VariableEditorServletHandler.java

示例12: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		String file=req.getParameter("file");
		String project = buildProjectNameFromFile(file);
		if(project!=null){
			context.put("project", project);
		}
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/rule-flow-designer.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:22,代碼來源:RuleFlowDesignerServletHandler.java

示例13: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/parameter-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:17,代碼來源:ParameterServletHandler.java

示例14: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String key=req.getParameter("key");
	String msg=null;
	if(StringUtils.isBlank(key)){
		msg="<h2 style='color:red'>請指定要查看的調試消息的key值</h2>";
	}else{
		msg=debugMessageHolder.getDebugMessage(key);
	}
	VelocityContext context = new VelocityContext();
	context.put("title", "URule Console");
	context.put("msg", msg);
	resp.setContentType("text/html");
	resp.setCharacterEncoding("utf-8");
	Template template=ve.getTemplate("html/console.html","utf-8");
	PrintWriter writer=resp.getWriter();
	template.merge(context, writer);
	writer.close();
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:20,代碼來源:ConsoleServletHandler.java

示例15: execute

import org.apache.velocity.Template; //導入依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/client-config-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:17,代碼來源:ClientConfigServletHandler.java


注:本文中的org.apache.velocity.Template類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。