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 super(env);
33 }
34
35 protected void doRendering(GraphEnvironment env, File[] htmlFiles, String template, String targetFile)
36 {
37 try
38 {
39 setEnv(env);
40 VelocityContext velocityContext = new VelocityContext();
41
42 velocityContext.put("fileList", Arrays.asList(htmlFiles));
43
44 Template t = getVe().getTemplate(template);
45 File file = new File(targetFile);
46 FileWriter writer = new FileWriter(file);
47
48 env.log("generating " + file);
49
50 t.merge(velocityContext, writer);
51 writer.flush();
52 writer.close();
53 }
54 catch (Exception e)
55 {
56 e.printStackTrace();
57 }
58 }
59
60 protected File[] getFiles(final GraphConfig config, final String extension)
61 {
62 File[] htmlFiles = config.getOutputDirectory().listFiles(new FilenameFilter()
63 {
64 public boolean accept(File dir, String name)
65 {
66 if (name.toLowerCase().equals("index.html"))
67 {
68 return false;
69 }
70 else
71 {
72 if (name.toLowerCase().equals("gallery.html"))
73 {
74 return false;
75 }
76 else
77 {
78 return name.endsWith(extension);
79 }
80 }
81 }
82 });
83 return htmlFiles;
84 }
85
86 public void init(RuntimeServices arg0) throws Exception
87 {
88
89
90 }
91
92 public void logVelocityMessage(int arg0, String arg1)
93 {
94 if (getEnv() != null)
95 {
96 getEnv().log(arg1);
97 }
98
99 }
100 }