Package net.sourceforge.rtf.helper.test

Source Code of net.sourceforge.rtf.helper.test.RTFTemplateWithVelocity

package net.sourceforge.rtf.helper.test;

import java.io.InputStream;
import java.io.StringWriter;
import java.util.Date;

import net.sourceforge.rtf.RTFTemplate;
import net.sourceforge.rtf.helper.RTFTemplateBuilder;

public class RTFTemplateWithVelocity {

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
           
            /**
             * 1. Get RTFtemplate builder
             */
            RTFTemplateBuilder builder = RTFTemplateBuilder.newRTFTemplateBuilder();
           
            /**
             * 2. Get RTFtemplate with Velocity Implementation
             */
            RTFTemplate rtfTemplate = builder.
                newRTFTemplate(RTFTemplateBuilder.DEFAULT_VELOCITY_RTFTEMPLATE);
           
            /**
             * 3. Set the template
             */
            String rtfSourceModel = "test.rtf";
            InputStream inputStream = TestFreemarkerTransformer.class.getResourceAsStream(rtfSourceModel);
            rtfTemplate.setTemplate(inputStream);
           
            /**
             * 4. Put context
             */
            rtfTemplate.put("date", new Date());
           
            /**
             * 5. Merge context with template
             * In this case context will be used to transform RTFDocument
             */ 
            StringWriter writer = new StringWriter();
            rtfTemplate.merge(writer);
           
            // => Result of merge
            System.out.println(writer.getBuffer());                       
           
        }
        catch (Exception e) {
            System.out.println("Error:");
            e.printStackTrace();
        }

    }

}
TOP

Related Classes of net.sourceforge.rtf.helper.test.RTFTemplateWithVelocity

TOP
Copyright © 2018 www.massapi.com. 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.