| 2319 |
rajveer |
1 |
package in.shop2020.ui.util;
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
import in.shop2020.metamodel.core.Helpdoc;
|
|
|
5 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
6 |
import in.shop2020.util.Utils;
|
|
|
7 |
|
|
|
8 |
import java.io.BufferedWriter;
|
|
|
9 |
import java.io.File;
|
|
|
10 |
import java.io.FileOutputStream;
|
|
|
11 |
import java.io.OutputStreamWriter;
|
|
|
12 |
import java.util.HashMap;
|
|
|
13 |
import java.util.LinkedHashMap;
|
|
|
14 |
import java.util.Map;
|
| 2367 |
rajveer |
15 |
import java.util.TreeMap;
|
| 2319 |
rajveer |
16 |
|
|
|
17 |
import org.apache.velocity.Template;
|
|
|
18 |
import org.apache.velocity.VelocityContext;
|
|
|
19 |
import org.apache.velocity.app.Velocity;
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Command line utility to generate glossary files for our site
|
|
|
24 |
*
|
|
|
25 |
* @author rajveer
|
|
|
26 |
*
|
|
|
27 |
*/
|
|
|
28 |
public class HelpdocsGenerator {
|
|
|
29 |
public static void main(String[] args) throws Exception {
|
|
|
30 |
HelpdocsGenerator generator = new HelpdocsGenerator();
|
|
|
31 |
generator.generateHelpdocFiles();
|
|
|
32 |
generator.generateGlossaryFile();
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
private void generateGlossaryFile() {
|
|
|
36 |
try {
|
|
|
37 |
Map<Long, Helpdoc> helpdocs = CreationUtils.getHelpdocs();
|
|
|
38 |
VelocityContext context = new VelocityContext();
|
|
|
39 |
String templateFile = Utils.VTL_SRC_PATH + "glossary.vm";
|
|
|
40 |
Map<String, Map<String, String>> params = new LinkedHashMap<String, Map<String,String>>();
|
| 2367 |
rajveer |
41 |
Map<String, String> section1 = new TreeMap<String, String>();
|
|
|
42 |
Map<String, String> section2 = new TreeMap<String, String>();
|
|
|
43 |
Map<String, String> section3 = new TreeMap<String, String>();
|
|
|
44 |
Map<String, String> section4 = new TreeMap<String, String>();
|
| 2319 |
rajveer |
45 |
params.put("0 - 9", section1);
|
|
|
46 |
params.put("A - H", section2);
|
|
|
47 |
params.put("I - P", section3);
|
|
|
48 |
params.put("Q - Z", section4);
|
|
|
49 |
for(Helpdoc helpdoc: helpdocs.values()){
|
|
|
50 |
String docname = helpdoc.getName();
|
|
|
51 |
char firstChar = docname.toUpperCase().charAt(0);
|
|
|
52 |
if(firstChar >= '0' && firstChar <= '9'){
|
|
|
53 |
section1.put(docname, getFileName(docname));
|
|
|
54 |
}
|
|
|
55 |
if(firstChar >= 'A' && firstChar <= 'H'){
|
|
|
56 |
section2.put(docname, getFileName(docname));
|
|
|
57 |
}
|
|
|
58 |
if(firstChar >= 'I' && firstChar <= 'P'){
|
|
|
59 |
section3.put(docname, getFileName(docname));
|
|
|
60 |
}
|
|
|
61 |
if(firstChar >= 'Q' && firstChar <= 'Z'){
|
|
|
62 |
section4.put(docname, getFileName(docname));
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
context.put("params", params);
|
|
|
66 |
String exportFileName = Utils.EXPORT_HELPDOCS_PATH + "glossary";
|
|
|
67 |
File exportFile = new File(exportFileName);
|
|
|
68 |
if(!exportFile.exists()) {
|
|
|
69 |
exportFile.createNewFile();
|
|
|
70 |
}
|
|
|
71 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
72 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
73 |
template.merge(context, writer);
|
|
|
74 |
writer.flush();
|
|
|
75 |
writer.close();
|
|
|
76 |
} catch (Exception e) {
|
|
|
77 |
// TODO Auto-generated catch block
|
|
|
78 |
e.printStackTrace();
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
private void generateHelpdocFiles() {
|
|
|
83 |
try {
|
|
|
84 |
Map<Long, Helpdoc> helpdocs = CreationUtils.getHelpdocs();
|
|
|
85 |
VelocityContext context = new VelocityContext();
|
|
|
86 |
String templateFile = Utils.VTL_SRC_PATH + "helpdoc.vm";
|
|
|
87 |
for(Helpdoc helpdoc: helpdocs.values()){
|
|
|
88 |
context.put("helpdoc", helpdoc);
|
|
|
89 |
String exportFileName = Utils.EXPORT_HELPDOCS_PATH + getFileName(helpdoc.getName());
|
|
|
90 |
File exportFile = new File(exportFileName);
|
|
|
91 |
if(!exportFile.exists()) {
|
|
|
92 |
exportFile.createNewFile();
|
|
|
93 |
}
|
|
|
94 |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile)));
|
|
|
95 |
Template template = Velocity.getTemplate(templateFile);
|
|
|
96 |
template.merge(context, writer);
|
|
|
97 |
writer.flush();
|
|
|
98 |
writer.close();
|
|
|
99 |
}
|
|
|
100 |
} catch (Exception e) {
|
|
|
101 |
// TODO Auto-generated catch block
|
|
|
102 |
e.printStackTrace();
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
private String getFileName(String name){
|
|
|
107 |
return name.toLowerCase().replace(' ', '-').replaceAll("/", "");
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
}
|