source: vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/ValidationParser.java@ 856

Last change on this file since 856 was 856, checked in by tobias, on Apr 1, 2010 at 2:06:38 PM

visual design change. ValidationParser added

File size: 4.9 KB
Line 
1package de.dass_it.vanhelsing.gui;
2import java.io.*;
3/*
4 * Einlesen der Dateien dird_conf.c, filed_conf.c und stored_conf.c
5 */
6
7
8public class ValidationParser{
9
10 public static void main(String args[]) {
11 try {
12 FileInputStream fs = new FileInputStream(args[1]);
13 DataInputStream ds = new DataInputStream(fs);
14 BufferedReader br = new BufferedReader(new InputStreamReader(ds));
15 String line;
16 String[] lineParts;
17 String name ="FEHLER"; //Resourcename
18 String daemon = args[0];
19
20 String item; //Resourcenitem
21 String type; //Resourcentype
22 String ref; //Referenz auf andere Resourcen
23 String nec; //Kann oder Mussfeld
24 String def; //defaultwert
25
26 String state = "";
27 while ((line = br.readLine()) != null){
28 //Zeile enthält entweder Resourcenname oder Resourcenteildefinition
29 if (line.startsWith("static RES_ITEM")){
30 lineParts = line.split(" ");
31 name = lineParts[2].substring(0, (lineParts[2].length()-2));
32 state = "res";
33 continue;
34 }
35 if (line.startsWith("};")){
36 state = "";
37 continue;
38 }
39 if (line.contains("{NULL")){
40 continue;
41 }
42 if (line.split(",").length != 6){
43 continue;
44 }
45 if (state.equals("res")){
46 lineParts = line.split(",");
47 item = lineParts[0].replaceAll(" ", "");
48 item = item.replaceAll("\\{", "");
49 item = item.replaceAll("\"", "");
50 type = lineParts[1].replaceAll(" ", "");
51 type = type.replaceAll("\"", "");
52 ref = lineParts[3];
53 nec = lineParts[4];
54 def = lineParts[5].replaceAll("\\}", "");
55 System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"ref" + " = " + getReferenz(ref));
56 System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"type" + " = " +getJavaType(type));
57 System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"required" + " = " +getJavaReq(nec));
58 System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"def" + " = " +def);
59 continue;
60 }
61 }
62 ds.close();
63 } catch (Exception e){
64 e.printStackTrace();
65 }
66 }
67
68 private static String getReferenz(String s){
69 return s;
70 }
71
72 private static String getJavaType(String s){
73 for (conf2type c2t : conf2type.values()){
74 if (c2t.conf.equals(s)){
75 return c2t.type;
76 }
77 }
78 /*if (s.equals("store_bool") || s.equals("store_bit") ){
79 return "boolean";
80 }
81 if (s.equals("store_str") || s.equals("store_name") || s.equals("store_strname")){
82 return "String";
83 }
84 if (s.equals("store_pint32")||s.equals("store_size")){
85 return "int";
86 }
87 if (s.equals("store_dir")){
88 return "Path";
89 }
90 if (s.equals("store_password")){
91 return "Password";
92 }
93 if (s.equals("store_time")){
94 return "Date";
95 }
96 if (s.equals("store_acl")){
97 return "Acl";
98 }
99 if (s.equals("store_res")){
100 return "Resource";
101 }*/
102 //switch(s){
103 //case "store_bool" : s = "boolean"; break;
104 //case "store_pint32" : s = "int"; break;
105 //case "store_str" : s = "String";
106 //case "store_name" : s = "String"; break;
107 //case "store_dir" : s = "Path"; break;
108 //case "store_password" : s = "Password"; break;
109 //case "store_time" : s = "Date"; break;
110 //case "store_bit" : s = "boolean"; break;
111 //case "store_size" : s = "int"; break;
112 //case "store_acl" : s = "Acl"; break;
113 //case "store_strname" : s = "String"; break;
114 //case "store_res" : s = "Resource"; break;
115 //}
116 return s;
117 }
118 private static String getJavaReq(String s){
119 if ( s.equals("ITEM_REQUIRED") ){
120 s = "true";
121 } else {
122 s = "false";
123 }
124 return s;
125 }
126 private static String getPrettyName(String s){
127 for (prettyNames name : prettyNames.values()){
128 if (name.ugly.equals(s)){
129 return name.pretty;
130 }
131 }
132
133 return s;
134 }
135 private enum prettyNames{
136 CATALOG ("cat_items", "catalog"),
137 CLIENT ("cli_items", "client"),
138 CONSOLE ("con_items", "console"),
139 COUNTER ("counter_items", "counter"),
140 DIRECTOR ("dir_items", "director"),
141 FILESET ("fs_items", "fileset"),
142 POOL ("pool_items", "pool"),
143 RUNSCRIPT ("runscript_items", "runscript"),
144 SCHEDULE ("sch_items", "schedule"),
145 STORAGEDAEMON ("store_items", "storagedaemon"),
146 AUTOCHANGER ("changer_items", "autochanger"),
147 DEVICE ("dev_items", "device");
148
149 private String ugly;
150 private String pretty;
151
152 prettyNames(String ugly, String pretty){
153 this.ugly = ugly;
154 this.pretty = pretty;
155 }
156 }
157 private enum conf2type{
158 STOREPOOL ("store_pool", "boolean"),
159 STOREBIT ("store_bit","boolean"),
160 STORE_STR ("store_str","String"),
161 STORE_NAME ("store_name", "String"),
162 STORE_STRNAME ("store_strname", "String"),
163 STORE_PINT32 ("store_pint32", "int"),
164 STORE_SIZE ("store_size", "int"),
165 STORE_DIR ("store_dir", "path"),
166 STORE_PASSWORD ("store_password", "Password"),
167 STORE_TIME ("store_time", "Date"),
168 STORE_ACL ("store_acl", "Acl"),
169 STORE_RES ("store_res", "Resource");
170
171 private String conf;
172 private String type;
173
174 conf2type(String conf, String type){
175 this.conf = conf;
176 this.type = type;
177 }
178 }
179}
Note: See TracBrowser for help on using the repository browser.