| 17 |
naveen |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.metamodel.util;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
7 |
import in.shop2020.metamodel.definitions.Category;
|
|
|
8 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
9 |
|
|
|
10 |
import org.apache.commons.lang.ArrayUtils;
|
|
|
11 |
import org.apache.commons.lang.StringUtils;
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* CN - Content Tool
|
|
|
15 |
* Imports and exports content. Validates against content model
|
|
|
16 |
*
|
|
|
17 |
* @author naveen
|
|
|
18 |
*
|
|
|
19 |
*/
|
|
|
20 |
public class CN {
|
|
|
21 |
public static final String CONTENT_SRC_TXT_PATH =
|
|
|
22 |
"/home/naveen/workspace/eclipse/webapp/src/content/txt/";
|
|
|
23 |
public static final String CONTENT_SRC_HTML_PATH =
|
|
|
24 |
"/home/naveen/workspace/eclipse/webapp/src/content/html/";
|
|
|
25 |
public static final String CONTENT_SRC_XML_PATH =
|
|
|
26 |
"/home/naveen/workspace/eclipse/webapp/src/content/xml/";
|
|
|
27 |
public static final String CONTENT_DB_PATH =
|
|
|
28 |
"/home/naveen/workspace/eclipse/webapp/db/entities/";
|
|
|
29 |
|
|
|
30 |
// Known patterns
|
|
|
31 |
public static final String PATTERN_LEVEL_1 = "* ";
|
|
|
32 |
public static final String PATTERN_LEVEL_2 = " * ";
|
|
|
33 |
public static final String PATTERN_LEVEL_3 = " * ";
|
|
|
34 |
public static final String PATTERN_LEVEL_4 = " * ";
|
|
|
35 |
|
|
|
36 |
private long categoryID;
|
|
|
37 |
private String srcFile;
|
|
|
38 |
private String dbFile;
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* @param args
|
|
|
42 |
*/
|
|
|
43 |
public static void main(String[] args) throws Exception {
|
|
|
44 |
String[] commands = new String[] {"show", "import"};
|
|
|
45 |
|
|
|
46 |
String usage = "Usage: CN ["+ StringUtils.join(commands, "|") +
|
|
|
47 |
"] {Category ID} {Content file name}\n" +
|
|
|
48 |
"Note:Only text files for now";
|
|
|
49 |
|
|
|
50 |
if(args.length < 3) {
|
|
|
51 |
System.out.println(usage);
|
|
|
52 |
System.exit(-1);
|
|
|
53 |
}
|
|
|
54 |
System.out.println("CN "+ args[0] + " " + args[1]+ " " + args[2]);
|
|
|
55 |
String inputCommand = args[0];
|
|
|
56 |
String inputCategoryID = args[1];
|
|
|
57 |
String inputFilename = args[2];
|
|
|
58 |
|
|
|
59 |
if(!ArrayUtils.contains(commands, inputCommand)) {
|
|
|
60 |
System.out.println(usage);
|
|
|
61 |
System.exit(-1);
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
long categoryID = new Long(inputCategoryID).longValue();
|
|
|
65 |
CN cn = new CN(categoryID, inputFilename);
|
|
|
66 |
if(inputCommand.equals("import")) {
|
|
|
67 |
cn.importEntity();
|
|
|
68 |
}
|
|
|
69 |
else if(inputCommand.equals("show")) {
|
|
|
70 |
cn.showEntity();
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
/**
|
|
|
75 |
*
|
|
|
76 |
* @param categoryID
|
|
|
77 |
* @param fileName
|
|
|
78 |
*/
|
|
|
79 |
public CN(long categoryID, String fileName) {
|
|
|
80 |
this.categoryID = categoryID;
|
|
|
81 |
|
|
|
82 |
this.srcFile = CONTENT_SRC_TXT_PATH + fileName + ".txt";
|
|
|
83 |
this.dbFile = CONTENT_DB_PATH + "entities" + ".ser";
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
*
|
|
|
88 |
* @throws Exception
|
|
|
89 |
*/
|
|
|
90 |
public void importEntity() throws Exception {
|
|
|
91 |
System.out.println("importEntity()");
|
|
|
92 |
|
|
|
93 |
DefinitionsContainer allDefs =
|
|
|
94 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
95 |
|
|
|
96 |
Category category = allDefs.getCategory(this.categoryID);
|
|
|
97 |
|
|
|
98 |
System.out.println(category);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
/**
|
|
|
102 |
*
|
|
|
103 |
* @throws Exception
|
|
|
104 |
*/
|
|
|
105 |
public void showEntity() throws Exception {
|
|
|
106 |
System.out.println("showEntity()");
|
|
|
107 |
}
|
|
|
108 |
}
|