[856] | 1 | package de.dass_it.vanhelsing.gui;
|
---|
| 2 | import java.io.*;
|
---|
| 3 | /*
|
---|
| 4 | * Einlesen der Dateien dird_conf.c, filed_conf.c und stored_conf.c
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | public 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 | }
|
---|
[858] | 35 | if (line.startsWith("RES_ITEM")){
|
---|
| 36 | lineParts = line.split(" ");
|
---|
| 37 | name = lineParts[1].substring(0, (lineParts[1].length()-2));
|
---|
| 38 | state = "res";
|
---|
| 39 | continue;
|
---|
| 40 |
|
---|
| 41 | }
|
---|
[856] | 42 | if (line.startsWith("};")){
|
---|
| 43 | state = "";
|
---|
| 44 | continue;
|
---|
| 45 | }
|
---|
| 46 | if (line.contains("{NULL")){
|
---|
| 47 | continue;
|
---|
| 48 | }
|
---|
| 49 | if (line.split(",").length != 6){
|
---|
| 50 | continue;
|
---|
| 51 | }
|
---|
| 52 | if (state.equals("res")){
|
---|
| 53 | lineParts = line.split(",");
|
---|
| 54 | item = lineParts[0].replaceAll(" ", "");
|
---|
| 55 | item = item.replaceAll("\\{", "");
|
---|
| 56 | item = item.replaceAll("\"", "");
|
---|
| 57 | type = lineParts[1].replaceAll(" ", "");
|
---|
| 58 | type = type.replaceAll("\"", "");
|
---|
| 59 | ref = lineParts[3];
|
---|
| 60 | nec = lineParts[4];
|
---|
| 61 | def = lineParts[5].replaceAll("\\}", "");
|
---|
| 62 | System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"ref" + " = " + getReferenz(ref));
|
---|
| 63 | System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"type" + " = " +getJavaType(type));
|
---|
| 64 | System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"required" + " = " +getJavaReq(nec));
|
---|
| 65 | System.out.println(daemon+"."+getPrettyName(name)+"."+item+"."+"def" + " = " +def);
|
---|
| 66 | continue;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | ds.close();
|
---|
| 70 | } catch (Exception e){
|
---|
| 71 | e.printStackTrace();
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | private static String getReferenz(String s){
|
---|
| 76 | return s;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | private static String getJavaType(String s){
|
---|
| 80 | for (conf2type c2t : conf2type.values()){
|
---|
| 81 | if (c2t.conf.equals(s)){
|
---|
| 82 | return c2t.type;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | /*if (s.equals("store_bool") || s.equals("store_bit") ){
|
---|
| 86 | return "boolean";
|
---|
| 87 | }
|
---|
| 88 | if (s.equals("store_str") || s.equals("store_name") || s.equals("store_strname")){
|
---|
| 89 | return "String";
|
---|
| 90 | }
|
---|
| 91 | if (s.equals("store_pint32")||s.equals("store_size")){
|
---|
| 92 | return "int";
|
---|
| 93 | }
|
---|
| 94 | if (s.equals("store_dir")){
|
---|
| 95 | return "Path";
|
---|
| 96 | }
|
---|
| 97 | if (s.equals("store_password")){
|
---|
| 98 | return "Password";
|
---|
| 99 | }
|
---|
| 100 | if (s.equals("store_time")){
|
---|
| 101 | return "Date";
|
---|
| 102 | }
|
---|
| 103 | if (s.equals("store_acl")){
|
---|
| 104 | return "Acl";
|
---|
| 105 | }
|
---|
| 106 | if (s.equals("store_res")){
|
---|
| 107 | return "Resource";
|
---|
| 108 | }*/
|
---|
| 109 | //switch(s){
|
---|
| 110 | //case "store_bool" : s = "boolean"; break;
|
---|
| 111 | //case "store_pint32" : s = "int"; break;
|
---|
| 112 | //case "store_str" : s = "String";
|
---|
| 113 | //case "store_name" : s = "String"; break;
|
---|
| 114 | //case "store_dir" : s = "Path"; break;
|
---|
| 115 | //case "store_password" : s = "Password"; break;
|
---|
| 116 | //case "store_time" : s = "Date"; break;
|
---|
| 117 | //case "store_bit" : s = "boolean"; break;
|
---|
| 118 | //case "store_size" : s = "int"; break;
|
---|
| 119 | //case "store_acl" : s = "Acl"; break;
|
---|
| 120 | //case "store_strname" : s = "String"; break;
|
---|
| 121 | //case "store_res" : s = "Resource"; break;
|
---|
| 122 | //}
|
---|
| 123 | return s;
|
---|
| 124 | }
|
---|
| 125 | private static String getJavaReq(String s){
|
---|
[858] | 126 | if ( s.contains("ITEM_REQUIRED") ){
|
---|
[856] | 127 | s = "true";
|
---|
| 128 | } else {
|
---|
| 129 | s = "false";
|
---|
| 130 | }
|
---|
| 131 | return s;
|
---|
| 132 | }
|
---|
| 133 | private static String getPrettyName(String s){
|
---|
| 134 | for (prettyNames name : prettyNames.values()){
|
---|
| 135 | if (name.ugly.equals(s)){
|
---|
| 136 | return name.pretty;
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | return s;
|
---|
| 141 | }
|
---|
[858] | 142 | /**
|
---|
| 143 | * @author tgoecke
|
---|
| 144 | */
|
---|
[856] | 145 | private enum prettyNames{
|
---|
| 146 | CATALOG ("cat_items", "catalog"),
|
---|
| 147 | CLIENT ("cli_items", "client"),
|
---|
| 148 | CONSOLE ("con_items", "console"),
|
---|
| 149 | COUNTER ("counter_items", "counter"),
|
---|
| 150 | DIRECTOR ("dir_items", "director"),
|
---|
| 151 | FILESET ("fs_items", "fileset"),
|
---|
| 152 | POOL ("pool_items", "pool"),
|
---|
| 153 | RUNSCRIPT ("runscript_items", "runscript"),
|
---|
| 154 | SCHEDULE ("sch_items", "schedule"),
|
---|
[858] | 155 | STORAGE ("store_items", "storage"),
|
---|
[856] | 156 | AUTOCHANGER ("changer_items", "autochanger"),
|
---|
[858] | 157 | DEVICE ("dev_items", "device"),
|
---|
| 158 | JOB("job_items", "job"),
|
---|
[859] | 159 | MESSAGE("msgs_items","messages");
|
---|
[856] | 160 |
|
---|
| 161 | private String ugly;
|
---|
| 162 | private String pretty;
|
---|
| 163 |
|
---|
| 164 | prettyNames(String ugly, String pretty){
|
---|
| 165 | this.ugly = ugly;
|
---|
| 166 | this.pretty = pretty;
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
[858] | 169 | /**
|
---|
| 170 | * @author tgoecke
|
---|
| 171 | */
|
---|
[856] | 172 | private enum conf2type{
|
---|
| 173 | STOREPOOL ("store_pool", "boolean"),
|
---|
| 174 | STOREBIT ("store_bit","boolean"),
|
---|
| 175 | STORE_STR ("store_str","String"),
|
---|
| 176 | STORE_NAME ("store_name", "String"),
|
---|
| 177 | STORE_STRNAME ("store_strname", "String"),
|
---|
| 178 | STORE_PINT32 ("store_pint32", "int"),
|
---|
| 179 | STORE_SIZE ("store_size", "int"),
|
---|
| 180 | STORE_DIR ("store_dir", "path"),
|
---|
| 181 | STORE_PASSWORD ("store_password", "Password"),
|
---|
| 182 | STORE_TIME ("store_time", "Date"),
|
---|
| 183 | STORE_ACL ("store_acl", "Acl"),
|
---|
[859] | 184 | STORE_RES ("store_res", "Resource"),
|
---|
| 185 | STORE_MSGS ("store_msgs","String");
|
---|
[856] | 186 |
|
---|
| 187 | private String conf;
|
---|
| 188 | private String type;
|
---|
| 189 |
|
---|
| 190 | conf2type(String conf, String type){
|
---|
| 191 | this.conf = conf;
|
---|
| 192 | this.type = type;
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 | }
|
---|