Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error logging for Unsuccessful L10n Fetch ( plus code clean up) #544

Merged
merged 99 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
f4c1214
Loading configuration from the JSON configuration file
jessiejuachon Mar 11, 2020
1a4d95e
Removing code that is not yet ready to be used from the sample applic…
jessiejuachon Mar 11, 2020
5e72b73
fixing failing code scan
jessiejuachon Mar 11, 2020
73d85ca
Adding a cache properties map to hold cache details such as etag and …
jessiejuachon Mar 12, 2020
2a38107
Removing white space
jessiejuachon Mar 12, 2020
c7f5d4f
Fixing failing unit test
jessiejuachon Mar 12, 2020
056891a
Parse headers, response code, response message from an HTTP response …
jessiejuachon Mar 12, 2020
a2ba98b
Storing response headers in Map of cache properties
jessiejuachon Mar 17, 2020
17978bd
Fixing failing unit test due to NullPointerException when doing Map.p…
jessiejuachon Mar 17, 2020
6c69170
Changes after code review.
jessiejuachon Mar 17, 2020
41a8aa1
Removing exception handling for now
jessiejuachon Mar 18, 2020
dd2455d
Deprecating VIPCfg.initialize; cleaning up code
jessiejuachon Mar 19, 2020
e26d372
Storing the http response code in the cache
jessiejuachon Mar 20, 2020
01ab69e
Using cached etag as if-none-match request header value in the reques…
jessiejuachon Mar 25, 2020
750c9d2
Handling 404 response from Singleton service
jessiejuachon Mar 26, 2020
529e5cc
Using HTTP repsonse's Cache-Control max-age and timestamp to dertermi…
jessiejuachon Mar 26, 2020
b40fcf9
Moving constants to URLUtils
jessiejuachon Mar 26, 2020
fa123f9
Fixing failing test
jessiejuachon Mar 27, 2020
30b2054
Fixing failing code scan
jessiejuachon Mar 27, 2020
0c69787
Merge branch 'g11n-java-client' into g11n-java-client
Xiaochao8 Mar 27, 2020
ffc0a74
Cleaning up import in ComponentService,java
jessiejuachon Mar 30, 2020
d8450e4
Cleaning up code - caching/expiry
jessiejuachon Mar 30, 2020
d7f7641
Merge branch 'g11n-java-client' of https://github.com/jessiejuachon/s…
jessiejuachon Mar 30, 2020
0dcd827
Adding tests for new caching workflow; enabling old caching workflow …
jessiejuachon Mar 31, 2020
d06adb3
Fixing a failing test
jessiejuachon Mar 31, 2020
48c8558
Adding mock server response
jessiejuachon Mar 31, 2020
4e45bed
Removing unused file sampleconfig.json
jessiejuachon Mar 31, 2020
6a40dc8
Changes from code review
jessiejuachon Mar 31, 2020
4c3c12d
Value of VIPCfg.cacheExpiredTime is -1 when value is not set in confi…
jessiejuachon Mar 31, 2020
7e0d939
Changing a LinkedHashMap to a HashMap because insertion order does no…
jessiejuachon Apr 2, 2020
baef0d0
Adding CacheItem object to contain map of data and a another map for …
jessiejuachon Apr 3, 2020
02a96e9
Fixing failing unit test
jessiejuachon Apr 3, 2020
78d88f7
Fixing code scan issues
jessiejuachon Apr 3, 2020
655c223
Code cleanup
jessiejuachon Apr 3, 2020
8746915
Lazily instantiating cacheProps; code clean up and comments
jessiejuachon Apr 5, 2020
897a03c
Changes after code review
jessiejuachon Apr 7, 2020
3a4e183
Adding header to CacheItem.java
jessiejuachon Apr 7, 2020
b08feb4
Fixing code san issue. Synchronize on a final field
jessiejuachon Apr 7, 2020
8f57e24
Fixing code scan bug
jessiejuachon Apr 7, 2020
72c8799
Changes after code review
jessiejuachon Apr 7, 2020
92edfc8
Updating CasheService.isContainComponent to return false if cache key…
jessiejuachon Apr 7, 2020
2042554
HttpRequester if-none-match header and other customized headers are a…
jessiejuachon Apr 8, 2020
ae707ff
Code clean up; keep old caching expiration logic
jessiejuachon Apr 8, 2020
82818d5
Fixing code scan bug
jessiejuachon Apr 8, 2020
31d4ff6
Merge branch 'g11n-java-client' into g11n-java-client
jessiejuachon Apr 8, 2020
c9f83d7
code clean up
jessiejuachon Apr 9, 2020
78dcc1c
Removing response code and response msg from cache; Passing cacheItem…
jessiejuachon Apr 9, 2020
9281c64
Changes after code review
jessiejuachon Apr 10, 2020
2657762
Adding header to CacheItem.java file
jessiejuachon Apr 10, 2020
9e80f09
Fixing failing unit test
jessiejuachon Apr 10, 2020
68467f3
Changes after code review
jessiejuachon Apr 10, 2020
d67c72e
Fixing code scan bugs
jessiejuachon Apr 10, 2020
8591973
Not storing anything in cache if response is neither 200 nor 304
jessiejuachon Apr 13, 2020
22a5b29
Loading messages from specified offline resource bundles
jessiejuachon Apr 15, 2020
ce2488b
Merge branch 'g11n-java-client' of https://github.com/vmware/singleto…
jessiejuachon Apr 15, 2020
1092963
Adding header
jessiejuachon Apr 15, 2020
35d1d97
Fixing failing unie test
jessiejuachon Apr 15, 2020
ada17f1
Code changes after review; code clean up
jessiejuachon Apr 16, 2020
fc60eef
Using java.nio.file.Paths
jessiejuachon Apr 17, 2020
3e70449
Offline mode as fallback when service fetch fails
jessiejuachon Apr 17, 2020
609d8e4
Resetting VIPCfg and I18nFactory instances for each test
jessiejuachon Apr 17, 2020
dd19b1c
Resetting VIPCfg and I18nFactory after test
jessiejuachon Apr 17, 2020
7389f8b
Fixing tests
jessiejuachon Apr 17, 2020
5b92e44
Limit to wiremock test logging
jessiejuachon Apr 20, 2020
dfb41b5
Decreasing unit test log
jessiejuachon Apr 20, 2020
21a7105
this test is timing out and trying to connect 70+ times
jessiejuachon Apr 21, 2020
84343d5
Adding comments to code
jessiejuachon Apr 21, 2020
be8e443
Merge branch 'g11n-java-client' of https://github.com/vmware/singleto…
jessiejuachon Apr 21, 2020
b805d36
Adding timestamp to cache fromn local bundle
jessiejuachon Apr 21, 2020
17bc16c
Deprecating methods in TranslationMessage; adding new method getMessage
jessiejuachon Apr 23, 2020
15da010
Added tests for TranslationMessage.getMessage
jessiejuachon Apr 24, 2020
631de86
Fixing test
jessiejuachon Apr 24, 2020
ffd9adb
Fixing test
jessiejuachon Apr 24, 2020
c00f7ae
Fixing test
jessiejuachon Apr 24, 2020
d0504c4
Removing comment field because source collection is not supported any…
jessiejuachon Apr 24, 2020
79b18d0
Code clean up
jessiejuachon Apr 24, 2020
ec9f5db
Changes from code review
jessiejuachon Apr 24, 2020
2e8bd36
Code clean up
jessiejuachon Apr 24, 2020
4e44a8c
Optional SourceOpt in initialization
jessiejuachon Apr 26, 2020
de5c4ee
Fixing test
jessiejuachon Apr 27, 2020
406cb2a
Adding comments to code
jessiejuachon Apr 28, 2020
c80696a
Adding comment for javadoc
jessiejuachon Apr 28, 2020
79d111e
Cleaning up code
jessiejuachon Apr 28, 2020
24d8d5d
Code clean up
jessiejuachon Apr 28, 2020
23e62b6
Fixing test
jessiejuachon Apr 28, 2020
369643f
Removing source message fallback from this PR
jessiejuachon Apr 29, 2020
4e67e25
Merge branch 'g11n-java-client' into g11n-java-client
jessiejuachon Apr 29, 2020
636b5b4
Default locale in config file instead of hardcoded; get supported loc…
jessiejuachon May 5, 2020
71a87e5
Merge branch 'g11n-java-client' into g11n-java-client
jessiejuachon May 5, 2020
b9a90e3
Fixing test
jessiejuachon May 5, 2020
060666d
Fixing tests
jessiejuachon May 5, 2020
52e3695
Default locale to Locale.ENGLISH if not set in config file
jessiejuachon May 5, 2020
2858ebc
Changed after code review: code clean up, bug fix
jessiejuachon May 6, 2020
bbe3047
Update src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local…
jessiejuachon May 8, 2020
fa56388
Update src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local…
jessiejuachon May 8, 2020
08cd96d
code clean up, error logging, bug fix
jessiejuachon May 8, 2020
e89ff56
Merge branch 'g11n-java-client' of https://github.com/vmware/singleto…
jessiejuachon May 8, 2020
119aebd
code clean up
jessiejuachon May 8, 2020
e8a937d
code clean up
jessiejuachon May 11, 2020
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 src/main/java/com/vmware/vipclient/i18n/VIPCfg.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

Expand All @@ -23,6 +24,7 @@
import com.vmware.vipclient.i18n.exceptions.VIPClientInitException;
import com.vmware.vipclient.i18n.messages.dto.MessagesDTO;
import com.vmware.vipclient.i18n.messages.service.ProductService;
import com.vmware.vipclient.i18n.util.LocaleUtility;

/**
* a class uses to define the global environment setting for I18nFactory
Expand Down Expand Up @@ -176,6 +178,8 @@ public void initialize(String cfg) throws VIPClientInitException {
if (prop.containsKey("cacheExpiredTime"))
this.cacheExpiredTime = Long.parseLong(prop
.getString("cacheExpiredTime"));
if (prop.containsKey("defaultLocale"))
LocaleUtility.setDefaultLocale(Locale.forLanguageTag(prop.getString("defaultLocale")));
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/vmware/vipclient/i18n/base/DataSourceEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@
*/
package com.vmware.vipclient.i18n.base;

import com.vmware.vipclient.i18n.messages.api.opt.LocaleOpt;
import com.vmware.vipclient.i18n.messages.api.opt.MessageOpt;
import com.vmware.vipclient.i18n.messages.api.opt.local.LocalLocaleOpt;
import com.vmware.vipclient.i18n.messages.api.opt.local.LocalMessagesOpt;
import com.vmware.vipclient.i18n.messages.api.opt.server.ComponentBasedOpt;
import com.vmware.vipclient.i18n.messages.dto.MessagesDTO;
import com.vmware.vipclient.i18n.messages.api.opt.server.RemoteLocaleOpt;

public enum DataSourceEnum {
Bundle {
@Override
public MessageOpt createMessageOpt(MessagesDTO dto) {
return new LocalMessagesOpt(dto);
}

@Override
public LocaleOpt createLocaleOpt() {
return new LocalLocaleOpt();
}
},
VIP {
@Override
public MessageOpt createMessageOpt(MessagesDTO dto) {
return new ComponentBasedOpt(dto);
}

@Override
public LocaleOpt createLocaleOpt() {
return new RemoteLocaleOpt();
}
};
public abstract MessageOpt createMessageOpt(MessagesDTO dto);
public abstract LocaleOpt createLocaleOpt();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ public void addCacheData(String key, String value) {
this.cachedData.put(key, value);
}

public boolean isCachedDataEmpty() {
return this.cachedData.isEmpty();
}

public synchronized void addCachedData(Map<String, String> cachedData) {
if (cachedData != null)
this.cachedData.putAll(cachedData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;

import com.vmware.vipclient.i18n.VIPCfg;
import com.vmware.vipclient.i18n.messages.service.LocaleService;

/**
Expand Down Expand Up @@ -45,7 +46,8 @@ public Map<String, Map<String, String>> getRegionList(List<String> supportedLang
* determined by the displanLanguage parameter
*/
public Map<String, String> getDisplayLanguagesList(String displayLanguage) {
return new LocaleService().getDisplayNamesFromCLDR(displayLanguage);
return new LocaleService().getDisplayNamesFromCLDR(displayLanguage,
VIPCfg.getInstance().getMsgOriginsQueue().listIterator());
}

/**
Expand All @@ -55,7 +57,8 @@ public Map<String, String> getDisplayLanguagesList(String displayLanguage) {
*/
public List<String> getSupportedLanguageTagList() {
Map<String, String> languageTagMap = new LocaleService()
.getDisplayNamesFromCLDR(java.util.Locale.ENGLISH.toLanguageTag());
.getDisplayNamesFromCLDR(java.util.Locale.ENGLISH.toLanguageTag(),
VIPCfg.getInstance().getMsgOriginsQueue().listIterator());
Collection<String> keyCollection = languageTagMap.keySet();
List<String> languageTagList = new ArrayList<String>(keyCollection);
return languageTagList;
Expand All @@ -69,7 +72,8 @@ public List<String> getSupportedLanguageTagList() {
* @return a list contains the display names
*/
public List<String> getSupportedDisplayNameList(String displayLanguage) {
Map<String, String> dispNameMap = new LocaleService().getDisplayNamesFromCLDR(displayLanguage);
Map<String, String> dispNameMap = new LocaleService().getDisplayNamesFromCLDR(displayLanguage,
VIPCfg.getInstance().getMsgOriginsQueue().listIterator());
Collection<String> valueCollection = dispNameMap.values();
List<String> dispNameList = new ArrayList<String>(valueCollection);
return dispNameList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public String getString(final Locale locale, final String component,
// source as latest, not return the old translation
if (source != null && !"".equals(source) && !VIPCfg.getInstance().isPseudo()) {
MessagesDTO remoteEnDTO = new MessagesDTO(component, key, source,
LocaleUtility.defaultLocale.toLanguageTag(), this.cfg);
LocaleUtility.getDefaultLocale().toLanguageTag(), this.cfg);
String remoteEnMsg = s.getString(remoteEnDTO);
if (!source.equals(remoteEnMsg)) {
translation = source;
Expand Down Expand Up @@ -176,7 +176,7 @@ public String getString(final Locale locale, final String component,
if (args != null && args.length > 0) {
if ((null != translation && translation.equals(source)) || VIPCfg.getInstance().isPseudo()) {
translation = FormatUtils.formatMsg(translation,
LocaleUtility.defaultLocale, args);
LocaleUtility.getDefaultLocale(), args);
} else {
translation = FormatUtils.formatMsg(translation, locale, args);
}
Expand Down Expand Up @@ -366,7 +366,7 @@ public String getString2(final String component,
String source;
try {
ResourceBundle rb = ResourceBundle.getBundle(bundle,
LocaleUtility.defaultLocale);
LocaleUtility.getDefaultLocale());
source = rb.getString(key);
} catch (Exception e) {
this.logger.error(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public MessageFormat() {
}

public MessageFormat(String pattern) {
this.locale = LocaleUtility.defaultLocale;
this.locale = LocaleUtility.getDefaultLocale();
applyPattern(pattern);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2019 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.vipclient.i18n.messages.api.opt;

import java.util.Map;

public interface LocaleOpt {
public Map<String, String> getLanguages(String displayLanguage);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2019 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.vipclient.i18n.messages.api.opt.local;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vmware.vipclient.i18n.VIPCfg;
import com.vmware.vipclient.i18n.messages.api.opt.LocaleOpt;

public class LocalLocaleOpt implements LocaleOpt{

private Logger logger = LoggerFactory.getLogger(LocalLocaleOpt.class);
private static final String BUNDLE_PREFIX = "messages_";

@Override
public Map<String, String> getLanguages(String displayLanguage) {

Map<String, String> supportedLocales = new HashMap<String, String>();
Locale inLocale = Locale.forLanguageTag(displayLanguage);
String offlineResourcesBaseUrl = VIPCfg.getInstance().getOfflineResourcesBaseUrl();
try {
Path path = Paths.get(Thread.currentThread().getContextClassLoader().
getResource(Paths.get(offlineResourcesBaseUrl).toString()).toURI());

try (Stream<Path> listOfFiles = Files.walk(path).filter(p -> p.toFile().isFile())) {
listOfFiles.map(file -> {
String fileName = file.getFileName().toString();
return fileName.substring(BUNDLE_PREFIX.length(), fileName.indexOf('.'));
}).forEach(s->supportedLocales.put(s, Locale.forLanguageTag(s).getDisplayName(inLocale)));
}
} catch (Exception e) {
logger.debug(e.getMessage());
}
return supportedLocales;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

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

import com.vmware.vipclient.i18n.VIPCfg;
import com.vmware.vipclient.i18n.base.DataSourceEnum;
import com.vmware.vipclient.i18n.base.cache.MessageCacheItem;
import com.vmware.vipclient.i18n.messages.api.opt.MessageOpt;
import com.vmware.vipclient.i18n.messages.api.opt.Opt;
Expand All @@ -20,6 +27,8 @@

public class LocalMessagesOpt implements Opt, MessageOpt {

private Logger logger = LoggerFactory.getLogger(LocalMessagesOpt.class.getName());

private static final String OFFLINE_RESOURCE_PATH = "{0}/messages_{1}.json";
private MessagesDTO dto;

Expand All @@ -35,18 +44,30 @@ public JSONObject getComponentMessages() {

@Override
public void getComponentMessages(MessageCacheItem cacheItem) {
String resource = VIPCfg.getInstance().getOfflineResourcesBaseUrl();
String filePath = FormatUtils.format(OFFLINE_RESOURCE_PATH, dto.getComponent(), dto.getLocale());
Path path = Paths.get(resource, filePath);
Locale bestMatch = Locale.lookup(Arrays.asList(new Locale.LanguageRange((dto.getLocale()))),
getSupportedLocales());
try {
String filePath = FormatUtils.format(OFFLINE_RESOURCE_PATH, dto.getComponent(), bestMatch.toLanguageTag());
Path path = Paths.get(VIPCfg.getInstance().getOfflineResourcesBaseUrl(), filePath);
path = Paths.get(Thread.currentThread().getContextClassLoader().
getResource(path.toString()).toURI());
Map<String, String> messages = JSONBundleUtil.getMessages(path);
cacheItem.addCachedData(messages);
cacheItem.setTimestamp(System.currentTimeMillis());
} catch (Exception e) {
logger.debug(e.getMessage());
// Do not update cacheItem
}
}


private List<Locale> getSupportedLocales() {
Map<String, String> supportedLanguages = DataSourceEnum.Bundle.createLocaleOpt()
.getLanguages(dto.getLocale());
List<Locale> supportedLocales = new LinkedList<Locale>();
for (String languageTag : supportedLanguages.keySet()) {
supportedLocales.add(Locale.forLanguageTag(languageTag));
}
return supportedLocales;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ public void getComponentMessages(MessageCacheItem cacheItem) {

if (responseCode != null && (responseCode.equals(HttpURLConnection.HTTP_OK) ||
responseCode.equals(HttpURLConnection.HTTP_NOT_MODIFIED))) {

if (response.get(URLUtils.RESPONSE_TIMESTAMP) != null)
cacheItem.setTimestamp((long) response.get(URLUtils.RESPONSE_TIMESTAMP) );
jessiejuachon marked this conversation as resolved.
Show resolved Hide resolved
if (response.get(URLUtils.HEADERS) != null)
cacheItem.setEtag(URLUtils.createEtagString((Map<String, List<String>>) response.get(URLUtils.HEADERS)));
if (response.get(URLUtils.MAX_AGE_MILLIS) != null)
cacheItem.setMaxAgeMillis((Long) response.get(URLUtils.MAX_AGE_MILLIS));

if (responseCode.equals(HttpURLConnection.HTTP_OK)) {
JSONObject respObj = (JSONObject) JSONValue.parse((String) response.get(URLUtils.BODY));
Expand All @@ -69,6 +62,12 @@ public void getComponentMessages(MessageCacheItem cacheItem) {
cacheItem.addCachedData(messages);
}
}
if (response.get(URLUtils.RESPONSE_TIMESTAMP) != null)
cacheItem.setTimestamp((long) response.get(URLUtils.RESPONSE_TIMESTAMP) );
if (response.get(URLUtils.HEADERS) != null)
cacheItem.setEtag(URLUtils.createEtagString((Map<String, List<String>>) response.get(URLUtils.HEADERS)));
if (response.get(URLUtils.MAX_AGE_MILLIS) != null)
cacheItem.setMaxAgeMillis((Long) response.get(URLUtils.MAX_AGE_MILLIS));
} catch (Exception e) {
logger.error("Failed to get messages");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
import org.slf4j.LoggerFactory;

import com.vmware.vipclient.i18n.VIPCfg;
import com.vmware.vipclient.i18n.messages.api.opt.LocaleOpt;
import com.vmware.vipclient.i18n.messages.api.url.URLUtils;
import com.vmware.vipclient.i18n.messages.api.url.V2URL;
import com.vmware.vipclient.i18n.util.ConstantsKeys;
import com.vmware.vipclient.i18n.util.JSONUtils;

public class LocaleOpt {
public class RemoteLocaleOpt implements LocaleOpt{

private Logger logger = LoggerFactory.getLogger(LocaleOpt.class.getName());
private Logger logger = LoggerFactory.getLogger(RemoteLocaleOpt.class.getName());

public LocaleOpt() {
public RemoteLocaleOpt() {
}

public Map<String, String> getTerritoriesFromCLDR(String language) {
Expand All @@ -46,7 +47,8 @@ public Map<String, String> getTerritoriesFromCLDR(String language) {
return respMap;
}

public Map<String, String> getDisplayNamesFromCLDR(String language) {
@Override
public Map<String, String> getLanguages(String language) {
Map<String, Object> response = VIPCfg.getInstance().getVipService().getHttpRequester()
.request(
V2URL.getSupportedLanguageListURL(language,
Expand All @@ -70,7 +72,7 @@ public Map<String, String> getDisplayNamesFromCLDR(String language) {
tmpMap.get(ConstantsKeys.DISPLAY_NAME).toString());
}
}
} catch (ParseException e) {
} catch (Exception e) {
logger.error(e.getMessage());
}
return dispMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.vmware.vipclient.i18n.VIPCfg;
import com.vmware.vipclient.i18n.base.cache.Cache;
import com.vmware.vipclient.i18n.base.cache.FormatCacheItem;
import com.vmware.vipclient.i18n.base.cache.MessageCacheItem;
import com.vmware.vipclient.i18n.messages.dto.MessagesDTO;
import com.vmware.vipclient.i18n.util.ConstantsKeys;
Expand Down Expand Up @@ -104,22 +105,21 @@ public void addCacheOfStatus(Map<String, String> dataMap) {

public List<Locale> getSupportedLocalesFromCache() {
List<Locale> locales = new ArrayList<Locale>();
Cache c = VIPCfg.getInstance().getCacheManager().getCache(VIPCfg.CACHE_L3);
Cache c = VIPCfg.getInstance().getCacheManager().getCache(VIPCfg.CACHE_L2);
if (c == null) {
return locales;
}
Set<String> keySet = c.keySet();
Object[] keys = keySet.toArray();
Map<String, Object> tempMap = new HashMap<String, Object>();
for (Object key : keys) {
String ckey = (String) key;
String locale = ckey.substring(
ckey.indexOf(ConstantsKeys.UNDERLINE_POUND) + 2,
ckey.length());
if (!tempMap.containsKey(locale)) {
locales.add(Locale.forLanguageTag(locale.replace("_", "-")));
tempMap.put(locale, locale);
}

for (String key : keySet) {
if (key.startsWith(LocaleService.DISPN_PREFIX)) {
FormatCacheItem cacheItem = (FormatCacheItem) c.get(key);
Map<String, String> langTagToDisplayNameMap = cacheItem.getCachedData();
for (String languageTag : langTagToDisplayNameMap.keySet()) {
locales.add(Locale.forLanguageTag(languageTag));
}
break;
}
}
return locales;
}
Expand Down
Loading