Skip to content

Commit bf73a3a

Browse files
author
DGrothe-PhD
committed
JSON maintenance fix
1 parent c626801 commit bf73a3a

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

src/app/Localization.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ private String lookUpField(String key) {
1717
return "Empty key";
1818
}
1919

20-
public Localization(){
20+
public Localization() {
2121
super("/json/localized.json");
2222
charRep = new CharRep();
23-
switchTo("EN");
23+
switchTo("EN");
2424
}
2525

2626
public String Header(String key) {

src/app/ReadJson.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,27 @@
1414
class ReadJson {
1515
String resource;
1616
String[] keysArray;
17-
String jsonString;
17+
String jsonString, defaultJsonString;
1818
JSONObject obj;
1919
List<String> keysList;
2020

2121
public ReadJson(String resource) {
2222

2323
jsonString = "";
24+
defaultJsonString = "{\"EN\": {\"Close window\": \"Close window\"}}";
2425

2526
try {
2627
this.resource = resource;
2728
InputStream inputAsStream = this.getClass().getResourceAsStream(resource);
2829
jsonString = new String(inputAsStream.readAllBytes());
2930

3031
obj = new JSONObject(jsonString);
31-
32-
// standard
33-
Iterator<String> keysIt = obj.keys();
34-
keysList = new ArrayList<String>();
35-
while(keysIt.hasNext()) {
36-
String key = (String) keysIt.next();
37-
keysList.add(key);
38-
}
39-
40-
keysList.sort(null);
41-
keysArray = keysList.toArray(new String[keysList.size()]);
32+
prepareKeys();
4233
}
4334
catch (org.json.JSONException js) {
44-
System.out.println("json error");
35+
System.out.println("JSON file raised an exception. Formatting error");
36+
obj = new JSONObject(defaultJsonString);
37+
prepareKeys();
4538
}
4639
catch (Exception e) {
4740
System.out.println("JSON loader failed for "+resource);
@@ -51,6 +44,19 @@ public ReadJson(String resource) {
5144
public String[] getAll() {
5245
return keysArray;
5346
}
47+
48+
private void prepareKeys() {
49+
Iterator<String> keysIt = obj.keys();
50+
keysList = new ArrayList<String>();
51+
while(keysIt.hasNext()) {
52+
String key = (String) keysIt.next();
53+
keysList.add(key);
54+
}
55+
56+
keysList.sort(null);
57+
keysArray = keysList.toArray(new String[keysList.size()]);
58+
}
59+
5460
}
5561

5662
class SearchWords extends ReadJson {

src/app/UserDialog.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public void switchMode(int mode) {
8989
public UserDialog() {
9090
try {
9191
lang = new Localization();
92+
9293
jsonSearchWords = new SearchWords();
9394
headline = new JLabel(lang.getLocalizedText("description"));
9495

@@ -134,7 +135,8 @@ public UserDialog() {
134135
mainFrame.setVisible(true);
135136
mainFrame.requestFocus();
136137

137-
} catch (Exception awe) {
138+
}
139+
catch (Exception awe) {
138140
// intended as fallback if UI cannot be shown on system
139141
System.out.println("Application window could not be opened. Reason:");
140142
System.out.println(awe.toString());

src/json/localized.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"times": "fois",
105105
"userST": "Termes de recherche trouvés:",
106106
"wordscounted": " mots comptés.",
107-
"List of Abbreviations": "Tableau d'abréviations",
107+
"List of Abbreviations": "Tableau d'abréviations",
108108
"(S): Words beginning with same letter sequence": "(S): Les mots qui commencent avec la même suite de caractères",
109109
"(A): Anagrams or words with extra hyphens": "(A): Les anagrammes ou des mots avec plus de traits d'union"
110110
},

src/json/searchwords.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"jobOfferDE": [
3-
"reise", "Reise", "Assist", "befrist", "Teilzeit", "Kunde",
4-
"Vertrieb", "Büro", "Homeoffice", "remote", "Projekt", "Gehaltsvorstellung", "Anschreiben", "Lebenslauf",
5-
"Zeugnisse", "Bewerbungsfrist", "Startup", "einschlägig", "Studium", "Ausbildung"
3+
"Anschreiben", "Assist", "Ausbildung", "Berufserfahrung", "Bewerbungsfrist", "Büro", "Gehaltsvorstellung",
4+
"Gleitzeit", "Homeoffice", "Kunde", "Lebenslauf", "Projekt", "Reise", "Startup", "Studium", "TV-L",
5+
"Teilzeit", "Vergütung", "Vertrieb", "Zertifikate", "Zeugnisse", "befrist", "einschlägig", "reise", "remote"
66
],
77
"weatherEN": [
88
"yesterday", "tomorrow", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday",
9-
"rain", "sun", "cloudy", "clouds", "snow", "ice", "precipitation", "wet"
9+
"rain", "sun", "cloudy", "clouds", "snow", "ice", "precipitation",
10+
"wet", "frozen", "storm", "icy", "heat", "thunderstorm", "thunder"
1011
],
1112
"weatherDE": [
12-
"gestern", "morgen", "übermorgen", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag",
13-
"Regen", "Sonne", "sonnig", "wolkig", "Wolke", "Schnee", "Niederschl"
13+
"Abkühlung", "Blitze", "Dienstag", "Donnerstag", "Freitag", "Gewitter", "Glatteis", "Hitze", "Kaltfront",
14+
"Kälte", "Mittwoch", "Montag", "Niederschl", "Regen", "Samstag", "Schnee", "Sonne", "Sonntag",
15+
"Sturmböen", "Warmfront", "Wolke", "gestern", "heiß", "morgen", "sonnig", "wolkig", "überfrieren", "übermorgen"
1416
],
1517
"months": [
1618
"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September",

0 commit comments

Comments
 (0)