Revize 02390102
Přidáno uživatelem Jan Havlíček před asi 5 roky(ů)
project/Deserializer/src/Converter.java | ||
---|---|---|
4 | 4 |
import java.io.IOException; |
5 | 5 |
import java.io.OutputStream; |
6 | 6 |
import java.io.PrintStream; |
7 |
import java.util.HashMap; |
|
7 | 8 |
import java.util.List; |
9 |
import java.util.Map; |
|
8 | 10 |
|
9 | 11 |
import jdeserialize.content; |
10 | 12 |
import jdeserialize.jdeserialize; |
11 | 13 |
|
12 | 14 |
public class Converter extends Thread { |
13 |
|
|
14 | 15 |
private Deserializer main; |
15 | 16 |
|
16 | 17 |
private File input; |
17 | 18 |
private File output; |
19 |
|
|
20 |
//Key as enum? |
|
21 |
private HashMap<String, String> html = new HashMap<String, String>(); |
|
22 |
private HashMap<String, String> json = new HashMap<String, String>(); |
|
18 | 23 |
|
19 | 24 |
public Converter(Deserializer main, File inputFilename, File outputFilename) { |
20 | 25 |
this.main = main; |
21 | 26 |
this.input = inputFilename; |
22 | 27 |
this.output = outputFilename; |
28 |
|
|
29 |
fillInTestingDictionaries(); |
|
30 |
} |
|
31 |
|
|
32 |
private void fillInTestingDictionaries() |
|
33 |
{ |
|
34 |
html.put("indent", ""); |
|
35 |
html.put("lineBreak", ""); |
|
36 |
html.put("classCol", ""); |
|
37 |
html.put("fieldCol", ""); |
|
38 |
html.put("valCol", ""); |
|
39 |
html.put("keywordCol", ""); |
|
40 |
|
|
41 |
json.put("indent", "\t"); |
|
42 |
json.put("lineBreak", "\n"); |
|
43 |
json.put("classCol", ""); |
|
44 |
json.put("fieldCol", ""); |
|
45 |
json.put("valCol", ""); |
|
46 |
json.put("keywordCol", ""); |
|
23 | 47 |
} |
24 | 48 |
|
25 | 49 |
@Override |
... | ... | |
72 | 96 |
//replace VS parametr |
73 | 97 |
//Pustit 2X s parametrem nenabori vnitrni data (kde muzou byt html znacky) |
74 | 98 |
//Ciste HTML / Cisty JSON |
75 |
json += cnt.toJson("", null); |
|
99 |
json += cnt.toJson("", null, this.json);
|
|
76 | 100 |
} |
77 | 101 |
} |
78 | 102 |
|
project/Deserializer/src/jdeserialize/arrayobj.java | ||
---|---|---|
32 | 32 |
this.data = data; |
33 | 33 |
} |
34 | 34 |
|
35 |
public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata) { |
|
35 |
public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, Map<String, String> formatting) {
|
|
36 | 36 |
StringBuilder sb = new StringBuilder(); |
37 | 37 |
sb.append("[ "); |
38 | 38 |
|
39 | 39 |
for (Object el : this.data) { |
40 | 40 |
if (el != null) { |
41 | 41 |
if (el instanceof content) { |
42 |
sb.append(((content) el).toJson(indentation, fielddata)); |
|
42 |
sb.append(((content) el).toJson(indentation, fielddata, formatting));
|
|
43 | 43 |
}else{ |
44 | 44 |
sb.append(el.toString()); |
45 | 45 |
} |
project/Deserializer/src/jdeserialize/classdesc.java | ||
---|---|---|
224 | 224 |
} |
225 | 225 |
} |
226 | 226 |
|
227 |
public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata) |
|
227 |
public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, Map<String, String> formatting)
|
|
228 | 228 |
{ |
229 | 229 |
StringBuffer sb = new StringBuffer(); |
230 | 230 |
String val = ""; |
231 | 231 |
|
232 |
sb.append(indentation).append("{\n");
|
|
232 |
sb.append(indentation).append("{" + formatting.get("lineBreak"));
|
|
233 | 233 |
|
234 |
indentation += "\t";
|
|
234 |
indentation += formatting.get("indent");
|
|
235 | 235 |
|
236 | 236 |
// ClassName |
237 | 237 |
sb.append(indentation).append("class ").append(this.name); |
... | ... | |
248 | 248 |
} |
249 | 249 |
sb.append(" : {"); // ending of first line |
250 | 250 |
|
251 |
indentation += "\t";
|
|
251 |
indentation += formatting.get("indent");
|
|
252 | 252 |
|
253 | 253 |
for (field f : this.fields) { |
254 | 254 |
// v this.fielddata najit element, jehoz key == classdesc |
... | ... | |
258 | 258 |
|
259 | 259 |
if(locVal instanceof content) |
260 | 260 |
{ |
261 |
val = ((content)locVal).toJson(indentation, fielddata); |
|
261 |
val = ((content)locVal).toJson(indentation, fielddata, formatting);
|
|
262 | 262 |
} |
263 | 263 |
else { |
264 | 264 |
val = locVal.toString(); |
265 | 265 |
} |
266 | 266 |
|
267 |
sb.append("\n").append(indentation);
|
|
267 |
sb.append(formatting.get("lineBreak")).append(indentation);
|
|
268 | 268 |
sb.append("\"").append(f.name).append("\""); |
269 | 269 |
sb.append(" : "); |
270 | 270 |
sb.append(val); |
... | ... | |
275 | 275 |
} |
276 | 276 |
indentation = indentation.substring(0, indentation.length() - 1); |
277 | 277 |
|
278 |
sb.append("\n").append(indentation).append("}");
|
|
278 |
sb.append(formatting.get("lineBreak")).append(indentation).append("}");
|
|
279 | 279 |
|
280 | 280 |
if(this.superclass != null) |
281 | 281 |
{ |
282 | 282 |
indentation = indentation.substring(0, indentation.length() - 1); |
283 |
sb.append("\n}");
|
|
284 |
sb.append(",\n");
|
|
285 |
sb.append(this.superclass.toJson(indentation, fielddata)); |
|
283 |
sb.append(formatting.get("lineBreak")).append("}");
|
|
284 |
sb.append("," + formatting.get("lineBreak"));
|
|
285 |
sb.append(this.superclass.toJson(indentation, fielddata, formatting));
|
|
286 | 286 |
} |
287 | 287 |
else |
288 | 288 |
{ |
289 | 289 |
indentation = indentation.substring(0, indentation.length() - 1); |
290 |
sb.append("\n").append(indentation).append("}");
|
|
290 |
sb.append(formatting.get("lineBreak")).append(indentation).append("}");
|
|
291 | 291 |
} |
292 | 292 |
|
293 | 293 |
return sb.toString(); |
project/Deserializer/src/jdeserialize/content.java | ||
---|---|---|
1 | 1 |
package jdeserialize; |
2 | 2 |
|
3 |
import java.util.HashMap; |
|
3 | 4 |
import java.util.Map; |
4 | 5 |
|
5 | 6 |
/** |
... | ... | |
68 | 69 |
*/ |
69 | 70 |
public void setIsExceptionObject(boolean value); |
70 | 71 |
|
71 |
public String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata); |
|
72 |
public String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, Map<String, String> formatting);
|
|
72 | 73 |
} |
73 | 74 |
|
project/Deserializer/src/jdeserialize/contentbase.java | ||
---|---|---|
27 | 27 |
public void validate() throws ValidityException { |
28 | 28 |
} |
29 | 29 |
|
30 |
public @Override String toJson(String indetation, Map<classdesc, Map<field, Object>> fielddata) |
|
30 |
public @Override String toJson(String indetation, Map<classdesc, Map<field, Object>> fielddata, Map<String, String> formatting)
|
|
31 | 31 |
{ |
32 | 32 |
return this.toString(); |
33 | 33 |
} |
project/Deserializer/src/jdeserialize/enumobj.java | ||
---|---|---|
34 | 34 |
this.classdesc = cd; |
35 | 35 |
this.value = so; |
36 | 36 |
} |
37 |
public @Override String toJson(String indetation, Map<classdesc, Map<field, Object>> fielddata) { |
|
37 |
public @Override String toJson(String indetation, Map<classdesc, Map<field, Object>> fielddata, Map<String, String> formatting) {
|
|
38 | 38 |
return this.value.value; |
39 | 39 |
} |
40 | 40 |
|
project/Deserializer/src/jdeserialize/instance.java | ||
---|---|---|
26 | 26 |
this.fielddata = new HashMap<classdesc, Map<field, Object>>(); |
27 | 27 |
} |
28 | 28 |
|
29 |
public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata) |
|
29 |
public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, Map<String, String> formatting)
|
|
30 | 30 |
{ |
31 | 31 |
StringBuffer sb = new StringBuffer(); |
32 | 32 |
String val = ""; |
33 | 33 |
|
34 |
sb.append("{\n");
|
|
34 |
sb.append("{" + formatting.get("lineBreak"));
|
|
35 | 35 |
|
36 |
indentation += "\t";
|
|
36 |
indentation += formatting.get("indent");
|
|
37 | 37 |
|
38 | 38 |
// ClassName |
39 | 39 |
sb.append(indentation).append("class ").append(classdesc.name); |
... | ... | |
50 | 50 |
} |
51 | 51 |
sb.append(" : {"); // ending of first line |
52 | 52 |
|
53 |
indentation += "\t";
|
|
53 |
indentation += formatting.get("indent");
|
|
54 | 54 |
|
55 | 55 |
for (field f : classdesc.fields) { |
56 | 56 |
// v this.fielddata najit element, jehoz key == classdesc |
... | ... | |
60 | 60 |
|
61 | 61 |
if(locVal instanceof content) |
62 | 62 |
{ |
63 |
val = ((content)locVal).toJson(indentation, this.fielddata); |
|
63 |
val = ((content)locVal).toJson(indentation, this.fielddata, formatting);
|
|
64 | 64 |
} |
65 | 65 |
else { |
66 | 66 |
val = locVal.toString(); |
67 | 67 |
} |
68 | 68 |
|
69 |
sb.append("\n").append(indentation);
|
|
69 |
sb.append(formatting.get("lineBreak")).append(indentation);
|
|
70 | 70 |
sb.append("\"").append(f.name).append("\""); |
71 | 71 |
sb.append(" : "); |
72 | 72 |
sb.append(val); |
... | ... | |
77 | 77 |
} |
78 | 78 |
indentation = indentation.substring(0, indentation.length() - 1); |
79 | 79 |
|
80 |
sb.append("\n").append(indentation).append("}");
|
|
80 |
sb.append(formatting.get("lineBreak")).append(indentation).append("}");
|
|
81 | 81 |
|
82 | 82 |
if(classdesc.superclass != null) |
83 | 83 |
{ |
84 | 84 |
indentation = indentation.substring(0, indentation.length() - 1); |
85 |
sb.append("\n}");
|
|
86 |
sb.append(",\n");
|
|
87 |
sb.append(classdesc.superclass.toJson(indentation, this.fielddata)); |
|
85 |
sb.append(formatting.get("lineBreak") + "}");
|
|
86 |
sb.append(",").append(formatting.get("lineBreak"));
|
|
87 |
sb.append(classdesc.superclass.toJson(indentation, this.fielddata, formatting));
|
|
88 | 88 |
} |
89 | 89 |
else |
90 | 90 |
{ |
91 | 91 |
indentation = indentation.substring(0, indentation.length() - 1); |
92 |
sb.append("\n").append(indentation).append("}");
|
|
92 |
sb.append(formatting.get("lineBreak")).append(indentation).append("}");
|
|
93 | 93 |
} |
94 | 94 |
|
95 | 95 |
return sb.toString(); |
project/Deserializer/src/jdeserialize/stringobj.java | ||
---|---|---|
18 | 18 |
return x; |
19 | 19 |
} |
20 | 20 |
|
21 |
public @Override String toJson(String indetation, Map<classdesc, Map<field, Object>> fielddata) |
|
21 |
public @Override String toJson(String indetation, Map<classdesc, Map<field, Object>> fielddata, Map<String, String> formatting)
|
|
22 | 22 |
{ |
23 | 23 |
return "\"" + this.value + "\""; |
24 | 24 |
} |
Také k dispozici: Unified diff
#re#7868 Test - JSON format observed.