Package org.apache.velocity

Examples of org.apache.velocity.VelocityContext


    public void generateErrorPage(Exception exception) throws Exception {
        VelocityEngine ve = new VelocityEngine();
        ve.init(getProperties());
        Template errorPage = ve.getTemplate("templates/errorPage.vm");
        VelocityContextMap contextMap = VelocityContextMap.of(new VelocityContext());
        contextMap.putAll(getGeneralParameters());
        contextMap.put("error_message", exception);
        contextMap.put("time_stamp", new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()));
        generateReport("feature-overview.html", errorPage, contextMap.getVelocityContext());
    }
View Full Code Here


                    logger.error("Exception: get template", e);
                  }
                }
               
                // 渲染VM
                VelocityContext cxt = new VelocityContext();
                monitor.getData(cxt);
                Writer writer = new StringWriter();
                template.merge(cxt, writer);
                response.setStatusCode(HttpStatus.SC_OK);
                NStringEntity entity = new NStringEntity(writer.toString(), ContentType.create("text/html", "UTF-8"));
View Full Code Here

    public static void main(final String[] args) throws Exception {
        Velocity.init();
        final Template t = Velocity.getTemplate("./templates/poc.vm");

        final VelocityContext ctx = new VelocityContext();

        final Writer writer = new StringWriter();
        t.merge(ctx, writer);

        System.out.println(writer);
View Full Code Here

            ErlLogger.error(e);
            log.error(e);
        }

        // add data to a context
        final VelocityContext context = new VelocityContext();
        context.put("obj", obj);
        context.put("children", obj.getChildren());
        context.put("date", date);
        context.put("type", type);
        context.put("css", cssCode);

        try {
            final String templText = getTemplateFromJar(relative);
            StringResourceLoader.getRepository().putStringResource("my_template",
                    templText);
View Full Code Here

        this.resource = resource;
        this.encoding = encoding;
    }

    public void generate(Writer writer, Map model) throws TemplateGenerationException {
        VelocityContext context = new VelocityContext(model);
        try {
            engine.evaluate(context, writer, resource.getDescription(), new InputStreamReader(resource.getInputStream(), encoding));
        } catch (IOException ioe) {
            throw new TemplateGenerationException("Could not generate velocity template for resource '" +
                resource.getDescription() + "'", ioe);
View Full Code Here

        this.template = template;
        this.templateDescription = templateDescription;
    }

    public void generate(Writer writer, Map model) throws TemplateGenerationException {
        VelocityContext context = new VelocityContext(model);
        try {
            template.merge(context, writer);
        } catch (IOException ioe) {
            throw new TemplateGenerationException("Could not generate velocity template for resource '" +
                templateDescription + "'", ioe);
View Full Code Here

        this.resource = resource;
        this.encoding = encoding;
    }

    public void generate(Writer writer, Map model) throws TemplateGenerationException {
        VelocityContext context = new VelocityContext(model);
        try {
            engine.evaluate(context, writer, resource.getDescription(), new InputStreamReader(resource.getInputStream(), encoding));
        } catch (IOException ioe) {
            throw new TemplateGenerationException("Could not generate velocity template for resource '" +
                resource.getDescription() + "'", ioe);
View Full Code Here

     * @param node The node to initialize.
     * @param ri The velcotiy runtime instance that will be used while initilizing.
     * @param name A name to be associated with the template to be used in log messages.
     */
    protected static void init(SimpleNode node, ExtendedRuntimeInstance ri, String name) {
        InternalContextAdapterImpl ica = new InternalContextAdapterImplnew VelocityContext() );
        try {

            ica.pushCurrentTemplateName( name );
            node.init(ica, ri);

View Full Code Here

    VelocityEngine engine;
    StringWriter writer;
    Template pageTemplate;

    public void initialize(String template) {
        context = new VelocityContext();
        engine = new VelocityEngine();
        writer = new StringWriter();
        WebSearchIni.loadProps();
        try {
            engine.init(Vars.velocityProps);
View Full Code Here

        mkdir(packagePath + module);
        mkdir(rootPath + "src/main/webapp/WEB-INF/views/" + module);
      }
    }

    VelocityContext appData = new VelocityContext();
    appData.put("app", app);
    appData.put("helper", new Helper());
    appData.put("userEntity", app.getEntity("User"));
    appData.put("dolCurly", "${");

    generateCode(rootPath + "pom.xml", "pom.xml.vm", appData, false);
    generateCode(rootPath + "src/main/resources/app.properties", "app.properties.vm", appData, true);
    generateCode(rootPath + "src/main/webapp/WEB-INF/messages/messagesGenerated.properties", "messagesGenerated.properties.vm", appData, true);
    generateCode(rootPath + "src/main/webapp/WEB-INF/spring/app-config.xml", "app-config.xml.vm", appData, true);
    generateCode(rootPath + "src/main/webapp/WEB-INF/spring/mail.xml", "mail.xml.vm", appData, true);
    generateCode(packagePath + "generated/common/Ref.java", "Ref.java.vm", appData, true);
    generateCode(packagePath + "generated/common/PageInfo.java", "PageInfo.java.vm", appData, true);
    generateCode(packagePath + "generated/common/Paginate.java", "Paginate.java.vm", appData, true);
    generateCode(packagePath + "generated/common/SelectOption.java", "SelectOption.java.vm", appData, true);
    generateCode(packagePath + "generated/common/SmtpAuthenticator.java", "SmtpAuthenticator.java.vm", appData, true);
    generateCode(packagePath + "generated/common/HelperGenerated.java", "HelperGenerated.java.vm", appData, true);
    generateCode(packagePath + "common/Helper.java", "Helper.java.vm", appData, false);
    generateCode(packagePath + "generated/common/CaptchaController.java", "CaptchaController.java.vm", appData, true);
    generateCode(packagePath + "generated/common/BaseControllerGenerated.java", "BaseControllerGenerated.java.vm", appData, true);
    generateCode(packagePath + "common/BaseController.java", "BaseController.java.vm", appData, true);
    generateCode(packagePath + "generated/common/RootControllerGenerated.java", "RootControllerGenerated.java.vm", appData, true);
    generateCode(packagePath + "common/RootController.java", "RootController.java.vm", appData, false);
    generateCode(packagePath + "generated/ChangePasswordForm.java", "ChangePasswordForm.java.vm", appData, true);
    generateCode(packagePath + "generated/ForgotPasswordForm.java", "ForgotPasswordForm.java.vm", appData, true);
    generateCode(packagePath + "generated/common/BaseEntityGenerated.java", "BaseEntityGenerated.java.vm", appData, true);
    generateCode(packagePath + "common/BaseEntity.java", "BaseEntity.java.vm", appData, false);
    generateCode(packagePath + "generated/common/BaseServiceGenerated.java", "BaseServiceGenerated.java.vm", appData, true);
    generateCode(packagePath + "generated/common/BaseServiceImplGenerated.java", "BaseServiceImplGenerated.java.vm", appData, true);
    generateCode(packagePath + "common/BaseService.java", "BaseService.java.vm", appData, true);
    generateCode(packagePath + "common/BaseServiceImpl.java", "BaseServiceImpl.java.vm", appData, true);
    generateCode(rootPath + "src/main/webapp/WEB-INF/views/register.jsp", "register.jsp.vm", appData, true);

    for (BizEntity entity: app.getEntities()) {
     
      appData.put("entity", entity);
     
      for (String codeType: entityCodeTypes) {
        generateCode(packagePath + "generated/" + entity.getModuleUrl() + "/" +
            entity.getName() + codeType + "Generated.java", "Entity" + codeType + "Generated.java.vm", appData, true);
        generateCode(packagePath + "handcrafted/" + entity.getModuleUrl() + "/" +
View Full Code Here

TOP

Related Classes of org.apache.velocity.VelocityContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.