Java 类org.apache.velocity.tools.generic.DisplayTool 实例源码

项目:soap-to-jpa    文件:SoapToJpaMojo.java   
/**
 * Create Interface for all the field containers
 *
 * @param t
 * @throws MojoFailureException
 */
private void generateJpaStubInterface(Template t) throws MojoFailureException, IOException {

    final String packagePath = BuildHelper.ensurePackageExists(this.jpaOutputDirectory.getAbsolutePath(), this.fieldsPackageName);

    File file = BuildHelper.getFile(packagePath, "IJpaStub", "");
    VelocityContext context = new VelocityContext();
    context.put("package", fieldsPackageName);
    context.put("generationDate", generationDate);
    context.put("identityFieldType", this.fieldNameUsedAsIdentityType);
    context.put("identityFieldName", this.fieldNameUsedAsIdentityName);
    context.put("display", new DisplayTool());

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

    BuildHelper.writeContentToFile(writer.toString(), file);
}
项目:deltaforce    文件:DeltaBuilderProcessor.java   
/**
 * Actually writes the model
 *
 * @param model
 * @param fields
 * @throws Exception
 */
protected void writeBuilder(DeltaBuilderTypeModel model, Map<String, FieldModel> fields,
        String template) throws Exception {
    VelocityContext vc = new VelocityContext();

    vc.put("generatorClassName", this.getClass().toString());
    vc.put("model", model);
    vc.put("fields", fields);
    vc.put("date", new Date().toString());
    vc.put("util", DFUtil.INSTANCE);

    // adding DisplayTool from Velocity Tools library
    vc.put("display", new DisplayTool());

    Template vt = velocityEngine.getTemplate(template);

    JavaFileObject jfo = processingEnv.getFiler()
            .createSourceFile(model.getDeltaBuilderQualifiedName());

    printNote("creating source file: " + jfo.toUri(), null);

    Writer writer = jfo.openWriter();

    printNote("applying velocity template: " + vt.getName(), null);

    vt.merge(vc, writer);

    writer.close();
}
项目:mcp    文件:VelocityRenderer.java   
private void renderToFolder(EntityObject eo, String template, String folder, String fileName) throws IOException {
    // first, let's build the filename.
    String fullFileName = folder + File.separator + fileName;

    VelocityEngine ve = new VelocityEngine();
    // Tried using classpath, but discarded it.
    ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
    ve.setProperty("file.resource.loader.class", FileResourceLoader.class.getName());
    // setting it empty, so we can use an absolute path
    ve.setProperty("file.resource.loader.path", "");
    ve.init();
    VelocityContext ctx = new VelocityContext();
    ctx.put("ENTITY", eo);
    ctx.put("display", new DisplayTool());
    // now, let's expand the template path in case we are using one of our
    // default templates.
    if (template.startsWith("templates/")) {
        // ok, we assume it's one of our default templates in MCP_HOME
        String modelHomeFolder = System.getenv("MCP_HOME");
        if (!modelHomeFolder.endsWith(File.separator))
            modelHomeFolder = modelHomeFolder + File.separator;
        template = modelHomeFolder + template;
    }

    Template t = ve.getTemplate(template);
    StringWriter writer = new StringWriter();
    t.merge(ctx, writer);
    // System.out.println(writer);

    log.info("Writing file " + fullFileName);
    FileWriter fileWriter = new FileWriter(fullFileName);
    fileWriter.write(writer.toString());
    fileWriter.flush();
    fileWriter.close();
}
项目:Glowplug    文件:EntityProcessor.java   
private void processEntityClass(Element e) {
    String className;
    String packageName;
    String tableName;
    TypeElement classElement = (TypeElement) e;
    PackageElement packageElement = Util.getPackage(e);

    className = classElement.getSimpleName().toString();
    packageName = packageElement.getQualifiedName().toString();
    tableName = className;


    VelocityContext vc = new VelocityContext();

    vc.put("className", className);
    vc.put("packageName", packageName);
    vc.put("tableName", tableName);

    ArrayList<VariableParser.AttributeStruct> attrs = new ArrayList<VariableParser.AttributeStruct>();
    ArrayList<VariableParser.RelationStruct> relationships = new ArrayList<VariableParser.RelationStruct>();
    if (parseFields(classElement, attrs, relationships)) {
        vc.put("attrs", attrs);
        vc.put("relationships", relationships);
        vc.put("display", new DisplayTool());

        Template vt = ve.getTemplate("entity.vm");

        String name = packageName + "." + classElement.getSimpleName() + "Entity";

        writeTemplateToFile(vt, vc, name, e);
    }
}