1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tools.visualizer.postgraphers; |
12 | |
|
13 | |
import org.mule.tools.visualizer.components.PostGrapher; |
14 | |
import org.mule.tools.visualizer.config.GraphConfig; |
15 | |
import org.mule.tools.visualizer.config.GraphEnvironment; |
16 | |
import org.mule.tools.visualizer.config.VelocitySupport; |
17 | |
|
18 | |
import java.io.File; |
19 | |
import java.io.FileWriter; |
20 | |
import java.io.FilenameFilter; |
21 | |
import java.util.Arrays; |
22 | |
|
23 | |
import org.apache.velocity.Template; |
24 | |
import org.apache.velocity.VelocityContext; |
25 | |
import org.apache.velocity.runtime.RuntimeServices; |
26 | |
|
27 | |
public abstract class AbstractIndexer extends VelocitySupport implements PostGrapher |
28 | |
{ |
29 | |
|
30 | |
protected AbstractIndexer(GraphEnvironment env) throws Exception |
31 | |
{ |
32 | 8 | super(env); |
33 | 8 | } |
34 | |
|
35 | |
protected void doRendering(GraphEnvironment env, File[] htmlFiles, String template, String targetFile) |
36 | |
{ |
37 | |
try |
38 | |
{ |
39 | 8 | setEnv(env); |
40 | 8 | VelocityContext velocityContext = new VelocityContext(); |
41 | |
|
42 | 8 | velocityContext.put("fileList", Arrays.asList(htmlFiles)); |
43 | |
|
44 | 8 | Template t = getVe().getTemplate(template); |
45 | 8 | File file = new File(targetFile); |
46 | 8 | FileWriter writer = new FileWriter(file); |
47 | |
|
48 | 8 | env.log("generating " + file); |
49 | |
|
50 | 8 | t.merge(velocityContext, writer); |
51 | 8 | writer.flush(); |
52 | 8 | writer.close(); |
53 | |
} |
54 | 0 | catch (Exception e) |
55 | |
{ |
56 | 0 | e.printStackTrace(); |
57 | 8 | } |
58 | 8 | } |
59 | |
|
60 | |
protected File[] getFiles(final GraphConfig config, final String extension) |
61 | |
{ |
62 | 8 | File[] htmlFiles = config.getOutputDirectory().listFiles(new FilenameFilter() |
63 | |
{ |
64 | 8 | public boolean accept(File dir, String name) |
65 | |
{ |
66 | 104 | if (name.toLowerCase().equals("index.html")) |
67 | |
{ |
68 | 8 | return false; |
69 | |
} |
70 | |
else |
71 | |
{ |
72 | 96 | if (name.toLowerCase().equals("gallery.html")) |
73 | |
{ |
74 | 8 | return false; |
75 | |
} |
76 | |
else |
77 | |
{ |
78 | 88 | return name.endsWith(extension); |
79 | |
} |
80 | |
} |
81 | |
} |
82 | |
}); |
83 | 8 | return htmlFiles; |
84 | |
} |
85 | |
|
86 | |
public void init(RuntimeServices arg0) throws Exception |
87 | |
{ |
88 | |
|
89 | |
|
90 | 0 | } |
91 | |
|
92 | |
public void logVelocityMessage(int arg0, String arg1) |
93 | |
{ |
94 | 0 | if (getEnv() != null) |
95 | |
{ |
96 | 0 | getEnv().log(arg1); |
97 | |
} |
98 | |
|
99 | 0 | } |
100 | |
} |