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 | 4 | super(env); |
37 | 4 | template = env.getProperties().getProperty("muleDocTemplate"); |
38 | 4 | if (template == null) |
39 | |
{ |
40 | 4 | template = DEFAULT_MULE_TEMPLATE; |
41 | |
} |
42 | 4 | } |
43 | |
|
44 | |
public void postRender(GraphEnvironment env, Map context, Graph graph) |
45 | |
{ |
46 | |
try |
47 | |
{ |
48 | |
|
49 | 4 | VelocityContext velocityContext = new VelocityContext(); |
50 | |
|
51 | 4 | for (Iterator iter = context.keySet().iterator(); iter.hasNext();) |
52 | |
{ |
53 | 24 | String key = (String) iter.next(); |
54 | 24 | String value = (String) context.get(key); |
55 | 24 | velocityContext.put(key, value); |
56 | 24 | } |
57 | |
|
58 | 4 | velocityContext.put("graph", graph); |
59 | 4 | Template t = getVe().getTemplate(template); |
60 | 4 | File file = new File(context.get("htmlFileName").toString()); |
61 | 4 | FileWriter writer = new FileWriter(file); |
62 | |
|
63 | 4 | env.log("generating " + file); |
64 | |
|
65 | 4 | t.merge(velocityContext, writer); |
66 | 4 | writer.flush(); |
67 | 4 | writer.close(); |
68 | |
} |
69 | 0 | catch (Exception e) |
70 | |
{ |
71 | 0 | e.printStackTrace(); |
72 | 4 | } |
73 | 4 | } |
74 | |
} |