Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.language;
import com.liferay.petra.string.CharPool;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.language.LanguageBuilderUtil;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.module.util.SystemBundleUtil;
import com.liferay.portal.kernel.resource.bundle.ResourceBundleLoader;
import com.liferay.portal.kernel.resource.bundle.ResourceBundleLoaderUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.PropertiesUtil;
import com.liferay.portal.kernel.util.ResourceBundleUtil;
import com.liferay.portal.kernel.util.ServiceProxyFactory;
import com.liferay.portal.kernel.util.SetUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
/**
* @author Shuyang Zhou
* @author Kamesh Sampath
*/
public class LanguageResources {
public static ResourceBundleLoader PORTAL_RESOURCE_BUNDLE_LOADER =
new ResourceBundleLoader() {
@Override
public ResourceBundle loadResourceBundle(Locale locale) {
return LanguageResources.getResourceBundle(locale);
}
};
public static String getMessage(Locale locale, String key) {
if (locale == null) {
return null;
}
String overrideValue = _getOverrideValue(key, locale);
if (overrideValue != null) {
return overrideValue;
}
Map languageMap = _languageMaps.get(locale);
if (languageMap == null) {
languageMap = _loadLocale(locale);
}
String value = languageMap.get(key);
if (value == null) {
return getMessage(getSuperLocale(locale), key);
}
return value;
}
public static ResourceBundle getResourceBundle(Locale locale) {
return new LanguageResourcesBundle(locale);
}
public static Locale getSuperLocale(Locale locale) {
Locale superLocale = _superLocales.get(locale);
if (superLocale != null) {
if (superLocale == _nullLocale) {
return null;
}
return superLocale;
}
superLocale = _getSuperLocale(locale);
if (superLocale == null) {
_superLocales.put(locale, _nullLocale);
}
else {
_superLocales.put(locale, superLocale);
}
return superLocale;
}
public void afterPropertiesSet() {
Filter languageResourceFilter = SystemBundleUtil.createFilter(
"(&(!(javax.portlet.name=*))(language.id=*)(objectClass=" +
ResourceBundle.class.getName() + "))");
_serviceTracker = new ServiceTracker<>(
_bundleContext, languageResourceFilter,
new LanguageResourceServiceTrackerCustomizer());
_serviceTracker.open();
ResourceBundleLoaderUtil.setPortalResourceBundleLoader(
PORTAL_RESOURCE_BUNDLE_LOADER);
}
public void destroy() {
_serviceTracker.close();
}
public void setConfig(String config) {
_configNames = StringUtil.split(
StringUtil.replace(config, CharPool.PERIOD, CharPool.SLASH));
}
private static void _fixValues(
Map languageMap, Properties properties) {
for (Map.Entry