1
2
3
4
5
6
7
8
9
10
11 package org.mule.tools.visualizer.postrenderers;
12
13 import org.mule.tools.visualizer.components.PostRenderer;
14 import org.mule.tools.visualizer.config.GraphEnvironment;
15 import org.mule.tools.visualizer.config.VelocitySupport;
16
17 import com.oy.shared.lm.graph.Graph;
18
19 import java.io.File;
20 import java.io.FileWriter;
21 import java.util.Iterator;
22 import java.util.Map;
23
24 import org.apache.velocity.Template;
25 import org.apache.velocity.VelocityContext;
26
27 public class MuleDocPostRenderer extends VelocitySupport implements PostRenderer
28 {
29
30 public static final String DEFAULT_MULE_TEMPLATE = "template/mule-config.vm";
31
32 private String template;
33
34 public MuleDocPostRenderer(GraphEnvironment env) throws Exception
35 {
36 super(env);
37 template = env.getProperties().getProperty("muleDocTemplate");
38 if (template == null)
39 {
40 template = DEFAULT_MULE_TEMPLATE;
41 }
42 }
43
44 public void postRender(GraphEnvironment env, Map context, Graph graph)
45 {
46 try
47 {
48
49 VelocityContext velocityContext = new VelocityContext();
50
51 for (Iterator iter = context.keySet().iterator(); iter.hasNext();)
52 {
53 String key = (String) iter.next();
54 String value = (String) context.get(key);
55 velocityContext.put(key, value);
56 }
57
58 velocityContext.put("graph", graph);
59 Template t = getVe().getTemplate(template);
60 File file = new File(context.get("htmlFileName").toString());
61 FileWriter writer = new FileWriter(file);
62
63 env.log("generating " + file);
64
65 t.merge(velocityContext, writer);
66 writer.flush();
67 writer.close();
68 }
69 catch (Exception e)
70 {
71 e.printStackTrace();
72 }
73 }
74 }