Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.ui.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import in.shop2020.metamodel.core.Entity;
import in.shop2020.metamodel.definitions.Catalog;
import in.shop2020.metamodel.definitions.EntityContainer;
import in.shop2020.util.Utils;

/**
 * @author naveen
 *
 */
public class VUI {
        public static String EXPORT_HTML_PATH 
                = "/home/naveen/workspace/eclipse/webapp/export/html/";

        /**
         * @param args
         */
        public static void main(String[] args) throws Exception {
                // Setup
                Velocity.init("src/in/shop2020/ui/velocity/velocity.properties");
                VelocityContext context = new VelocityContext();
                
                long entityID = Long.parseLong(args[0]);
                String templateFile = args[1];
                
                EntityContainer entContainer = 
                        Catalog.getInstance().getEntityContainer();
                
                Entity entity = entContainer.getEntity(entityID);
                Utils.logger.info("entity=" + entity);
                
                context.put("entity", entity);
                Template template = Velocity.getTemplate(templateFile);
                
                String htmlFileName = EXPORT_HTML_PATH + entityID + ".html"; 
                File htmlFile = new File(htmlFileName);
                if(!htmlFile.exists()) {
                        htmlFile.createNewFile();
                }
                
                BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(htmlFile)));
                
                template.merge(context, writer);
                
                writer.flush();
                writer.close();
                Utils.logger.info("Export Complete!");
        }

}