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


Java Velocity.getTemplate方法代码示例

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


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

示例1: generate

import org.apache.velocity.app.Velocity; //导入方法依赖的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

示例2: createTable

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
@Override
public String createTable(Grammar grammar) {
    Velocity.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8");
    Velocity.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");
    Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());

    Velocity.init();
    VelocityContext context = new VelocityContext();
    context.put("grammar", grammar);

    context.put("nonterminalSymbols", grammar.getLhsSymbols());

    Template template = Velocity.getTemplate("/grammartools/PredictiveParsingTable.velo");
    StringWriter stringWriter = new StringWriter();
    template.merge(context, stringWriter);
    return stringWriter.toString().replaceAll("\n", "");
}
 
开发者ID:georgfedermann,项目名称:compilers,代码行数:19,代码来源:LL1TableCreator.java

示例3: outputCode

import org.apache.velocity.app.Velocity; //导入方法依赖的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

示例4: getTemplate

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
/**
 * Gets the template by viewname, the viewname is relative path
 * 
 * @param viewname
 *          the relative view path name
 * @param allowEmpty
 *          if not presented, allow using a empty
 * @return Template
 * @throws IOException
 */
private Template getTemplate(File f) throws IOException {

  String fullname = f.getCanonicalPath();
  T t = cache.get(fullname);

  if (t == null || t.last != f.lastModified()) {

    /**
     * get the template from the top
     */
    Template t1 = Velocity.getTemplate(fullname, "UTF-8");
    t = T.create(t1, f.lastModified());

    cache.put(fullname, t);
  }

  return t == null ? null : t.template;

}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:30,代码来源:VelocityView.java

示例5: parseTemplateAndRunExpect

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
protected void parseTemplateAndRunExpect(String expectTemplateName, Map<String, String> contextVars) throws IOException, InterruptedException {
    VelocityContext context = new VelocityContext();
    for (Map.Entry<String, String> ent : contextVars.entrySet()) {
        context.put(ent.getKey(), ent.getValue());
    }

    Template template = Velocity.getTemplate(expectTemplateName);
    String inputPath = EXPECT_DIR + File.separator + expectTemplateName;
    String outputPath = inputPath.substring(0, inputPath.length() - 3);

    Writer output = new FileWriter(outputPath);
    template.merge(context, output);
    output.close();

    expect(ZIPFILE_EXTRACTED, outputPath);
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:17,代码来源:AbstractTitanAssemblyIT.java

示例6: createTemplatePage

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
private void createTemplatePage(Content content, String templateFileName, Path outFilePath) throws IOException {
	// template name
	content.put("template", Config.getTemplate());

	Properties p = new Properties();
	p.setProperty("input.encoding", "UTF-8");
	p.setProperty("output.encoding", "UTF-8");
	p.setProperty("file.resource.loader.path", Config.getTemplateBaseDir());
	Velocity.init(p);
	
	VelocityContext context = content.getVelocityContext();
	
	org.apache.velocity.Template template = Velocity.getTemplate(Config.getTemplateFile(lang, templateFileName).toString(), "UTF-8");
	
	BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFilePath.toFile()), "UTF-8"));
	template.merge(context, bw);
	bw.close();
}
 
开发者ID:cccties,项目名称:chilo-producer,代码行数:19,代码来源:Process.java

示例7: compileUristJs

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
/**
 * Load the urist.js template and compile it with project information.
 */
public static void compileUristJs() {
    Log.info("TemplateRenderer", "Writing urist.js");
    VelocityContext context = new VelocityContext();
    context.put("conf", Uristmaps.conf);
    context.put("version",Uristmaps.VERSION);

    Template uristJs = Velocity.getTemplate("templates/js/urist.js.vm");

    File targetFile = OutputFiles.getUristJs();
    targetFile.getParentFile().mkdirs();
    try (FileWriter writer = new FileWriter(targetFile)) {
        uristJs.merge(context, writer);
    } catch (IOException e) {
        Log.warn("TemplateRenderer", "Could not write js file: " + targetFile);
        if (Log.DEBUG) Log.debug("TemplateRenderer", "Exception", e);
    }
}
 
开发者ID:dominiks,项目名称:uristmapsj,代码行数:21,代码来源:TemplateRenderer.java

示例8: createReportFromValidationResult

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
private static void createReportFromValidationResult(ValidationResult result, Path outputPath) {
    Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    Velocity.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    Velocity.init();

    try {
        Template template = Velocity.getTemplate("reporting/ValidationResult.vm");

        VelocityContext context = new VelocityContext();
        context.put("validationResult", result);
        context.put("resourcesWithWarnings", getResourcesWithWarnings(result));
        StringWriter sw = new StringWriter();
        template.merge(context, sw);

        try (FileWriter fw = new FileWriter(outputPath.toFile())) {
            fw.write(sw.toString());
            fw.flush();
        } catch (IOException ioe) {
            LOGGER.error("Creation of HTML Report file {} failed.", outputPath.toString(), ioe);
        }
    } catch (VelocityException e) {
        LOGGER.error("Creation of HTML report failed due to a Velocity Exception", e);
    }

}
 
开发者ID:uniba-dsg,项目名称:BPMNspector,代码行数:26,代码来源:HtmlReportGenerator.java

示例9: parseObj

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
protected void parseObj(
        final File base,
        final boolean append,
        final String pkg,
        final String name,
        final String out,
        final Map<String, Object> objs)
        throws MojoExecutionException {

    final VelocityContext ctx = newContext();
    ctx.put("package", pkg);

    if (objs != null) {
        for (Map.Entry<String, Object> obj : objs.entrySet()) {
            if (StringUtils.isNotBlank(obj.getKey()) && obj.getValue() != null) {
                ctx.put(obj.getKey(), obj.getValue());
            }
        }
    }

    final Template template = Velocity.getTemplate(name + ".vm");
    writeFile(out, base, ctx, template, append);
}
 
开发者ID:ashank,项目名称:Office-365-SDK-for-Android,代码行数:24,代码来源:AbstractMetadataMojo.java

示例10: Test3

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public Test3() throws Exception {
    //init
    Velocity.init("Velocity/GS_Velocity_1/src/main/java/velocity.properties");
    // get Template
    Template template = Velocity.getTemplate("Test3.vm");
    // getContext
    Context context = new VelocityContext();

    String name = "Vova";
    int age = 21;
    boolean flag = true;

    context.put("name", name);
    context.put("age", age);
    context.put("flag", flag);

    context.put("today", new Date());
    context.put("product", new Product("Book", 12.3));

    // get Writer
    Writer writer = new StringWriter();
    // merge
    template.merge(context, writer);

    System.out.println(writer.toString());
}
 
开发者ID:java-course-ee,项目名称:java-course-ee,代码行数:27,代码来源:Test3.java

示例11: Test1

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
public Test1() throws Exception {

        //init
        Velocity.init("Velocity/GS_Velocity_1/src/main/java/velocity.properties");
        // get Template
        Template template = Velocity.getTemplate("Test1.vm");
        // getContext
        Context context = new VelocityContext();
        // get Writer
        Writer writer = new StringWriter();
        // merge
        template.merge(context, writer);

        System.out.println(writer.toString());

    }
 
开发者ID:java-course-ee,项目名称:java-course-ee,代码行数:17,代码来源:Test1.java

示例12: sendUpdatesEmail

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
private static void sendUpdatesEmail() {

        Category news = new Category("News");
        news.getContent().add(new Content("News number 1", "Text blah-blah-blah", new Date()));
        news.getContent().add(new Content("News number 2", "Text2 blah-blah-blah", new Date()));
        news.getContent().add(new Content("News number 3", "Text3 blah-blah-blah", new Date()));


        Category events = new Category("Events");
        events.getContent().add(new Content("Event number 1", "Text blah-blah-blah", new Date()));
        events.getContent().add(new Content("Event number 2", "Text2 blah-blah-blah", new Date()));
        events.getContent().add(new Content("Event number 3", "Text3 blah-blah-blah", new Date()));

        Template template = Velocity.getTemplate("updates.vm");
        Context context = new VelocityContext();

        context.put("currentDate", new Date());
        context.put("categories", Arrays.asList(news, events));

        Writer writer = new StringWriter();
        template.merge(context, writer);
        EmailUtil.send("[email protected]", "News updates", writer.toString(), EmailUtil.EmailType.HTML);

    }
 
开发者ID:java-course-ee,项目名称:java-course-ee,代码行数:25,代码来源:Main.java

示例13: doGenerate

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
@Override
public void doGenerate(final Map<String, Object> mapping, final Path output, final Path templatePath) {
  try {
    Properties p = new Properties();
    p.setProperty("input.encoding", "UTF-8");
    p.setProperty("file.resource.loader.path", templatePath.getParent().toAbsolutePath().toString());
    Velocity.init(p);
    final VelocityContext ctx = new VelocityContext();
    final BiConsumer<String, Object> _function = (String k, Object v) -> {
      ctx.put(k, v);
    };
    mapping.forEach(_function);
    Template template = Velocity.getTemplate(templatePath.getFileName().toString());
    File _file = output.toFile();
    FileWriter writer = new FileWriter(_file);
    template.merge(ctx, writer);
    writer.flush();
    writer.close();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:s-hosoai,项目名称:astahm2t,代码行数:23,代码来源:VelocityGenerator.java

示例14: generateApiImplementation

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
@Override
public String generateApiImplementation(List<EndpointInfo> endpoints, String className, String packageName,
                                        Map<Long, TypedObject> typeMap)
{
    Template template = Velocity.getTemplate("templates/class.vm");
    StringWriter stringWriter = new StringWriter();
    VelocityContext context = new VelocityContext();
    context.put("packageName", packageName);
    context.put("clientFactoryClassName", CLASS_NAME_REST_TEMPLATE_FACTORY);
    context.put("superInterfaces", new String[]{className.substring(0, className.length() - 4)});
    context.put("className", className);
    context.put("endpoints", endpoints);
    context.put("writer", writer);
    context.put("types", typeMap);
    template.merge(context, stringWriter);
    return stringWriter.toString();
}
 
开发者ID:zvoykish,项目名称:restdl,代码行数:18,代码来源:JavaRestdlGeneratorProvider.java

示例15: generateClassContents

import org.apache.velocity.app.Velocity; //导入方法依赖的package包/类
private String generateClassContents(TypedObject typedObject, String targetPackage, String className,
                                     Map<Long, TypedObject> typeMap)
{
    TypedObjectType typedObjectType = TypedObjectType.fromString(typedObject.getType());
    ContentGenerator<TypedObject> contentGenerator = contentGeneratorMap.get(typedObjectType);
    if (contentGenerator != null) {
        String content = contentGenerator.generateContent(typedObject, className, typeMap);
        if (content == null) {
            return null;
        }

        Template template = Velocity.getTemplate("templates/package_with_contents.vm");
        StringWriter stringWriter = new StringWriter();
        VelocityContext context = new VelocityContext();
        context.put("packageName", targetPackage);
        context.put("contents", content);
        template.merge(context, stringWriter);
        return stringWriter.toString();
    }
    else {
        return null;
    }
}
 
开发者ID:zvoykish,项目名称:restdl,代码行数:24,代码来源:JavaRestdlGeneratorProvider.java


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