diff --git a/.github/workflows/gradle.yaml b/.github/workflows/gradle.yaml index 8e6e1d92f..9e48c42df 100644 --- a/.github/workflows/gradle.yaml +++ b/.github/workflows/gradle.yaml @@ -13,7 +13,7 @@ jobs: unit-test: name: Unit Test - runs-on: windows-latest + runs-on: ubuntu-latest needs: pre-process if: needs.pre-process.outputs.were-only-docs-updated != 'yes' steps: @@ -103,7 +103,8 @@ jobs: run: | git clone --branch=master https://github.com/vmware/singleton.git server cd $GITHUB_WORKSPACE/server/g11n-ws && ./gradlew build -x test - find $GITHUB_WORKSPACE/server/publish/ -name 'singleton-[0~9]*.jar' -exec mv '{}' $GITHUB_WORKSPACE/server/publish/singleton.jar \; + #find $GITHUB_WORKSPACE/server/publish/ -name 'singleton-[0~9]*.jar' -exec mv '{}' $GITHUB_WORKSPACE/server/publish/singleton.jar \; + mv $GITHUB_WORKSPACE/server/publish/singleton-0.1.0.jar $GITHUB_WORKSPACE/server/publish/singleton.jar - uses: actions/upload-artifact@v4 with: name: singleton-service @@ -139,9 +140,11 @@ jobs: cd $GITHUB_WORKSPACE ./gradlew clean build -x test cp ./build/libs/*.jar $GITHUB_WORKSPACE/devops/autotest/client/java/lib/ + ls -l $GITHUB_WORKSPACE/devops/autotest/client/java/lib/ cd $GITHUB_WORKSPACE/devops/autotest/client/java ./gradlew build -x test docker cp src/main/resources/l10n singleton:/ cd target + ls -l java -cp '.:./*' org.testng.TestNG -d test-output testng.xml diff --git a/build.gradle b/build.gradle index 666db49da..d305ad595 100644 --- a/build.gradle +++ b/build.gradle @@ -37,8 +37,8 @@ dependencies { compile group: 'javax.servlet.jsp', name: 'javax.servlet.jsp-api', version: '2.3.1' compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0' compile group: 'org.apache.taglibs', name: 'taglibs-standard-impl', version: '1.2.5' - compile group: 'org.json', name: 'json', version: '20250107' - compile group: 'com.vmware.singleton', name: 'singleton-i18n-patterns-core', version: '[0.5.1,)' + compile group: 'org.json', name: 'json', version: '20250107' + compile group: 'com.vmware.singleton', name: 'singleton-i18n-patterns-core', version: '0.5.17.1' compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' testCompile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.30' testCompile group: 'log4j', name: 'log4j', version: '1.2.17' diff --git a/sample-client-app/build.gradle b/sample-client-app/build.gradle index 04d58e52d..a5af1452a 100644 --- a/sample-client-app/build.gradle +++ b/sample-client-app/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ apply plugin: 'eclipse' @@ -26,12 +26,14 @@ repositories { } dependencies { - compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' + compile group: 'org.json', name: 'json', version:'20250107' + // compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.30' compile group: 'log4j', name: 'log4j', version: '1.2.17' - compile group: 'com.vmware.singleton', name: 'singleton-i18n-patterns-core', version: '0.4.0' + compile group: 'com.vmware.singleton', name: 'singleton-i18n-patterns-core', version: '0.5.17.1' + compile group: 'junit', name: 'junit', version: '4.10' compile fileTree(dir: 'lib', include: ['*.jar']) } diff --git a/sample-client-app/sample-app-with-shared-lib/README.md b/sample-client-app/sample-app-with-shared-lib/README.md index 55905011e..3c07ee568 100644 --- a/sample-client-app/sample-app-with-shared-lib/README.md +++ b/sample-client-app/sample-app-with-shared-lib/README.md @@ -19,7 +19,7 @@ How to build and run this sample application as an executable jar ``` * Put the Singleton Java client library into the lib folder. ``` - cp ../../build/libs/vip4java-0.1.0.jar ./lib/ + cp ../../build/libs/singleton-client-java-0.1.0.jar ./lib/ ``` * Put the sample shared library into the lib folder. See how to build the sample shared library in [here](https://github.com/vmware/singleton/blob/g11n-java-client/sample-client-app/sample-shared-library/README.md) ``` @@ -46,7 +46,7 @@ How to build and run this sample application as a Spring Boot executable jar ``` * Put the Singleton Java client library into the lib folder. ``` - cp ../../build/libs/vip4java-0.1.0.jar ./lib/ + cp ../../build/libs/singleton-client-java-0.1.0.jar ./lib/ ``` * Put the sample shared library into the lib folder. See how to build the sample shared library in [here](https://github.com/vmware/singleton/blob/g11n-java-client/sample-client-app/sample-shared-library/README.md) ``` diff --git a/sample-client-app/sample-app-with-shared-lib/build-spring-boot.gradle b/sample-client-app/sample-app-with-shared-lib/build-spring-boot.gradle index 0aa47f337..6df4a01c0 100644 --- a/sample-client-app/sample-app-with-shared-lib/build-spring-boot.gradle +++ b/sample-client-app/sample-app-with-shared-lib/build-spring-boot.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ plugins { @@ -19,8 +19,8 @@ repositories { dependencies { implementation files('lib/sample-shared-library-1.0.jar') - implementation files('lib/vip4java-0.1.0.jar') - compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' + implementation files('lib/singleton-client-java-0.1.0.jar') + compile group: 'org.json', name: 'json', version:'20250107' // tag::actuator[] implementation 'org.springframework.boot:spring-boot-starter-actuator' diff --git a/sample-client-app/sample-app-with-shared-lib/build.gradle b/sample-client-app/sample-app-with-shared-lib/build.gradle index c69fc340c..2993cbbfa 100644 --- a/sample-client-app/sample-app-with-shared-lib/build.gradle +++ b/sample-client-app/sample-app-with-shared-lib/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ apply plugin: 'eclipse' @@ -26,7 +26,7 @@ repositories { } dependencies { - compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' + compile group: 'org.json', name: 'json', version:'20250107' compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.30' diff --git a/sample-client-app/sample-app-with-shared-lib/src/main/resources/sampleconfig.properties b/sample-client-app/sample-app-with-shared-lib/src/main/resources/sampleconfig.properties index 646947eaa..cda7614a4 100644 --- a/sample-client-app/sample-app-with-shared-lib/src/main/resources/sampleconfig.properties +++ b/sample-client-app/sample-app-with-shared-lib/src/main/resources/sampleconfig.properties @@ -15,7 +15,7 @@ version = 1.0.0 # [cacheExpiredTime ] - Cache expiration time. unit: millisecond. # [machineTranslation] - If machineTranslation is true, will get translation by machine translation. ###################################################################################### -vipServer = http://localhost:8099 +vipServer = http://localhost:8091 offlineResourcesBaseUrl = offlineBundles/ initializeCache = false pseudo = false diff --git a/sample-client-app/sample-shared-library/README.md b/sample-client-app/sample-shared-library/README.md index 1becf8123..2d38439b1 100644 --- a/sample-client-app/sample-shared-library/README.md +++ b/sample-client-app/sample-shared-library/README.md @@ -11,7 +11,7 @@ How to build and run this sample shared library ------------ * Go to the root directory of this sample application ``` - g11n-java-client/sample/-client-app/sample-shared-library + g11n-java-client/sample-client-app/sample-shared-library ``` * Create a lib folder. ``` @@ -19,7 +19,7 @@ How to build and run this sample shared library ``` * Put the Singleton Java client library into the lib folder. ``` - cp ../../build/libs/vip4java-0.1.0.jar ./lib/ + cp ../../build/libs/singleton-client-java-0.1.0.jar ./lib/ ``` * Build the sample application. ``` diff --git a/sample-client-app/sample-shared-library/build.gradle b/sample-client-app/sample-shared-library/build.gradle index 7b5b3b294..4eb0429bc 100644 --- a/sample-client-app/sample-shared-library/build.gradle +++ b/sample-client-app/sample-shared-library/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ apply plugin: 'eclipse' @@ -21,7 +21,7 @@ repositories { } dependencies { - compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' + compile group: 'org.json', name: 'json', version:'20250107' compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.30' compile group: 'log4j', name: 'log4j', version: '1.2.17' diff --git a/sample-client-app/src/main/java/com/vmware/vipclient/sample/Translation.java b/sample-client-app/src/main/java/com/vmware/vipclient/sample/Translation.java index d645e17b9..32fb6459c 100644 --- a/sample-client-app/src/main/java/com/vmware/vipclient/sample/Translation.java +++ b/sample-client-app/src/main/java/com/vmware/vipclient/sample/Translation.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.sample; @@ -8,7 +8,7 @@ import java.util.Locale; import java.util.Map; -import org.json.simple.JSONObject; +import org.json.JSONObject; import com.vmware.vipclient.i18n.I18nFactory; import com.vmware.vipclient.i18n.base.instances.TranslationMessage; diff --git a/sample-client-app/src/main/java/com/vmware/vipclient/sample/TranslationDemo.java b/sample-client-app/src/main/java/com/vmware/vipclient/sample/TranslationDemo.java index 633a4f9b5..256f1b75a 100644 --- a/sample-client-app/src/main/java/com/vmware/vipclient/sample/TranslationDemo.java +++ b/sample-client-app/src/main/java/com/vmware/vipclient/sample/TranslationDemo.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.sample; @@ -7,6 +7,8 @@ import static org.junit.Assert.assertEquals; import java.util.Date; +import java.util.TimeZone; +import java.text.SimpleDateFormat; import java.util.Locale; import com.vmware.vipclient.i18n.I18nFactory; @@ -134,11 +136,18 @@ private static void getMessageWithSimpleArg(){ new Date(timestamp), "a disturbance in the Force" }; + // get expected date string based on default timezone + Date d = new Date(timestamp); + final SimpleDateFormat df = new SimpleDateFormat("MMMMM d, yyyy"); + df.setTimeZone(TimeZone.getDefault()); + final SimpleDateFormat tf = new SimpleDateFormat("h:mm a"); + tf.setTimeZone(TimeZone.getDefault()); + String dateString = tf.format(d) + " on " + df.format(d); String includeFormatMessage = t.getMessage(Locale.ENGLISH, component, "sample.includeFormat.message", arguments); System.out.println("message with number&date arguments: " + includeFormatMessage); - Assert.assertEquals("At 1:39 PM on November 20, 2017, there was a disturbance in the Force on planet 7.", includeFormatMessage); + Assert.assertEquals("At " + dateString + ", there was a disturbance in the Force on planet 7.", includeFormatMessage); System.out.println(">>>>>> TranslationDemo.getMessageWithSimpleArg success"); } } diff --git a/src/main/java/com/vmware/vipclient/i18n/base/cache/persist/DiskCacheLoader.java b/src/main/java/com/vmware/vipclient/i18n/base/cache/persist/DiskCacheLoader.java index 30a198834..91fbf0275 100644 --- a/src/main/java/com/vmware/vipclient/i18n/base/cache/persist/DiskCacheLoader.java +++ b/src/main/java/com/vmware/vipclient/i18n/base/cache/persist/DiskCacheLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.base.cache.persist; @@ -15,7 +15,8 @@ import java.util.Map; import com.vmware.vipclient.i18n.base.cache.TranslationCacheManager; -import org.json.simple.parser.JSONParser; +import org.json.JSONObject; +import org.json.JSONTokener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,10 +40,8 @@ public Map load(String key) { } } reader = new InputStreamReader(fis, "UTF-8"); - Object o = new JSONParser().parse(reader); - if (o != null) { - map = (Map) o; - } + JSONObject jsonObject = new JSONObject(new JSONTokener(reader)); + map = jsonObject.toMap(); } catch (Exception e) { logger.error(e.getMessage()); } finally { diff --git a/src/main/java/com/vmware/vipclient/i18n/base/instances/DateFormatting.java b/src/main/java/com/vmware/vipclient/i18n/base/instances/DateFormatting.java index 5cf9cb23d..f9234531a 100644 --- a/src/main/java/com/vmware/vipclient/i18n/base/instances/DateFormatting.java +++ b/src/main/java/com/vmware/vipclient/i18n/base/instances/DateFormatting.java @@ -1,12 +1,12 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.base.instances; import com.vmware.vipclient.i18n.I18nFactory; import com.vmware.vipclient.i18n.l2.common.PatternCategory; -import org.json.simple.JSONObject; +import org.json.JSONObject; import java.util.Locale; diff --git a/src/main/java/com/vmware/vipclient/i18n/base/instances/PatternMessage.java b/src/main/java/com/vmware/vipclient/i18n/base/instances/PatternMessage.java index bf7cda3c8..7eb32bdd1 100644 --- a/src/main/java/com/vmware/vipclient/i18n/base/instances/PatternMessage.java +++ b/src/main/java/com/vmware/vipclient/i18n/base/instances/PatternMessage.java @@ -1,11 +1,11 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.base.instances; import com.vmware.vipclient.i18n.messages.service.PatternService; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/com/vmware/vipclient/i18n/base/instances/TranslationMessage.java b/src/main/java/com/vmware/vipclient/i18n/base/instances/TranslationMessage.java index 47f53c06d..371ba9462 100644 --- a/src/main/java/com/vmware/vipclient/i18n/base/instances/TranslationMessage.java +++ b/src/main/java/com/vmware/vipclient/i18n/base/instances/TranslationMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2024 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.base.instances; @@ -12,7 +12,7 @@ import com.vmware.vipclient.i18n.messages.service.ComponentsService; import com.vmware.vipclient.i18n.messages.service.StringService; import com.vmware.vipclient.i18n.util.*; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -529,7 +529,7 @@ public Map getMessages(String resourceBundle, final Locale local Map messages = new LinkedHashMap<>(); - Map sources = resourceBundle != null ? getSourcesFromBundle(resourceBundle): + Map sources = resourceBundle != null ? getSourcesFromBundle(resourceBundle): getMessages(Locale.forLanguageTag(ConstantsKeys.SOURCE), component, false).getMessages(); if(!sources.isEmpty()) { @@ -597,8 +597,7 @@ private ComponentService.TranslationsDTO getMultiVersionMessagesOfKey(final Loca */ public Map>> getStrings(final Set locales, final Set components) { - this.logger.trace("Start to execute TranslationMessage.getStrings of multiple components of multiple locales."); - + this.logger.info("Start to execute TranslationMessage.getStrings of multiple components of multiple locales."); Map>> retMap = new HashMap<>(); if (null == locales || locales.isEmpty() || null == components || components.isEmpty()) { this.logger.error(ConstantsMsg.WRONG_PARAMETER + "locales: {}, components: {}.", locales, components); diff --git a/src/main/java/com/vmware/vipclient/i18n/filters/VIPComponentFilter.java b/src/main/java/com/vmware/vipclient/i18n/filters/VIPComponentFilter.java index fc3a1048c..5c11287ef 100644 --- a/src/main/java/com/vmware/vipclient/i18n/filters/VIPComponentFilter.java +++ b/src/main/java/com/vmware/vipclient/i18n/filters/VIPComponentFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2024 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.filters; @@ -17,7 +17,7 @@ import com.vmware.vipclient.i18n.exceptions.VIPJavaClientException; import com.vmware.vipclient.i18n.util.StringUtil; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +45,8 @@ public void doFilter(ServletRequest request, ServletResponse response, Map ctmap = translation.getStrings(LocaleUtility.fmtToMappedLocale(locale), component); if (ctmap != null) { - messages = JSONObject.toJSONString(ctmap); + JSONObject jsonObject = new JSONObject(ctmap); + messages = jsonObject.toString(); } } OutputStream os = response.getOutputStream(); diff --git a/src/main/java/com/vmware/vipclient/i18n/filters/VIPPatternFilter.java b/src/main/java/com/vmware/vipclient/i18n/filters/VIPPatternFilter.java index a243bf946..f5cd2b4f7 100644 --- a/src/main/java/com/vmware/vipclient/i18n/filters/VIPPatternFilter.java +++ b/src/main/java/com/vmware/vipclient/i18n/filters/VIPPatternFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2024 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.filters; @@ -21,7 +21,7 @@ import com.vmware.vipclient.i18n.base.instances.PatternMessage; import com.vmware.vipclient.i18n.exceptions.VIPJavaClientException; import com.vmware.vipclient.i18n.util.StringUtil; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,9 +46,11 @@ public void doFilter(final ServletRequest request, ServletResponse response, String patterns = "{}"; if (!StringUtil.isEmpty(locale) && !LocaleUtility.isDefaultLocale(locale)) { - Map ctmap = patternMessage.getPatternMessage(Locale.forLanguageTag(locale)); - if (ctmap != null) { - patterns = JSONObject.toJSONString(ctmap); + JSONObject jsonObject = patternMessage.getPatternMessage(Locale.forLanguageTag(locale)); + if (jsonObject != null) { + // JSONObject jsonObject = new JSONObject(ctmap); + patterns = jsonObject.toString(); + // patterns = JSONObject.toJSONString(ctmap); } } OutputStream os = response.getOutputStream(); diff --git a/src/main/java/com/vmware/vipclient/i18n/formats/DateFormat.java b/src/main/java/com/vmware/vipclient/i18n/formats/DateFormat.java index 425cb045e..74de47b10 100644 --- a/src/main/java/com/vmware/vipclient/i18n/formats/DateFormat.java +++ b/src/main/java/com/vmware/vipclient/i18n/formats/DateFormat.java @@ -1,14 +1,13 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.formats; import java.util.Map; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.json.simple.parser.ParseException; +import org.json.JSONObject; +import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,7 +52,7 @@ private String getFormatFromRemote(String longDate, String pattern) { } JSONObject retJson; try { - retJson = (JSONObject) JSONValue.parseWithException(retJsonStr); + retJson = new JSONObject(retJsonStr); if (retJson != null) { JSONObject dataJson = (JSONObject) retJson .get(ConstantsKeys.DATA); @@ -63,7 +62,7 @@ private String getFormatFromRemote(String longDate, String pattern) { .toString(); } } - } catch (ParseException e) { + } catch (JSONException e) { logger.error(e.getMessage()); } return format; diff --git a/src/main/java/com/vmware/vipclient/i18n/formats/NumberFormat.java b/src/main/java/com/vmware/vipclient/i18n/formats/NumberFormat.java index 7e261bddd..9bffd0840 100644 --- a/src/main/java/com/vmware/vipclient/i18n/formats/NumberFormat.java +++ b/src/main/java/com/vmware/vipclient/i18n/formats/NumberFormat.java @@ -1,14 +1,13 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.formats; import java.util.Map; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.json.simple.parser.ParseException; +import org.json.JSONObject; +import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,7 +52,7 @@ private String getFormatFromRemote(String number, String scale) { } JSONObject retJson; try { - retJson = (JSONObject) JSONValue.parseWithException(retJsonStr); + retJson = new JSONObject(retJsonStr); if (retJson != null) { JSONObject dataJson = (JSONObject) retJson .get(ConstantsKeys.DATA); @@ -63,7 +62,7 @@ private String getFormatFromRemote(String number, String scale) { .toString(); } } - } catch (ParseException e) { + } catch (JSONException e) { logger.error(e.getMessage()); } return format; diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/number/parser/IntegerDigitsParser.java b/src/main/java/com/vmware/vipclient/i18n/l2/number/parser/IntegerDigitsParser.java index 2168e62c8..1ee67a321 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/number/parser/IntegerDigitsParser.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/number/parser/IntegerDigitsParser.java @@ -1,10 +1,10 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.number.parser; -import org.json.simple.JSONObject; +import org.json.JSONObject; import com.vmware.vipclient.i18n.l2.common.PatternKeys; diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/plural/parser/PluralRules.java b/src/main/java/com/vmware/vipclient/i18n/l2/plural/parser/PluralRules.java index 7d71f2ce6..3d2ad1d00 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/plural/parser/PluralRules.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/plural/parser/PluralRules.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.plural.parser; @@ -18,10 +18,11 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.stream.Collectors; import java.util.Set; import java.util.regex.Pattern; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -1250,7 +1251,8 @@ public static PluralRules forLocale(Locale locale, PluralType type) { } catch (NullPointerException e) { logger.info("Lack plural pattern!"); } - return getInstance(pluralRules); + return getInstance(pluralRules.toMap().entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue()))); } } diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/service/NumberFormatService.java b/src/main/java/com/vmware/vipclient/i18n/l2/service/NumberFormatService.java index 9d1607952..271bbfb8d 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/service/NumberFormatService.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/service/NumberFormatService.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.service; @@ -11,7 +11,7 @@ import com.vmware.vipclient.i18n.l2.common.PatternKeys; import com.vmware.vipclient.i18n.l2.text.NumberFormat; import com.vmware.vipclient.i18n.util.ConstantsKeys; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -140,15 +140,19 @@ public String format(Object value, String currencyCode, Integer fractionSize, Lo private JSONObject getCurrencyRelatedData(JSONObject allCategoriesData, String currencyCode) { JSONObject currencyFormatData = new JSONObject(); JSONObject numberFormatData = (JSONObject) allCategoriesData.get(PatternCategory.NUMBERS.toString()); - JSONObject currencyData = (JSONObject) ((HashMap) allCategoriesData.get(PatternKeys.CURRENCIES)) + JSONObject currencyData = (JSONObject) ((JSONObject) allCategoriesData.get(PatternKeys.CURRENCIES)) .get(currencyCode); if (currencyData == null) { throw new IllegalArgumentException("Unsupported currency code " + currencyCode + "."); } - JSONObject currencySupplementalData = (JSONObject) ((HashMap) allCategoriesData + JSONObject currencySupplementalData = (JSONObject) ((JSONObject) allCategoriesData .get(PatternCategory.SUPPLEMENTAL.toString())).get(PatternKeys.CURRENCIES); - JSONObject fractionData = (JSONObject) ((HashMap) currencySupplementalData.get(PatternKeys.FRACTIONS)) - .get(currencyCode); + JSONObject fractionData = null; + try { + fractionData = (JSONObject) ((JSONObject) currencySupplementalData.get(PatternKeys.FRACTIONS)).get(currencyCode); + } catch (org.json.JSONException e) { + logger.info("NumberFormatService - Can't find fractionData, null will be set"); + } currencyFormatData.put(PatternCategory.NUMBERS.toString(), numberFormatData); currencyFormatData.put(PatternKeys.CURRENCY, currencyData); currencyFormatData.put(PatternKeys.FRACTION, fractionData); diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/text/DateFormat.java b/src/main/java/com/vmware/vipclient/i18n/l2/text/DateFormat.java index 615b3e623..d5ddf5933 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/text/DateFormat.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/text/DateFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.text; @@ -11,7 +11,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.json.simple.JSONObject; +import org.json.JSONObject; import com.vmware.vipclient.i18n.l2.common.ConstantChars; import com.vmware.vipclient.i18n.l2.common.PatternKeys; diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/text/DecimalFormat.java b/src/main/java/com/vmware/vipclient/i18n/l2/text/DecimalFormat.java index c96281d6c..62d5f1431 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/text/DecimalFormat.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/text/DecimalFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.text; @@ -8,7 +8,7 @@ import java.math.BigInteger; import java.util.HashMap; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,11 +43,16 @@ public class DecimalFormat extends NumberFormat { public DecimalFormat(JSONObject formatData, int style) { JSONObject numberFormats; if (style == NumberFormat.CURRENCYSTYLE) { - this.numberSymbols = (JSONObject) ((HashMap) formatData.get(PatternCategory.NUMBERS.toString())) + this.numberSymbols = (JSONObject) ((JSONObject) formatData.get(PatternCategory.NUMBERS.toString())) .get(PatternKeys.NUMBERSYMBOLS); - numberFormats = (JSONObject) ((HashMap) formatData.get(PatternCategory.NUMBERS.toString())) + numberFormats = (JSONObject) ((JSONObject) formatData.get(PatternCategory.NUMBERS.toString())) .get(PatternKeys.NUMBERFORMATS); - this.fractionData = (JSONObject) formatData.get(PatternKeys.FRACTION); + this.fractionData = null; + try { + this.fractionData = (JSONObject) formatData.get(PatternKeys.FRACTION); + } catch (org.json.JSONException e) { + logger.info("Can't find fractionData, null will be set"); + } } else { this.numberSymbols = (JSONObject) formatData.get(PatternKeys.NUMBERSYMBOLS); numberFormats = (JSONObject) formatData.get(PatternKeys.NUMBERFORMATS); diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/text/NumberFormat.java b/src/main/java/com/vmware/vipclient/i18n/l2/text/NumberFormat.java index e20b80ad6..648be9b6b 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/text/NumberFormat.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/text/NumberFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.text; @@ -7,7 +7,7 @@ import java.math.BigDecimal; import java.math.BigInteger; -import org.json.simple.JSONObject; +import org.json.JSONObject; import com.vmware.vipclient.i18n.l2.common.PatternKeys; diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/text/PatternItem.java b/src/main/java/com/vmware/vipclient/i18n/l2/text/PatternItem.java index 06f043acd..95bc68780 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/text/PatternItem.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/text/PatternItem.java @@ -1,12 +1,12 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.text; import java.util.Calendar; -import org.json.simple.JSONObject; +import org.json.JSONObject; import com.vmware.vipclient.i18n.l2.text.parser.AMPMPatternParser; import com.vmware.vipclient.i18n.l2.text.parser.DatePatternParser; diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/text/RegionDateFormat.java b/src/main/java/com/vmware/vipclient/i18n/l2/text/RegionDateFormat.java index b96c5822f..9aae94cd1 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/text/RegionDateFormat.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/text/RegionDateFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.text; @@ -10,7 +10,7 @@ import java.util.List; import java.util.TimeZone; -import org.json.simple.JSONObject; +import org.json.JSONObject; public class RegionDateFormat extends DateFormat { diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/text/SimpleDateFormat.java b/src/main/java/com/vmware/vipclient/i18n/l2/text/SimpleDateFormat.java index 74f1554bd..35d9c5fa7 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/text/SimpleDateFormat.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/text/SimpleDateFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.text; @@ -11,7 +11,7 @@ import java.util.Locale; import java.util.TimeZone; -import org.json.simple.JSONObject; +import org.json.JSONObject; public class SimpleDateFormat extends DateFormat { diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/AMPMPatternParser.java b/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/AMPMPatternParser.java index 40a4a1f92..81d65bb44 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/AMPMPatternParser.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/AMPMPatternParser.java @@ -1,13 +1,13 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.text.parser; import java.util.Calendar; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; +import org.json.JSONArray; +import org.json.JSONObject; import com.vmware.vipclient.i18n.l2.common.PatternKeys; import com.vmware.vipclient.i18n.l2.text.PatternItem; diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/DateStrPatternParser.java b/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/DateStrPatternParser.java index 74f8fa625..f5898390a 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/DateStrPatternParser.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/DateStrPatternParser.java @@ -1,13 +1,13 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.text.parser; import com.vmware.vipclient.i18n.l2.common.PatternKeys; import com.vmware.vipclient.i18n.l2.text.PatternItem; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; +import org.json.JSONArray; +import org.json.JSONObject; import java.util.Calendar; diff --git a/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/EraPatternParser.java b/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/EraPatternParser.java index 030ddf63a..ab7298399 100644 --- a/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/EraPatternParser.java +++ b/src/main/java/com/vmware/vipclient/i18n/l2/text/parser/EraPatternParser.java @@ -1,13 +1,13 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.l2.text.parser; import java.util.Calendar; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; +import org.json.JSONArray; +import org.json.JSONObject; import com.vmware.vipclient.i18n.l2.common.PatternKeys; import com.vmware.vipclient.i18n.l2.text.PatternItem; diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/BaseOpt.java b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/BaseOpt.java index 20043877f..9527ee67b 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/BaseOpt.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/BaseOpt.java @@ -1,12 +1,10 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.api.opt; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.json.simple.parser.ParseException; +import org.json.JSONObject; import com.vmware.vipclient.i18n.util.ConstantsKeys; @@ -20,8 +18,7 @@ public class BaseOpt { public Object getMessagesFromResponse(String responseStr, String node) { Object msgsObj = null; try { - JSONObject responseObj = (JSONObject) JSONValue - .parseWithException(responseStr); + JSONObject responseObj = new JSONObject(responseStr); if (responseObj != null) { JSONObject dataObj = (JSONObject) responseObj.get(ConstantsKeys.DATA); msgsObj = dataObj.get(node); @@ -45,8 +42,7 @@ public Object getStatusFromResponse(String responseStr, String node) { if (responseStr == null || responseStr.equalsIgnoreCase("")) return msgObject; try { - JSONObject responseObj = (JSONObject) JSONValue - .parseWithException(responseStr); + JSONObject responseObj = new JSONObject(responseStr); if (responseObj != null) { Object obj = responseObj.get(ConstantsKeys.RESPONSE); if (obj != null && !obj.toString().equalsIgnoreCase("")) { @@ -61,9 +57,9 @@ public Object getStatusFromResponse(String responseStr, String node) { return msgObject; } - protected void parseServerResponse() throws ParseException { + protected void parseServerResponse() throws Exception { if (null == responseJsonObj) { - responseJsonObj = (JSONObject) JSONValue.parseWithException(responseStr); + responseJsonObj = new JSONObject(responseStr); } } diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalLocaleOpt.java b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalLocaleOpt.java index 288c89d80..87449af65 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalLocaleOpt.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalLocaleOpt.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.api.opt.local; @@ -14,13 +14,14 @@ import com.vmware.vipclient.i18n.messages.service.ProductService; import com.vmware.vipclient.i18n.util.ConstantsKeys; import com.vmware.vipclient.i18n.util.JSONUtils; -import org.json.simple.parser.JSONParser; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static com.vmware.i18n.pattern.service.impl.PatternServiceImpl.localeAliasesMap; import static com.vmware.i18n.pattern.service.impl.PatternServiceImpl.localePathMap; @@ -70,10 +71,11 @@ private Map getLanguagesNamesFromBundle(String locale) { } try { String languagesJsonStr = PatternUtil.getLanguageFromLib(normalizedLocale); - Map languagesData = (Map) new JSONParser().parse(languagesJsonStr); + JSONObject languagesData = new JSONObject(languagesJsonStr); if (languagesData != null) { logger.debug("Found the languages' names from local bundle for locale [{}].\n", locale); - return (Map) languagesData.get(PatternKeys.LANGUAGES); + return ((JSONObject) languagesData.get(PatternKeys.LANGUAGES)).toMap().entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue())); }else{ logger.warn("Didn't find the languages' names from local bundle for locale [{}].\n", locale); } @@ -92,7 +94,8 @@ public void getRegions(String locale, LocaleCacheItem cacheItem) { return; try { String regionsJsonStr = PatternUtil.getRegionFromLib(normalizedLocale); - Map regionsData = (Map) new JSONParser().parse(regionsJsonStr); + JSONObject jsonObject = new JSONObject(regionsJsonStr); + Map regionsData = jsonObject.toMap(); if (regionsData != null) { Map territories = (Map) regionsData.get(PatternKeys.TERRITORIES); if(territories != null) { diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalMessagesOpt.java b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalMessagesOpt.java index 938753220..3dc0cac71 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalMessagesOpt.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalMessagesOpt.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.api.opt.local; @@ -14,8 +14,8 @@ import com.vmware.vipclient.i18n.util.FormatUtils; import com.vmware.vipclient.i18n.util.JSONBundleUtil; import com.vmware.vipclient.i18n.util.LocaleUtility; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; +import org.json.JSONObject; +import org.json.JSONTokener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,6 +23,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.Map; +import java.util.stream.Collectors; public class LocalMessagesOpt implements Opt, MessageOpt { @@ -46,9 +47,9 @@ public void getComponentMessages(MessageCacheItem cacheItem) { InputStream is = null; try { is = getInputStream(); - JSONParser jsonParser = new JSONParser(); - JSONObject jsonObject = (JSONObject) jsonParser.parse(new InputStreamReader(is, "UTF-8")); - Map messages = (JSONObject) jsonObject.get("messages"); + JSONObject jsonObject = new JSONObject(new JSONTokener(new InputStreamReader(is, "UTF-8"))); + Map messages = ((JSONObject) jsonObject.get("messages")).toMap().entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue())); cacheItem.setCacheItem(messages, null, System.currentTimeMillis(), null); } catch (Exception e) { String msg = "Failed to get offline messages for product: " + dto.getProductID() + " " + dto.getVersion() + diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalPatternOpt.java b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalPatternOpt.java index 88fd77813..77e2a4241 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalPatternOpt.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalPatternOpt.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.api.opt.local; @@ -10,11 +10,12 @@ import com.vmware.vipclient.i18n.l2.common.PatternKeys; import com.vmware.vipclient.i18n.messages.api.opt.PatternOpt; import com.vmware.vipclient.i18n.base.cache.PatternCacheItem; -import org.json.simple.parser.JSONParser; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Map; +import java.util.stream.Collectors; import static com.vmware.i18n.pattern.service.impl.PatternServiceImpl.localeAliasesMap; import static com.vmware.i18n.pattern.service.impl.PatternServiceImpl.localePathMap; @@ -43,7 +44,8 @@ private void getPatternsByLocale(String normalizedLocale, PatternCacheItem cache return; try { String patternStr = PatternUtil.getPatternFromLib(normalizedLocale, null); - Map patterns = (Map) new JSONParser().parse(patternStr); + JSONObject jsonObject = new JSONObject(patternStr); + Map patterns = jsonObject.toMap(); if(patterns != null && (patterns.get(PatternKeys.CATEGORIES) != null)) { logger.debug("Found the pattern from local bundle for locale [{}].\n", normalizedLocale); cacheItem.set((Map) patterns.get(PatternKeys.CATEGORIES), System.currentTimeMillis()); diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/ComponentBasedOpt.java b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/ComponentBasedOpt.java index 063e48f7b..246271d9a 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/ComponentBasedOpt.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/ComponentBasedOpt.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.api.opt.server; @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import com.vmware.vipclient.i18n.VIPCfg; import com.vmware.vipclient.i18n.base.cache.MessageCacheItem; @@ -18,8 +19,7 @@ import com.vmware.vipclient.i18n.messages.api.url.V2URL; import com.vmware.vipclient.i18n.messages.dto.MessagesDTO; import com.vmware.vipclient.i18n.util.ConstantsKeys; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,10 +54,17 @@ public void getComponentMessages(MessageCacheItem cacheItem) { Long maxAgeMillis = response.get(URLUtils.MAX_AGE_MILLIS) == null ? null : (Long) response.get(URLUtils.MAX_AGE_MILLIS); if (responseCode.equals(HttpURLConnection.HTTP_OK)) { - JSONObject respObj = (JSONObject) JSONValue.parse((String) response.get(URLUtils.BODY)); + String body = (String) response.get(URLUtils.BODY); + JSONObject respObj = null; + if (body != null && !body.isEmpty()) { + respObj = new JSONObject(body); + } + // JSONObject respObj = (JSONObject) JSONValue.parse((String) response.get(URLUtils.BODY)); try { if (getResponseCode(respObj) == 200) { - Map messages = this.getMsgsJson(response); + Map objMap = this.getMsgsJson(response).toMap(); + Map messages = objMap.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue())); if (messages != null) { cacheItem.setCacheItem(messages, etag, timestamp, maxAgeMillis); } diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/ComponentsBasedOpt.java b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/ComponentsBasedOpt.java index 271425e23..436d740dc 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/ComponentsBasedOpt.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/ComponentsBasedOpt.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.api.opt.server; @@ -9,8 +9,8 @@ import java.util.Map; import java.util.Set; -import org.json.simple.JSONObject; -import org.json.simple.parser.ParseException; +import org.json.JSONObject; +import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,7 +57,7 @@ public JSONObject queryFromServer(final Set components, final Set getPatternsFromResponse(String responseBody) { Map categoriesObj = null; - Map dataObj = (Map) getDataFromResponse(responseBody); + JSONObject dataObj = (JSONObject) getDataFromResponse(responseBody); if (dataObj != null && dataObj instanceof JSONObject) { - Object obj = dataObj.get(PatternKeys.CATEGORIES); - if (obj != null && obj instanceof JSONObject) { - categoriesObj = (Map) obj; - } + categoriesObj = ((JSONObject) dataObj.get(PatternKeys.CATEGORIES)).toMap(); } return categoriesObj; } diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/RemoteProductOpt.java b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/RemoteProductOpt.java index ddce53637..bf0ca5d35 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/RemoteProductOpt.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/RemoteProductOpt.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.api.opt.server; @@ -12,12 +12,13 @@ import com.vmware.vipclient.i18n.messages.api.url.V2URL; import com.vmware.vipclient.i18n.messages.dto.BaseDTO; import com.vmware.vipclient.i18n.util.ConstantsKeys; -import org.json.simple.JSONArray; +import org.json.JSONArray; import java.net.HttpURLConnection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class RemoteProductOpt extends BaseOpt implements ProductOpt { @@ -45,7 +46,9 @@ public List getComponents() { msgObject = (JSONArray) dataObj; } } - return msgObject; + return msgObject.toList().stream() + .map(obj -> obj == null ? null : obj.toString()) + .collect(Collectors.toList()); } /** @@ -76,7 +79,9 @@ public void getSupportedLocales(MessageCacheItem cacheItem) { if (responseStr != null && !responseStr.isEmpty()) { Object dataObj = this.getMessagesFromResponse(responseStr, ConstantsKeys.LOCALES); if (dataObj != null) { - List supportedLocales = (JSONArray) dataObj; + List supportedLocales = ((JSONArray) dataObj).toList().stream() + .map(obj -> obj == null ? null : obj.toString()) + .collect(Collectors.toList()); Map languageTags = new HashMap<>(); if (!supportedLocales.isEmpty()) { for (String languageTag : supportedLocales) { diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/StringBasedOpt.java b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/StringBasedOpt.java index fcb3ad037..0ae3d9403 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/StringBasedOpt.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/api/opt/server/StringBasedOpt.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.api.opt.server; @@ -12,8 +12,8 @@ import com.vmware.vipclient.i18n.base.cache.MessageCacheItem; import com.vmware.vipclient.i18n.common.ConstantsMsg; import com.vmware.vipclient.i18n.messages.api.opt.KeyBasedOpt; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; +import org.json.JSONArray; +import org.json.JSONObject; import com.vmware.vipclient.i18n.VIPCfg; import com.vmware.vipclient.i18n.messages.api.opt.BaseOpt; @@ -22,7 +22,6 @@ import com.vmware.vipclient.i18n.messages.api.url.V2URL; import com.vmware.vipclient.i18n.messages.dto.MessagesDTO; import com.vmware.vipclient.i18n.util.ConstantsKeys; -import org.json.simple.JSONValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -139,7 +138,7 @@ public void fetchMultiVersionKeyMessages(MessageCacheItem cacheItem) { Long maxAgeMillis = response.get(URLUtils.MAX_AGE_MILLIS) == null ? null : (Long) response.get(URLUtils.MAX_AGE_MILLIS); if (responseCode.equals(HttpURLConnection.HTTP_OK)) { - JSONObject respObj = (JSONObject) JSONValue.parse((String) response.get(URLUtils.BODY)); + JSONObject respObj = new JSONObject((String) response.get(URLUtils.BODY)); try { int businessCode = getResponseCode(respObj); if (isSuccess(businessCode)) { @@ -156,7 +155,7 @@ public void fetchMultiVersionKeyMessages(MessageCacheItem cacheItem) { logger.warn(String.format(ConstantsMsg.SERVER_RETURN_ERROR, businessCode, getResponseMessage(respObj))); } } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } } else { cacheItem.setCacheItem(etag, timestamp, maxAgeMillis); diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentService.java b/src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentService.java index a2e0c0a2f..ad219a2ad 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentService.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentService.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.service; @@ -14,8 +14,6 @@ import com.vmware.vipclient.i18n.util.FormatUtils; import com.vmware.vipclient.i18n.util.JSONUtils; import com.vmware.vipclient.i18n.util.LocaleUtility; -import org.json.simple.JSONValue; -import org.json.simple.parser.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -192,8 +190,9 @@ public boolean isComponentAvailable() { String json = dao.getTranslationStatus(); if (!JSONUtils.isEmpty(json)) { try { - s = (Long) JSONValue.parseWithException(json); - } catch (ParseException e) { + // s = (Long) JSONValue.parseWithException(json); + s = Long.parseLong(json); + } catch (Exception e) { logger.error(e.getMessage()); } } diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentsService.java b/src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentsService.java index 2333c0d1d..7cd948237 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentsService.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentsService.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.service; @@ -17,8 +17,9 @@ import com.vmware.vipclient.i18n.util.FormatUtils; import com.vmware.vipclient.i18n.util.LocaleUtility; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,7 +94,9 @@ private Map>> getTranslation(final Set localeMap = this.makeLocaleMap(localesToQuery, localesFromServer); + final Map localeMap = this.makeLocaleMap(localesToQuery, localesFromServer.toList().stream() + .map(obj -> obj == null ? null : obj.toString()) + .collect(Collectors.toList())); final SortedSet localesToFallback = new TreeSet<>(); final SortedSet componentsToFallback = new TreeSet<>(); @@ -101,20 +104,30 @@ private Map>> getTranslation(final Set iter = bundles.iterator(); while (iter.hasNext()) { final JSONObject bundle = (JSONObject) iter.next(); - final String locale = localeMap.get(bundle.get(ConstantsKeys.LOCALE)); + final String locale = localeMap.get((String) bundle.get(ConstantsKeys.LOCALE)); final String comp = (String) bundle.get(ConstantsKeys.COMPONENT); - final JSONObject messages = (JSONObject) bundle.get(ConstantsKeys.MESSAGES); + JSONObject messages = null; + try { + Object object = bundle.get(ConstantsKeys.MESSAGES); + if ( object instanceof JSONObject) { + messages = (JSONObject) bundle.get(ConstantsKeys.MESSAGES); + } + } catch (JSONException e) { + logger.info("can't get messages, null will be set"); + } if (messages != null && !"".equals(messages)) { // update cache. final MessagesDTO dto = new MessagesDTO(); dto.setComponent(comp); dto.setLocale(locale); - new CacheService(dto).addCacheOfComponent(new MessageCacheItem(messages, null, + new CacheService(dto).addCacheOfComponent(new MessageCacheItem(messages.toMap().entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue())), null, cacheItem.getTimestamp(), cacheItem.getMaxAgeMillis())); // update map to return. - dataMap.get(locale).put(comp, messages); + dataMap.get(locale).put(comp, messages.toMap().entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> (String)e.getValue()))); } else { localesToFallback.add(locale); componentsToFallback.add(comp); diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/service/PatternService.java b/src/main/java/com/vmware/vipclient/i18n/messages/service/PatternService.java index 7faef466d..f5fd9120e 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/service/PatternService.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/service/PatternService.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.service; @@ -10,7 +10,7 @@ import com.vmware.vipclient.i18n.common.ConstantsMsg; import com.vmware.vipclient.i18n.util.FormatUtils; import com.vmware.vipclient.i18n.util.LocaleUtility; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/com/vmware/vipclient/i18n/messages/service/StringService.java b/src/main/java/com/vmware/vipclient/i18n/messages/service/StringService.java index 994f51155..b620074e8 100644 --- a/src/main/java/com/vmware/vipclient/i18n/messages/service/StringService.java +++ b/src/main/java/com/vmware/vipclient/i18n/messages/service/StringService.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.service; @@ -22,9 +22,8 @@ import com.vmware.vipclient.i18n.util.FormatUtils; import com.vmware.vipclient.i18n.util.JSONUtils; import com.vmware.vipclient.i18n.util.LocaleUtility; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.json.simple.parser.ParseException; +import org.json.JSONObject; +import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,12 +98,13 @@ public boolean isStringAvailable(MessagesDTO dto) { Map m = null; if (!JSONUtils.isEmpty(json)) { try { - m = (Map) JSONValue.parseWithException(json); + JSONObject jsonObject = new JSONObject(json); + m = jsonObject.toMap(); if (m != null) { status = m.get(dto.getKey()) == null ? "" : (String) m.get(dto.getKey()); } - } catch (ParseException e) { + } catch (JSONException e) { logger.error(e.getMessage()); } } diff --git a/src/main/java/com/vmware/vipclient/i18n/util/FileUtil.java b/src/main/java/com/vmware/vipclient/i18n/util/FileUtil.java index 99ba63e0a..daa201d89 100644 --- a/src/main/java/com/vmware/vipclient/i18n/util/FileUtil.java +++ b/src/main/java/com/vmware/vipclient/i18n/util/FileUtil.java @@ -1,11 +1,12 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.util; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; +import org.json.JSONObject; +import org.json.JSONTokener; +import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,9 +26,9 @@ public static JSONObject readJson(Path path) { JSONObject jsonObj = null; try (InputStream is = Files.newInputStream(path); Reader reader = new InputStreamReader(is, "UTF-8");){ - jsonObj = (JSONObject) (new JSONParser().parse(reader)); + jsonObj = new JSONObject(new JSONTokener(reader)); } catch (Exception e) { - logger.error("Failed to read json file " + path); + logger.error("Failed to read json file " + path, e); } return jsonObj; @@ -50,13 +51,9 @@ public static JSONObject readJarJsonFile(String jarPath, String filePath) { try (InputStream fis = url.openStream(); Reader reader = new InputStreamReader(fis, "UTF-8");) { - - Object o = new JSONParser().parse(reader); - if (o != null) { - jsonObj = (JSONObject) o; - } + jsonObj = new JSONObject(new JSONTokener(reader)); } catch (Exception e) { - logger.error(e.getMessage()); + logger.error(e.getMessage(), e); } } catch (MalformedURLException e1) { // TODO Auto-generated catch block @@ -75,10 +72,7 @@ public static JSONObject readLocalJsonFile(String filePath) { if (file.exists()) { try (InputStream fis = new FileInputStream(file); Reader reader = new InputStreamReader(fis, "UTF-8");) { - Object o = new JSONParser().parse(reader); - if (o != null) { - jsonObj = (JSONObject) o; - } + jsonObj = new JSONObject(new JSONTokener(reader)); } catch (Exception e) { logger.error(e.getMessage()); } diff --git a/src/main/java/com/vmware/vipclient/i18n/util/JSONBundleUtil.java b/src/main/java/com/vmware/vipclient/i18n/util/JSONBundleUtil.java index c2ba18338..221fc973b 100644 --- a/src/main/java/com/vmware/vipclient/i18n/util/JSONBundleUtil.java +++ b/src/main/java/com/vmware/vipclient/i18n/util/JSONBundleUtil.java @@ -1,12 +1,12 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.util; import java.nio.file.Path; -import org.json.simple.JSONObject; +import org.json.JSONObject; public class JSONBundleUtil { diff --git a/src/main/java/com/vmware/vipclient/i18n/util/JSONUtils.java b/src/main/java/com/vmware/vipclient/i18n/util/JSONUtils.java index ac897ecf6..da545d70e 100644 --- a/src/main/java/com/vmware/vipclient/i18n/util/JSONUtils.java +++ b/src/main/java/com/vmware/vipclient/i18n/util/JSONUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.util; @@ -11,9 +11,8 @@ import java.util.Map; import java.util.TreeMap; -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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,32 +21,18 @@ public class JSONUtils { @SuppressWarnings("unchecked") public static Map getMapFromJson(String json) { - JSONParser parser = new JSONParser(); - ContainerFactory containerFactory = getContainerFactory(); Map result = null; if (json != null && !"".equals(json)) { try { - result = (Map) parser.parse(json, containerFactory); - } catch (ParseException e) { - logger.error(e.getMessage()); + JSONObject jsonObject = new JSONObject(json); + result = jsonObject.toMap(); + } catch (JSONException e) { + logger.error(e.getMessage(), e); } } return result; } - private static ContainerFactory getContainerFactory() { - ContainerFactory containerFactory = new ContainerFactory() { - public List creatArrayContainer() { - return new LinkedList(); - } - - public Map createObjectContainer() { - return new LinkedHashMap(); - } - }; - return containerFactory; - } - public static Map map2SortMap(Map jsonMap) { if (jsonMap == null || jsonMap.size() == 0) { return null; diff --git a/src/test/java/com/vmware/vip/i18n/LocaleTest.java b/src/test/java/com/vmware/vip/i18n/LocaleTest.java index ea8b126a0..caaa5e1f9 100644 --- a/src/test/java/com/vmware/vip/i18n/LocaleTest.java +++ b/src/test/java/com/vmware/vip/i18n/LocaleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vip.i18n; @@ -10,7 +10,7 @@ import com.vmware.vipclient.i18n.base.instances.LocaleMessage; import com.vmware.vipclient.i18n.exceptions.VIPClientInitException; import com.vmware.vipclient.i18n.util.LocaleUtility; -import org.json.simple.parser.ParseException; +import org.json.JSONException; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -123,7 +123,7 @@ public void normalizeToLanguageTag() { } @Test - public void testGetRegionList() throws ParseException { + public void testGetRegionList() throws JSONException { List list = new ArrayList(); list.add("en-US"); list.add("zh_CN"); @@ -136,7 +136,7 @@ public void testGetRegionList() throws ParseException { } @Test - public void testGetDisplayNamesByLanguage() throws ParseException { + public void testGetDisplayNamesByLanguage() throws JSONException { Map enResp = localeI18n.getDisplayLanguagesList("en"); Assert.assertNotNull(enResp); Map zhResp = localeI18n.getDisplayLanguagesList("zh_Hans"); diff --git a/src/test/java/com/vmware/vip/i18n/TranslationMessageTest.java b/src/test/java/com/vmware/vip/i18n/TranslationMessageTest.java index 42bb11fd4..7d5e3ffaa 100644 --- a/src/test/java/com/vmware/vip/i18n/TranslationMessageTest.java +++ b/src/test/java/com/vmware/vip/i18n/TranslationMessageTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vip.i18n; @@ -18,7 +18,7 @@ import java.util.stream.Stream; import com.ibm.icu.text.DateFormat; -import org.json.simple.JSONObject; +import org.json.JSONObject; import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/com/vmware/vipclient/i18n/messages/service/OfflineModeTest.java b/src/test/java/com/vmware/vipclient/i18n/messages/service/OfflineModeTest.java index 095f383bb..8a6a712d0 100644 --- a/src/test/java/com/vmware/vipclient/i18n/messages/service/OfflineModeTest.java +++ b/src/test/java/com/vmware/vipclient/i18n/messages/service/OfflineModeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 VMware, Inc. + * Copyright 2019-2025 VMware, Inc. * SPDX-License-Identifier: EPL-2.0 */ package com.vmware.vipclient.i18n.messages.service; @@ -20,7 +20,7 @@ import com.vmware.vipclient.i18n.messages.dto.MessagesDTO; import com.vmware.vipclient.i18n.util.FormatUtils; import com.vmware.vipclient.i18n.util.LocaleUtility; -import org.json.simple.parser.ParseException; +import org.json.JSONException; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -350,7 +350,7 @@ public void testGetMsgsOnlineModePriority() { } @Test - public void testGetSupportedLocalesOfflineBundles() throws ParseException { + public void testGetSupportedLocalesOfflineBundles() throws JSONException { //Enable offline mode String offlineResourcesBaseUrlOrig = cfg.getOfflineResourcesBaseUrl(); cfg.setOfflineResourcesBaseUrl("offlineBundles/");