Example usage for java.util Locale getCountry

List of usage examples for java.util Locale getCountry

Introduction

In this page you can find the example usage for java.util Locale getCountry.

Prototype

public String getCountry() 

Source Link

Document

Returns the country/region code for this locale, which should either be the empty string, an uppercase ISO 3166 2-letter code, or a UN M.49 3-digit code.

Usage

From source file:com.salesmanager.core.util.PaymentUtil.java

public static Map<String, PaymentMethod> getPaymentMethods(int merchantId, Locale locale) throws Exception {

    Map payments = new HashMap();

    ResourceBundle bundle = ResourceBundle.getBundle("modules", locale);
    if (bundle == null) {
        log.error("Cannot load ResourceBundle checkout.properties");
    }/*from w ww  .j a v a 2  s  .  c  om*/

    ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService);

    CountryDescription countryDescription = CountryUtil.getCountryByIsoCode(locale.getCountry(), locale);

    Map modules = new HashMap();

    if (countryDescription != null) {
        modules = rservice.getPaymentMethodsMap(countryDescription.getId().getCountryId());
    }

    ConfigurationRequest requestvo = new ConfigurationRequest(merchantId, true,
            PaymentConstants.MODULE_PAYMENT);
    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    ConfigurationResponse responsevo = mservice.getConfiguration(requestvo);
    List config = responsevo.getMerchantConfigurationList();

    if (config != null) {
        Iterator it = config.iterator();
        while (it.hasNext()) {

            MerchantConfiguration m = (MerchantConfiguration) it.next();

            String key = m.getConfigurationKey();
            if (key.equals(PaymentConstants.MODULE_PAYMENT_INDICATOR_NAME)) {// module
                // configured

                // if(m.getConfigurationValue().equals("true")) {

                PaymentMethod method = null;
                // try to retreive the module first
                if (payments.containsKey(m.getConfigurationValue1())) {

                    method = (PaymentMethod) payments.get(m.getConfigurationValue1());

                } else {

                    method = new PaymentMethod();

                }

                if (m.getConfigurationValue() != null && m.getConfigurationValue().equals("true")) {
                    //payments.remove(m
                    //      .getConfigurationValue1());
                    //continue;
                    method.setEnabled(true);
                }

                CoreModuleService cms = (CoreModuleService) modules.get(m.getConfigurationValue1());
                if (cms != null) {
                    method.setPaymentImage(cms.getCoreModuleServiceLogoPath());
                }

                method.setPaymentModuleName(m.getConfigurationValue1());
                if (bundle != null) {
                    try {
                        String label = bundle.getString("module." + m.getConfigurationValue1());
                        if (StringUtils.isBlank(label)) {
                            label = "";
                        }
                        method.setPaymentMethodName(label);
                        String text = bundle.getString("module.paymenttext." + m.getConfigurationValue1());
                        method.setPaymentModuleText(text);
                    } catch (Exception e) {
                    }
                }
                if (m.getConfigurationValue() != null && m.getConfigurationValue().equals("true")) {
                    method.setEnabled(true);
                }

                payments.put(m.getConfigurationValue1(), method);
                continue;
            }

            if (key.contains(PaymentConstants.MODULE_PAYMENT_GATEWAY)) {// gateway
                // module

                PaymentMethod method = null;
                // try to retreive the module first
                if (payments.containsKey(m.getConfigurationModule())) {

                    method = (PaymentMethod) payments.get(m.getConfigurationModule());

                } else {

                    method = new PaymentMethod();

                }

                IntegrationProperties props = null;
                /** ASSUMING PROPERTIES ARE IN CONFIGURATION_VALUE 2 **/
                if (!StringUtils.isBlank(m.getConfigurationValue2())) {
                    props = MerchantConfigurationUtil.getIntegrationProperties(m.getConfigurationValue2(), ";");
                }

                if (props != null && props.getProperties3() != null && props.getProperties3().equals("2")) {// use
                    // cvv
                    method.addConfig("CVV", "true");

                }

                // core_modules_services subtype
                method.setType(1);
                payments.put(m.getConfigurationModule(), method);
                continue;

            }

            if (key.contains(PaymentConstants.MODULE_PAYMENT)) {// single
                // payment
                // module

                PaymentMethod method = null;
                // try to retreive the module first
                if (payments.containsKey(m.getConfigurationModule())) {

                    method = (PaymentMethod) payments.get(m.getConfigurationModule());

                } else {

                    method = new PaymentMethod();

                }

                // core_modules_services subtype
                method.setType(0);
                method.addConfig("key", m.getConfigurationValue());
                method.addConfig("key1", m.getConfigurationValue1());
                method.addConfig("key2", m.getConfigurationValue2());

                payments.put(m.getConfigurationModule(), method);
                continue;

            }

        }
    }

    Set entries = payments.keySet();

    Map paymentMethods = new HashMap();

    for (Object o : entries) {
        String key = (String) o;

        PaymentMethod pm = (PaymentMethod) payments.get(key);

        if (pm.isEnabled()) {
            paymentMethods.put(pm.getPaymentModuleName(), pm);
        }
    }

    return paymentMethods;

}

From source file:com.ddiiyy.xydz.xutils.util.OtherUtils.java

/**
 * @param context if null, use the default format
 *                (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30).
 * @return/*from  ww  w.  j  a  va  2  s .c o m*/
 */
@SuppressLint("DefaultLocale")
@SuppressWarnings("rawtypes")
public static String getUserAgent(Context context) {
    String webUserAgent = null;
    if (context != null) {
        try {
            Class sysResCls = Class.forName("com.android.internal.R$string");
            Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
            Integer resId = (Integer) webUserAgentField.get(null);
            webUserAgent = context.getString(resId);
        } catch (Throwable ignored) {
        }
    }
    if (TextUtils.isEmpty(webUserAgent)) {
        webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1";
    }

    Locale locale = Locale.getDefault();
    StringBuffer buffer = new StringBuffer();
    // Add version
    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        buffer.append(version);
    } else {
        // default to "1.0"
        buffer.append("1.0");
    }
    buffer.append("; ");
    final String language = locale.getLanguage();
    if (language != null) {
        buffer.append(language.toLowerCase());
        final String country = locale.getCountry();
        if (country != null) {
            buffer.append("-");
            buffer.append(country.toLowerCase());
        }
    } else {
        // default to "en"
        buffer.append("en");
    }
    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
        final String model = Build.MODEL;
        if (model.length() > 0) {
            buffer.append("; ");
            buffer.append(model);
        }
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        buffer.append(" Build/");
        buffer.append(id);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
}

From source file:com.lidroid.xutils.utils.OtherUtils.java

/**
 * @param context if null, use the default format
 *                (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30).
 * @return//from w  ww. ja v a  2 s .c om
 */
@SuppressLint("DefaultLocale")
public static String getUserAgent(Context context) {
    String webUserAgent = null;
    if (context != null) {
        try {
            Class<?> sysResCls = Class.forName("com.android.internal.R$string");
            Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
            Integer resId = (Integer) webUserAgentField.get(null);
            webUserAgent = context.getString(resId);
        } catch (Throwable ignored) {
        }
    }
    if (TextUtils.isEmpty(webUserAgent)) {
        webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1";
    }

    Locale locale = Locale.getDefault();
    StringBuffer buffer = new StringBuffer();
    // Add version
    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        buffer.append(version);
    } else {
        // default to "1.0"
        buffer.append("1.0");
    }
    buffer.append("; ");
    final String language = locale.getLanguage();
    if (language != null) {
        buffer.append(language.toLowerCase());
        final String country = locale.getCountry();
        if (country != null) {
            buffer.append("-");
            buffer.append(country.toLowerCase());
        }
    } else {
        // default to "en"
        buffer.append("en");
    }
    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
        final String model = Build.MODEL;
        if (model.length() > 0) {
            buffer.append("; ");
            buffer.append(model);
        }
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        buffer.append(" Build/");
        buffer.append(id);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
}

From source file:com.cat.external.util.OtherUtils.java

/**
 * @param context if null, use the default format
 *                (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30).
 * @return/*from  w w  w.  ja v  a 2 s.c o  m*/
 */
@SuppressLint("DefaultLocale")
public static String getUserAgent(Context context) {
    String webUserAgent = null;
    if (context != null) {
        try {
            @SuppressWarnings("rawtypes")
            Class sysResCls = Class.forName("com.android.internal.R$string");
            Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
            Integer resId = (Integer) webUserAgentField.get(null);
            webUserAgent = context.getString(resId);
        } catch (Throwable ignored) {
        }
    }
    if (TextUtils.isEmpty(webUserAgent)) {
        webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1";
    }

    Locale locale = Locale.getDefault();
    StringBuffer buffer = new StringBuffer();
    // Add version
    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        buffer.append(version);
    } else {
        // default to "1.0"
        buffer.append("1.0");
    }
    buffer.append("; ");
    final String language = locale.getLanguage();
    if (language != null) {
        buffer.append(language.toLowerCase());
        final String country = locale.getCountry();
        if (country != null) {
            buffer.append("-");
            buffer.append(country.toLowerCase());
        }
    } else {
        // default to "en"
        buffer.append("en");
    }
    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
        final String model = Build.MODEL;
        if (model.length() > 0) {
            buffer.append("; ");
            buffer.append(model);
        }
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        buffer.append(" Build/");
        buffer.append(id);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
}

From source file:com.ruint.core.utils.OtherUtils.java

/**
 * @param context//from   www.  j a  v  a2 s .  c  o m
 *          if null, use the default format (Mozilla/5.0 (Linux; U; Android
 *          %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0
 *          %sSafari/534.30).
 * @return
 */
@SuppressWarnings("rawtypes")
public static String getUserAgent(Context context) {
    String webUserAgent = null;
    if (context != null) {
        try {
            Class sysResCls = Class.forName("com.android.internal.R$string");
            Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
            Integer resId = (Integer) webUserAgentField.get(null);
            webUserAgent = context.getString(resId);
        } catch (Throwable ignored) {
        }
    }
    if (TextUtils.isEmpty(webUserAgent)) {
        webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1";
    }

    Locale locale = Locale.getDefault();
    StringBuffer buffer = new StringBuffer();
    // Add version
    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        buffer.append(version);
    } else {
        // default to "1.0"
        buffer.append("1.0");
    }
    buffer.append("; ");
    final String language = locale.getLanguage();
    if (language != null) {
        buffer.append(language.toLowerCase());
        final String country = locale.getCountry();
        if (country != null) {
            buffer.append("-");
            buffer.append(country.toLowerCase());
        }
    } else {
        // default to "en"
        buffer.append("en");
    }
    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
        final String model = Build.MODEL;
        if (model.length() > 0) {
            buffer.append("; ");
            buffer.append(model);
        }
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        buffer.append(" Build/");
        buffer.append(id);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
}

From source file:com.libframework.annotation.util.OtherUtils.java

/**
 * @param context if null, use the default format
 *                (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30).
 * @return//from  ww w . j  a v a 2 s . c o  m
 */
public static String getUserAgent(Context context) {
    String webUserAgent = null;
    if (context != null) {
        try {
            Class<?> sysResCls = Class.forName("com.android.internal.R$string");
            Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
            Integer resId = (Integer) webUserAgentField.get(null);
            webUserAgent = context.getString(resId);
        } catch (Throwable ignored) {
        }
    }
    if (TextUtils.isEmpty(webUserAgent)) {
        webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1";
    }

    Locale locale = Locale.getDefault();
    StringBuffer buffer = new StringBuffer();
    // Add version
    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        buffer.append(version);
    } else {
        // default to "1.0"
        buffer.append("1.0");
    }
    buffer.append("; ");
    final String language = locale.getLanguage();
    if (language != null) {
        buffer.append(language.toLowerCase(Locale.getDefault()));
        final String country = locale.getCountry();
        if (country != null) {
            buffer.append("-");
            buffer.append(country.toLowerCase(Locale.getDefault()));
        }
    } else {
        // default to "en"
        buffer.append("en");
    }
    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
        final String model = Build.MODEL;
        if (model.length() > 0) {
            buffer.append("; ");
            buffer.append(model);
        }
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        buffer.append(" Build/");
        buffer.append(id);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
}

From source file:lucee.commons.i18n.FormatUtil.java

private static void addCustom(List<DateFormat> list, Locale locale, short formatType) {
    // get custom formats from file
    Config config = ThreadLocalPageContext.getConfig();
    Resource dir = config.getConfigDir().getRealResource("locales");
    if (dir.isDirectory()) {
        String appendix = "-datetime";
        if (formatType == FORMAT_TYPE_DATE)
            appendix = "-date";
        if (formatType == FORMAT_TYPE_TIME)
            appendix = "-time";

        Resource file = dir// ww  w  . ja va 2  s  .c  om
                .getRealResource(locale.getLanguage() + "-" + locale.getCountry() + appendix + ".df");
        if (file.isFile()) {
            try {
                String content = IOUtil.toString(file, (Charset) null);
                String[] arr = lucee.runtime.type.util.ListUtil.listToStringArray(content, '\n');
                String line;
                SimpleDateFormat sdf;
                for (int i = 0; i < arr.length; i++) {
                    line = arr[i].trim();
                    if (StringUtil.isEmpty(line))
                        continue;
                    sdf = new SimpleDateFormat(line, locale);
                    if (!list.contains(sdf))
                        list.add(sdf);
                }

            } catch (Throwable t) {
            }
        }
    }
}

From source file:org.dspace.core.I18nUtil.java

/**
 * Get the appropriate localized version of a file according to language settings
 * e. g. help files in jsp/help//*w  w  w . j  a  va2  s. com*/
 *
 * @param locale
 *        Locale to get the file for
 * @param fileName
 *        String fileName, to get the localized file for
 * @param fileType
 *        String file extension
 * @return localizedFileName
 *          String - localized filename
 */
private static String getFilename(Locale locale, String fileName, String fileType) {
    String localizedFileName = null;
    boolean fileFound = false;
    // with Language, Country, Variant
    String fileNameLCV = null;
    // with Language, Country
    String fileNameLC = null;
    // with Language
    String fileNameL = null;
    fileNameL = fileName + "_" + locale.getLanguage();

    if (fileType == null) {
        fileType = "";
    }

    if (!("".equals(locale.getCountry()))) {
        fileNameLC = fileName + "_" + locale.getLanguage() + "_" + locale.getCountry();

        if (!("".equals(locale.getVariant()))) {
            fileNameLCV = fileName + "_" + locale.getLanguage() + "_" + locale.getCountry() + "_"
                    + locale.getVariant();
        }
    }

    if (fileNameLCV != null && !fileFound) {
        File fileTmp = new File(fileNameLCV + fileType);
        if (fileTmp.exists()) {
            fileFound = true;
            localizedFileName = fileNameLCV + fileType;
        }
    }

    if (fileNameLC != null && !fileFound) {
        File fileTmp = new File(fileNameLC + fileType);
        if (fileTmp.exists()) {
            fileFound = true;
            localizedFileName = fileNameLC + fileType;
        }
    }

    if (fileNameL != null && !fileFound) {
        File fileTmp = new File(fileNameL + fileType);
        if (fileTmp.exists()) {
            fileFound = true;
            localizedFileName = fileNameL + fileType;
        }
    }
    if (!fileFound) {
        localizedFileName = fileName + fileType;
    }
    return localizedFileName;
}

From source file:com.salesmanager.core.util.ShippingUtil.java

/**
 * Builds a Map<String,String> of package options ID, CODE from the service
 * .properties file the package line must be built using
 * <ID>|<SHIPPING_CODE>;<ID>|<SHIPPING_CODE>
 * /*from   ww  w .j a  v  a 2 s .co  m*/
 * @param packageline
 * @param moduleid
 * @param locale
 * @return
 */
public static Map<String, String> buildPackageMap(String moduleid, Locale locale) throws Exception {

    ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService);

    ModuleConfiguration serviceconfig = rservice.getModuleConfiguration(moduleid, "packages",
            locale.getCountry());

    if (serviceconfig == null) {
        serviceconfig = rservice.getModuleConfiguration(moduleid, "packages", "XX");// generic
    }

    if (serviceconfig == null) {
        throw new Exception(
                "ModuleConfiguration does not exist for " + moduleid + "-packages-XX-" + locale.getCountry());
    }

    String packageline = serviceconfig.getConfigurationValue();

    ResourceBundle bundle = ResourceBundle.getBundle(moduleid, locale);
    Map packsmap = getConfigurationMap(packageline, ";", "|");

    Map returnmap = new HashMap();

    Iterator it = packsmap.keySet().iterator();
    while (it.hasNext()) {
        String pkgid = (String) it.next();
        String label = bundle.getString("shipping.quote.packageoption.label." + pkgid);
        returnmap.put(pkgid, label);
    }
    return returnmap;
}

From source file:ca.psiphon.PsiphonTunnel.java

private static String getDeviceRegion(Context context) {
    String region = "";
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        region = telephonyManager.getSimCountryIso();
        if (region == null) {
            region = "";
        }//from  w w  w .  j  a  va  2  s .c o m
        if (region.length() == 0 && telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
            region = telephonyManager.getNetworkCountryIso();
            if (region == null) {
                region = "";
            }
        }
    }
    if (region.length() == 0) {
        Locale defaultLocale = Locale.getDefault();
        if (defaultLocale != null) {
            region = defaultLocale.getCountry();
        }
    }
    return region.toUpperCase(Locale.US);
}