Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
22 naveen 1
/**
2
 * 
3
 */
4
package in.shop2020.ui.util;
5
 
6
import java.io.BufferedWriter;
7
import java.io.File;
8
import java.io.FileOutputStream;
9
import java.io.OutputStreamWriter;
10
 
11
import org.apache.velocity.Template;
12
import org.apache.velocity.VelocityContext;
13
import org.apache.velocity.app.Velocity;
14
 
15
import in.shop2020.metamodel.core.Entity;
16
import in.shop2020.metamodel.definitions.Catalog;
17
import in.shop2020.metamodel.definitions.EntityContainer;
18
import in.shop2020.util.Utils;
19
 
20
/**
21
 * @author naveen
22
 *
23
 */
24
public class VUI {
25
	public static String EXPORT_HTML_PATH 
26
		= "/home/naveen/workspace/eclipse/webapp/export/html/";
27
 
28
	/**
29
	 * @param args
30
	 */
31
	public static void main(String[] args) throws Exception {
32
		// Setup
33
		Velocity.init("src/in/shop2020/ui/velocity/velocity.properties");
34
		VelocityContext context = new VelocityContext();
35
 
36
		long entityID = Long.parseLong(args[0]);
37
		String templateFile = args[1];
38
 
39
		EntityContainer entContainer = 
40
			Catalog.getInstance().getEntityContainer();
41
 
42
		Entity entity = entContainer.getEntity(entityID);
43
		Utils.logger.info("entity=" + entity);
44
 
45
		context.put("entity", entity);
46
		Template template = Velocity.getTemplate(templateFile);
47
 
48
		String htmlFileName = EXPORT_HTML_PATH + entityID + ".html"; 
49
		File htmlFile = new File(htmlFileName);
50
		if(!htmlFile.exists()) {
51
			htmlFile.createNewFile();
52
		}
53
 
54
		BufferedWriter writer = new BufferedWriter(
55
		    new OutputStreamWriter(new FileOutputStream(htmlFile)));
56
 
57
		template.merge(context, writer);
58
 
59
		writer.flush();
60
		writer.close();
61
		Utils.logger.info("Export Complete!");
62
	}
63
 
64
}