Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ jobs:
./gradlew build -x test
cp build/libs/i18n-patterns-core-0.11.0.jar java-client-sample/lib
cp build/libs/i18n-patterns-core-0.11.0.jar jarpath
# temporary fix, will delete after java client is updated
curl https://repo1.maven.org/maven2/org/json/json/20250107/json-20250107.jar -o java-client-sample/lib/json-20250107.jar
cp java-client-sample/lib/json-20250107.jar jarpath
ls java-client-sample/lib jarpath
cd java-client-sample
sudo chmod +x gradlew
./gradlew build -x test
Expand Down
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Copyright 2019-2023 VMware, Inc.
//Copyright 2019-2025 VMware, Inc.
//SPDX-License-Identifier: EPL-2.0
apply plugin: 'java'
apply plugin: "jacoco"
Expand Down Expand Up @@ -54,9 +54,7 @@ repositories {

dependencies {
implementation("commons-collections:commons-collections:3.2.2")
implementation("com.googlecode.json-simple:json-simple:1.1.1"){
exclude group: 'junit'
}
implementation("org.json:json:20250107")

implementation("com.fasterxml.jackson.core:jackson-databind:2.16.0")
implementation("commons-io:commons-io:2.13.0")
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/vmware/i18n/utils/CLDRUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 VMware, Inc.
* Copyright 2019-2025 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.i18n.utils;
Expand Down Expand Up @@ -31,8 +31,8 @@
import com.vmware.i18n.common.OfficialStatusEnum;
import com.vmware.i18n.utils.timezone.CldrTimeZoneUtils;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -1007,8 +1007,10 @@ public static void regionDataExtract() {
String locale = null;
if (!CommonUtil.isEmpty(itemMap.get(Constants.LANGUAGE_POPULATION))) {
Map<String, String> maxPopulationLanguage = new HashMap<>();
Map<String, Object> map = JSONUtil
.string2SortMap(itemMap.get(Constants.LANGUAGE_POPULATION).toString());
Map<String, Object> map = null;
// map = JSONUtil.string2SortMap(new ObjectMapper().writeValueAsString(itemMap.get(Constants.LANGUAGE_POPULATION)));
JSONObject jsonObject = new JSONObject((Map<String, Object>) itemMap.get(Constants.LANGUAGE_POPULATION));
map = JSONUtil.string2SortMap(jsonObject.toString());
for (Map.Entry<String, Object> item : map.entrySet()) {
Map<String, String> data = (Map<String, String>) item.getValue();
boolean isMaxLanguage = getMaxLanguage(maxPopulationLanguage, data);
Expand Down
60 changes: 26 additions & 34 deletions src/main/java/com/vmware/i18n/utils/JSONUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 VMware, Inc.
* Copyright 2019-2025 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.i18n.utils;
Expand All @@ -9,13 +9,11 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.TreeMap;

import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ContainerFactory;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.json.JSONObject;
import org.json.JSONException;

public class JSONUtil {

Expand All @@ -25,29 +23,18 @@
* @return Map<String, Object> obj
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> getMapFromJson(String json) {
JSONParser parser = new JSONParser();
ContainerFactory containerFactory = getContainerFactory();
Map<String, Object> result = null;
try {
result = (Map<String, Object>) parser.parse(json, containerFactory);
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}

private static ContainerFactory getContainerFactory() {
ContainerFactory containerFactory = new ContainerFactory() {
public List<Object> creatArrayContainer() {
return new LinkedList<Object>();
}

public Map<String, Object> createObjectContainer() {
return new LinkedHashMap<String, Object>();
}
};
return containerFactory;
public static Map<String, Object> getMapFromJson(String json) throws JSONException {
Map<String, Object> mapping = null;
try {
// mapping = new ObjectMapper().readValue(json, HashMap.class);
JSONObject jsonObject = new JSONObject(json);
mapping = jsonObject.toMap();
} catch (JSONException e) {
System.out.println("json=" + json);
e.printStackTrace();
throw e;

Check warning on line 35 in src/main/java/com/vmware/i18n/utils/JSONUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/vmware/i18n/utils/JSONUtil.java#L32-L35

Added lines #L32 - L35 were not covered by tests
}
return mapping;
}

/**
Expand All @@ -65,7 +52,12 @@
Object retvalue = null;
for (int i = 0; i < patharr.length; i++) {
String key = patharr[i];
retvalue = current.get(key);
try {
retvalue = current.get(key);
} catch (JSONException e) {
retvalue = null;
break;
}
if (i < (patharr.length - 1)) {
current = (JSONObject) retvalue;
}
Expand All @@ -81,8 +73,8 @@
public static JSONObject string2JSON(String jsonStr) {
JSONObject genreJsonObject = null;
try {
genreJsonObject = (JSONObject) JSONValue.parseWithException(jsonStr);
} catch (ParseException e) {
genreJsonObject = new JSONObject(jsonStr);
} catch (JSONException e) {

Check warning on line 77 in src/main/java/com/vmware/i18n/utils/JSONUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/vmware/i18n/utils/JSONUtil.java#L77

Added line #L77 was not covered by tests
e.printStackTrace();
}
return genreJsonObject;
Expand All @@ -100,9 +92,9 @@
}
});
try {
Map<String, Object> genreJsonObject = (Map<String, Object>) JSONValue.parseWithException(jsonStr);
Map<String, Object> genreJsonObject = (Map<String, Object>) getMapFromJson(jsonStr);
sortMap.putAll(genreJsonObject);
} catch (ParseException e) {
} catch (JSONException e) {

Check warning on line 97 in src/main/java/com/vmware/i18n/utils/JSONUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/vmware/i18n/utils/JSONUtil.java#L97

Added line #L97 was not covered by tests
e.printStackTrace();
}
return sortMap;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/vmware/i18n/utils/LocaleDataUtils.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* Copyright 2019-2022 VMware, Inc.
* Copyright 2019-2025 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.i18n.utils;

import java.io.File;
import java.util.*;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/vmware/i18n/utils/MiscUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 VMware, Inc.
* Copyright 2019-2025 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.i18n.utils;
Expand All @@ -9,7 +9,7 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.json.simple.JSONObject;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/vmware/i18n/utils/SupplementUtils.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* Copyright 2019-2023 VMware, Inc.
* Copyright 2019-2025 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.i18n.utils;

import java.io.File;
import java.text.MessageFormat;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.vmware.i18n.common.Constants;
import org.json.simple.JSONObject;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -46,7 +46,7 @@ public static void supplementalCurrencyExtract() {
Map<String, Object> regionMap = (Map<String, Object>) supplementalMap.get(Constants.REGION);
Map<String, String> resMap = new LinkedHashMap<String, String>();
for (Map.Entry<String, Object> entry : regionMap.entrySet()) {
LinkedList<Object> list = (LinkedList<Object>) entry.getValue();
List<Object> list = (List<Object>) entry.getValue();
for (int i = 0; i < list.size(); i++) {
Map<String, Object> itemMap = (Map<String, Object>) list.get(i);
for (Map.Entry<String, Object> item : itemMap.entrySet()) {
Expand Down
50 changes: 27 additions & 23 deletions src/main/java/com/vmware/i18n/utils/timezone/CldrTimeZoneUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 VMware, Inc.
* Copyright 2019-2025 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.i18n.utils.timezone;
Expand All @@ -17,8 +17,8 @@
import java.util.TimeZone;
import java.util.TreeMap;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.JSONArray;
import org.json.JSONObject;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -33,10 +33,11 @@
JSONObject timzone = (JSONObject) select(metaZonesJson, "supplemental.metaZones.metazoneInfo.timezone");
Map<String, JSONArray> result = new TreeMap<String, JSONArray>();
if (timzone != null) {
for (Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) timzone.entrySet()) {
String zoneKeystr1 = entry.getKey();
Object obj1 = entry.getValue();
if (obj1 instanceof List) {
for (String key : (Set<String>) timzone.keySet()) {
// for (Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) timzone.entrySet()) {
String zoneKeystr1 = key;
Object obj1 = timzone.get(key);
if (obj1 instanceof JSONArray) {
JSONArray objArry = (JSONArray) obj1;
JSONObject usesMetazones = (JSONObject) objArry.get(0);
JSONObject usesMetazoneObj = (JSONObject) usesMetazones.get(Constants.TIMEZONENAME_USES_METAZONE);
Expand All @@ -46,10 +47,11 @@
}
}
JSONObject jsonObj1 = (JSONObject) obj1;
for (Entry<String, Object> entry1 : (Set<Map.Entry<String, Object>>) jsonObj1.entrySet()) {
String zoneKeystr2 = entry1.getKey();
Object obj2 = entry1.getValue();
if (obj2 instanceof List) {
for (String key1 : (Set<String>) jsonObj1.keySet()) {
// for (Entry<String, Object> entry1 : (Set<Map.Entry<String, Object>>) jsonObj1.entrySet()) {
String zoneKeystr2 = key1;
Object obj2 = jsonObj1.get(key1);
if (obj2 instanceof JSONArray) {
JSONArray objArry2 = (JSONArray) obj2;
JSONObject usesMetazones2 = (JSONObject) objArry2.get(0);
JSONObject usesMetazoneObj2 = (JSONObject) usesMetazones2
Expand All @@ -61,10 +63,11 @@
}
}
JSONObject jsonObj2 = (JSONObject) obj2;
for (Entry<String, Object> entry2 : (Set<Map.Entry<String, Object>>) jsonObj2.entrySet()) {
String zoneKeystr3 = entry2.getKey();
Object obj3 = entry2.getValue();
if (obj3 instanceof List) {
for (String key2 : (Set<String>) jsonObj2.keySet()) {
// for (Entry<String, Object> entry2 : (Set<Map.Entry<String, Object>>) jsonObj2.entrySet()) {
String zoneKeystr3 = key2;
Object obj3 = jsonObj2.get(key2);
if (obj3 instanceof JSONArray) {
JSONArray objArry3 = (JSONArray) obj3;
JSONObject usesMetazones3 = (JSONObject) objArry3.get(0);
JSONObject usesMetazoneObj3 = (JSONObject) usesMetazones3
Expand All @@ -76,10 +79,11 @@
}
}
JSONObject jsonObj3 = (JSONObject) obj3;
for (Entry<String, Object> entry3 : (Set<Map.Entry<String, Object>>) jsonObj3.entrySet()) {
String zoneKeystr4 = entry3.getKey();
Object obj4 = entry3.getValue();
if (obj4 instanceof List) {
for (String key3 : (Set<String>) jsonObj3.keySet()) {
// for (Entry<String, Object> entry3 : (Set<Map.Entry<String, Object>>) jsonObj3.entrySet()) {
String zoneKeystr4 = key3;
Object obj4 = jsonObj3.get(key3);

Check warning on line 85 in src/main/java/com/vmware/i18n/utils/timezone/CldrTimeZoneUtils.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/vmware/i18n/utils/timezone/CldrTimeZoneUtils.java#L84-L85

Added lines #L84 - L85 were not covered by tests
if (obj4 instanceof JSONArray) {
JSONArray objArry4 = (JSONArray) obj4;
JSONObject usesMetazones4 = (JSONObject) objArry4.get(0);
JSONObject usesMetazoneObj4 = (JSONObject) usesMetazones4
Expand Down Expand Up @@ -116,9 +120,9 @@
Map<String, JSONArray> timezoneKeysProps = findTimezoneKeys(metaZonesJson);
Map<String, List<JSONObject>> mapZonesMap = new TreeMap<String, List<JSONObject>>();
if (arry != null) {
Iterator<JSONObject> iterator = arry.iterator();
Iterator<Object> iterator = arry.iterator();
while (iterator.hasNext()) {
JSONObject objZone = iterator.next();
JSONObject objZone = (JSONObject) iterator.next();
String timezoneKey = (String) select(objZone, "mapZone._type");
if (mapZonesMap.get(timezoneKey) != null) {
mapZonesMap.get(timezoneKey).add(objZone);
Expand All @@ -139,10 +143,10 @@
JSONArray mataZoneP = entry.getValue();
cldrMetaZone.put(Constants.TIMEZONENAME_METAZONE_EXEMPLARCITY, exemplarCity);
cldrMetaZone.put(Constants.TIMEZONENAME_METAZONE_TIMEZONE, timeZone);
Iterator<JSONObject> metaiterator = mataZoneP.iterator();
Iterator<Object> metaiterator = mataZoneP.iterator();
List<Map<String, Object>> usesMetazones = new ArrayList<Map<String, Object>>();
while (metaiterator.hasNext()) {
JSONObject objZone = metaiterator.next();
JSONObject objZone = (JSONObject) metaiterator.next();
Map<String, Object> usesMetazoneMap = new TreeMap<String, Object>();
String metazoneKey = (String) select(objZone, "usesMetazone._mzone");
String _fromVal = (String) select(objZone, "usesMetazone._from");
Expand Down
15 changes: 9 additions & 6 deletions src/test/java/com/vmware/test/i18n/I18nUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 VMware, Inc.
* Copyright 2019-2025 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.test.i18n;
Expand All @@ -10,8 +10,8 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import org.json.JSONObject;
import org.json.JSONException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -60,8 +60,11 @@ public void testLocalesExtract() {
for(int i=0;i<languageArray.length;i++) {
String regions = PatternUtil.getRegionFromLib(languageArray[i]);
Map<String, Object> genreJsonObject = null;
genreJsonObject = (Map<String, Object>) JSONValue.parseWithException(regions);
Map<String, Object> territoriesObject = (Map<String, Object>) JSONValue.parseWithException(genreJsonObject.get("territories").toString());
JSONObject jsonObject = new JSONObject(regions);
genreJsonObject = jsonObject.toMap();
Map<String, Object> territoriesObject = (Map<String, Object>) genreJsonObject.get("territories");
// genreJsonObject = (Map<String, Object>) new ObjectMapper().readValue(regions, HashMap.class);
// Map<String, Object> territoriesObject = (Map<String, Object>) new ObjectMapper().readValue(genreJsonObject.get("territories").toString(), HashMap.class);
if (languageArray[i].equals("zh")) {
Assert.assertEquals("zh", genreJsonObject.get("language"));
Assert.assertNotNull(territoriesObject.get("TW"));
Expand Down Expand Up @@ -101,7 +104,7 @@ public void testLocalesExtract() {
}

}
} catch (ParseException e) {
} catch (JSONException e) {
e.printStackTrace();
}
}
Expand Down
Loading