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


Java Template.merge方法代碼示例

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


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

示例3: execute

import org.apache.velocity.Template; //導入方法依賴的package包/類
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());
		context.put("files", req.getParameter("files"));
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/rete-diagram.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:17,代碼來源:ReteDiagramServletHandler.java

示例4: writeBin

import org.apache.velocity.Template; //導入方法依賴的package包/類
protected void writeBin(String destDir, String project, String packagePath) throws IOException {
    String binPath = getBinPath();
    List<String> files = getBinFiles();
    for (String fileName : files) {
        String file = binPath + fileName;
        Template template = VelocityUtil.getTempate(file);
        VelocityContext ctx = new VelocityContext();
        ctx.put("packagePath", packagePath);
        ctx.put("project", project);
        if (file.contains("shutdown")) {
            ctx.put("application", this.applicationName);

        } else {
            ctx.put("application", packagePath + "." + this.applicationName);
        }
        StringWriter writer = new StringWriter();
        template.merge(ctx, writer);
        writer.close();
        write(writer.toString(), destDir + fileName);
    }
}
 
開發者ID:wu191287278,項目名稱:sc-generator,代碼行數:22,代碼來源:AbstractGenerator.java

示例5: 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("uflo-html/calendar.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:uflo,代碼行數:17,代碼來源:CalendarServletHandler.java

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

示例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("uflo-html/designer.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:uflo,代碼行數:17,代碼來源:DesignerServletHandler.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());
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("uflo-html/central.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:uflo,代碼行數:17,代碼來源:CentralServletHandler.java

示例9: 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("uflo-html/todo.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:uflo,代碼行數:17,代碼來源:TodoServletHandler.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());
		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

示例11: writeApplicationConfigs

import org.apache.velocity.Template; //導入方法依賴的package包/類
protected void writeApplicationConfigs(String destApplicationPath, String project, String packagePath) throws IOException {

        String applicationPath = getSrcApplicationFilesPath();
        List<String> applicationFiles = getApplicationFiles();
        for (String filename : applicationFiles) {
            if (filename.contains("/")) {
                String parentPath = filename.substring(0, filename.lastIndexOf("/"));
                new File(destApplicationPath + "/" + parentPath).mkdirs();
            }

            Template tempate = VelocityUtil.getTempate((applicationPath + "/" + filename).replaceAll("[/]+", "/"));
            VelocityContext ctx = new VelocityContext();
            ctx.put("project", project);
            ctx.put("driverClass", driverClass);
            ctx.put("username", username);
            ctx.put("password", password);
            ctx.put("packagePath", packagePath);
            ctx.put("realPath", packagePath.replace(".", "/"));
            ctx.put("url", url);
            StringWriter writer = new StringWriter();
            tempate.merge(ctx, writer);
            writer.close();
            write(writer.toString(), destApplicationPath + "/" + filename);
        }
    }
 
開發者ID:wu191287278,項目名稱:sc-generator,代碼行數:26,代碼來源:AbstractGenerator.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/scorecard-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:22,代碼來源:ScorecardEditorServletHandler.java

示例13: outputCode

import org.apache.velocity.Template; //導入方法依賴的package包/類
public void outputCode(String codePath, String templatePath) throws IOException {
    VelocityContext context = new VelocityContext();
    context.put("cModule", cModule);

    Template template = null;
    try {
        template = Velocity.getTemplate(templatePath, TEMPLATE_ENCODING);
    } catch (ResourceNotFoundException e) {
        throw e;
    }
    
    File file = new File(codePath);
    logger.info("Generating {} ({})", file.getName(), templatePath);

    PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), OUTPUT_ENCODING)));
    template.merge(context, pw);
    pw.close();
}
 
開發者ID:ChangeVision,項目名稱:astah-uml2c-plugin,代碼行數:19,代碼來源:CodeGenerator.java

示例14: renderNonWebAppTemplate

import org.apache.velocity.Template; //導入方法依賴的package包/類
@Test
public void renderNonWebAppTemplate() throws Exception {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			VelocityAutoConfiguration.class);
	try {
		VelocityEngine velocity = context.getBean(VelocityEngine.class);
		StringWriter writer = new StringWriter();
		Template template = velocity.getTemplate("message.vm");
		template.process();
		VelocityContext velocityContext = new VelocityContext();
		velocityContext.put("greeting", "Hello World");
		template.merge(velocityContext, writer);
		assertThat(writer.toString()).contains("Hello World");
	}
	finally {
		context.close();
	}
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:19,代碼來源:VelocityAutoConfigurationTests.java

示例15: writeDockerfile

import org.apache.velocity.Template; //導入方法依賴的package包/類
protected void writeDockerfile(String srcDockerfile, String destDockerfile, String project, String packagePath) throws IOException {
    Template tempate = VelocityUtil.getTempate(srcDockerfile);
    VelocityContext ctx = new VelocityContext();
    ctx.put("package", packagePath);
    ctx.put("project", project);
    ctx.put("username", this.username);
    ctx.put("password", this.password);
    String host = url.substring(0, url.lastIndexOf("/")).substring(url.substring(0, url.lastIndexOf("/")).lastIndexOf("/") + 1);

    int port = 3306;
    String database = project;
    try {
        database = url.substring(url.lastIndexOf("/") + 1);
        if (host.contains(":")) {
            String[] split = host.split(":");
            port = Integer.parseInt(split[1]);
        }
    } catch (Exception e) {

    }
    ctx.put("port",port);
    ctx.put("database",database);
    ctx.put("application", packagePath + "." + this.applicationName);
    StringWriter writer = new StringWriter();
    tempate.merge(ctx, writer);
    writer.close();
    write(writer.toString(), destDockerfile);
}
 
開發者ID:wu191287278,項目名稱:sc-generator,代碼行數:29,代碼來源:AbstractGenerator.java


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