Example usage for java.util Locale getLanguage

List of usage examples for java.util Locale getLanguage

Introduction

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

Prototype

public String getLanguage() 

Source Link

Document

Returns the language code of this Locale.

Usage

From source file:com.frameworkset.platform.cms.driver.i18n.CmsLocaleManager.java

/**
 * Sets the default locale of the Java VM to <code>{@link Locale#ENGLISH}</code> if the 
 * current default has any other language then English set.<p>
 *
 * This is required because otherwise the default (English) resource bundles 
 * would not be displayed for the English locale if a translated default locale exists.<p>
 * /*ww  w .  j  a  va 2s .c  om*/
 * Here's an example of how this issues shows up:
 * On a German server, the default locale usually is <code>{@link Locale#GERMAN}</code>.
 * All English translations for OpenCms are located in the "default" message files, for example 
 * <code>com.frameworkset.platform.cms.driver.i18n.message.properties</code>. If the German localization is installed, it will be
 * located in <code>com.frameworkset.platform.cms.driver.i18n.message_de.properties</code>. If user has English selected
 * as his locale, the default Java lookup mechanism first tries to find 
 * <code>com.frameworkset.platform.cms.driver.i18n.message_en.properties</code>. However, this file does not exist, since the
 * English localization is kept in the default file. Next, the Java lookup mechanism tries to find the servers
 * default locale, which in this example is German. Since there is a German message file, the Java lookup mechanism
 * is finished and uses this German localization, not the default file. Therefore the 
 * user get the German localization, not the English one.
 * Setting the default locale explicitly to English avoids this issue.<p>
 */
private static void setDefaultLocale() {

    // set the default locale to english
    // this is required because otherwise the default (english) resource bundles 
    // would not be displayed for the english locale if a translated locale exists

    Locale oldLocale = Locale.getDefault();
    if (!(Locale.ENGLISH.getLanguage().equals(oldLocale.getLanguage()))) {
        // default language is not English
        try {
            Locale.setDefault(Locale.ENGLISH);
            //                if (CmsLog.INIT.isInfoEnabled()) {
            //                    CmsLog.INIT.info(Messages.get().getBundle().key(
            //                        Messages.INIT_I18N_DEFAULT_LOCALE_2,
            //                        Locale.ENGLISH,
            //                        oldLocale));
            //                }
        } catch (Exception e) {
            // any Exception: the locale has not been changed, so there may be issues with the English
            // localization but OpenCms will run in general
            //                CmsLog.INIT.error(Messages.get().getBundle().key(
            //                    Messages.LOG_UNABLE_TO_SET_DEFAULT_LOCALE_2,
            //                    Locale.ENGLISH,
            //                    oldLocale), e);
        }
    } else {
        //            if (CmsLog.INIT.isInfoEnabled()) {
        //                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_I18N_KEEPING_DEFAULT_LOCALE_1, oldLocale));
        //            }
    }

    // initialize the static member with the new default 
    m_defaultLocale = Locale.getDefault();
}

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

/**
 * Add attributes to an OrderProduct and calculates the OrderProductPrice
 * accordingly/* w w  w .  j ava 2s .com*/
 * 
 * @param attributes
 * @param product
 * @param currency
 * @param locale
 * @return
 * @throws Exception
 */
public static OrderProduct addAttributesToProduct(List<OrderProductAttribute> attributes, OrderProduct product,
        String currency, Locale locale) throws Exception {

    Locale loc = locale;
    String lang = loc.getLanguage();

    CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService);

    BigDecimal sumPrice = null;

    // get attributes for this product
    Collection productAttributes = cservice.getProductAttributes(product.getProductId(), locale.getLanguage());
    Map mapAttributes = new HashMap();
    if (productAttributes != null) {

        Iterator i = productAttributes.iterator();
        while (i.hasNext()) {
            ProductAttribute p = (ProductAttribute) i.next();
            mapAttributes.put(p.getOptionValueId(), p);
        }
    }

    StringBuffer attributesLine = null;

    if (attributes != null) {
        attributesLine = new StringBuffer();
        int count = 0;
        Iterator i = attributes.iterator();
        while (i.hasNext()) {
            OrderProductAttribute opa = (OrderProductAttribute) i.next();
            String attrPriceText = opa.getPrice();
            BigDecimal attrPrice = null;
            if (attrPriceText != null) {
                attrPrice = CurrencyUtil.validateCurrency(attrPriceText, currency);
            } else {
                attrPrice = opa.getOptionValuePrice();
            }
            // get all information from the attribute
            ProductAttribute pa = (ProductAttribute) mapAttributes.get(opa.getProductOptionValueId());
            if (pa != null) {
                if (attrPrice == null) {
                    attrPrice = pa.getOptionValuePrice();
                }
            }
            if (attrPrice != null) {
                opa.setOptionValuePrice(attrPrice);
                opa.setPrice(CurrencyUtil.displayFormatedAmountNoCurrency(attrPrice, currency));
                if (sumPrice == null) {
                    // try {
                    // sumPrice= new
                    // BigDecimal(attrPrice.doubleValue()).setScale(BigDecimal.ROUND_UNNECESSARY);
                    sumPrice = attrPrice;
                    // } catch (Exception e) {
                    // }

                } else {
                    BigDecimal currentPrice = sumPrice;
                    sumPrice = currentPrice.add(attrPrice);
                }
            }
            opa.setOrderProductId(product.getProductId());
            opa.setProductAttributeIsFree(pa.isProductAttributeIsFree());

            opa.setProductOption("");
            if (StringUtils.isBlank(opa.getProductOptionValue())) {
                opa.setProductOptionValue("");
            }

            ProductOption po = pa.getProductOption();
            Set poDescriptions = po.getDescriptions();
            if (poDescriptions != null) {
                Iterator pi = poDescriptions.iterator();
                while (pi.hasNext()) {
                    ProductOptionDescription pod = (ProductOptionDescription) pi.next();
                    if (pod.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) {
                        opa.setProductOption(pod.getProductOptionName());
                        break;
                    }
                }
            }

            if (StringUtils.isBlank(opa.getProductOptionValue())) {
                ProductOptionValue pov = pa.getProductOptionValue();
                if (pov != null) {
                    Set povDescriptions = pov.getDescriptions();
                    if (povDescriptions != null) {
                        Iterator povi = povDescriptions.iterator();
                        while (povi.hasNext()) {
                            ProductOptionValueDescription povd = (ProductOptionValueDescription) povi.next();
                            if (povd.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) {
                                opa.setProductOptionValue(povd.getProductOptionValueName());
                                break;
                            }
                        }
                    }
                }
            }
            opa.setProductAttributeWeight(pa.getProductAttributeWeight());
            if (count == 0) {
                attributesLine.append("[ ");
            }
            attributesLine.append(opa.getProductOption()).append(" -> ").append(opa.getProductOptionValue());
            if (count + 1 == attributes.size()) {
                attributesLine.append("]");
            } else {
                attributesLine.append(", ");
            }
            count++;
        }
    }

    // add attribute price to productprice
    if (sumPrice != null) {

        // get product price
        BigDecimal productPrice = product.getProductPrice();
        productPrice = productPrice.add(sumPrice);

        // added
        product.setProductPrice(productPrice);

        BigDecimal finalPrice = productPrice.multiply(new BigDecimal(product.getProductQuantity()));

        product.setPriceText(CurrencyUtil.displayFormatedAmountNoCurrency(productPrice, currency));
        product.setPriceFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency));
    }

    if (attributesLine != null) {
        product.setAttributesLine(attributesLine.toString());
    }

    Set attributesSet = new HashSet(attributes);

    product.setOrderattributes(attributesSet);

    return product;
}

From source file:net.pms.util.Languages.java

private static String localeToLanguageCode(Locale locale) {
    /*//from w  ww. j  av a  2s. co  m
     * This might seem redundant, but a language can also contain a
     * country/region and a variant. Stating that e.g language
     * "ar" should return "ar" means that "messages_ar.properties"
     * will be used for any country/region and variant of Arabic.
     * This should be true until UMS contains multiple dialects of Arabic,
     * in which case different codes would have to be returned for the
     * different dialects.
     */

    if (locale == null) {
        return null;
    }
    String languageCode = locale.getLanguage();
    if (languageCode != null && !languageCode.isEmpty()) {
        switch (languageCode) {
        case "en":
            if (locale.getCountry().equalsIgnoreCase("GB")) {
                return "en-GB";
            } else {
                return "en-US";
            }
        case "pt":
            if (locale.getCountry().equalsIgnoreCase("BR")) {
                return "pt-BR";
            } else {
                return "pt";
            }
        case "nb":
        case "nn":
            return "no";
        case "cmn":
        case "zh":
            if (locale.getScript().equalsIgnoreCase("Hans")) {
                return "zh-Hans";
            } else if (locale.getCountry().equalsIgnoreCase("CN")
                    || locale.getCountry().equalsIgnoreCase("SG")) {
                return "zh-Hans";
            } else {
                return "zh-Hant";
            }
        default:
            return languageCode;
        }
    } else {
        return null;
    }
}

From source file:com.yolanda.nohttp.BasicRequest.java

/**
 * Create acceptLanguage.//from w  ww  . j a v  a 2 s .co m
 *
 * @return Returns the client can accept the language types. Such as:zh-CN,zh.
 */
public static String defaultAcceptLanguage() {
    if (TextUtils.isEmpty(acceptLanguage)) {
        Locale locale = Locale.getDefault();
        String language = locale.getLanguage();
        String country = locale.getCountry();
        StringBuilder acceptLanguageBuilder = new StringBuilder(language);
        if (!TextUtils.isEmpty(country))
            acceptLanguageBuilder.append('-').append(country).append(',').append(language);
        acceptLanguage = acceptLanguageBuilder.toString();
    }
    return acceptLanguage;
}

From source file:marytts.modules.ModuleRegistry.java

/**
 * Lookup a list of modules for the given combination of type, locale and voice.
 * A given lookup will return a list of modules accepting the datatype as input,
 * ordered by specificity so that the most specific modules come first.
 * For each output type produced by modules, there will be only one module
 * producing that type, namely the most specific one found.
 * Specificity is ordered as follows:/* ww  w .jav a2  s  .  c o  m*/
 * 1. most specific is the full combination of datatype, locale and voice;
 * 2. the combination of datatype, language-only locale and voice (i.e., for requested locale "en-US" will find modules with locale "en");
 * 3. the combination of datatype and locale, ignoring voice;
 * 4. the combination of datatype and language-only locale, ignoring voice;
 * 5. least specific is the datatype, ignoring locale and voice.
 * @param type the type of input data
 * @param locale the locale
 * @param voice the voice to use.
 * @return a list of mary modules accepting the datatype and suitable for
 * the given locale and voice, ordered by their specificity,
 * or an empty list if there is no suitable module.
 * @throws IllegalStateException if called when registration is not yet complete. 
 */
@SuppressWarnings("unchecked")
private static List<MaryModule> get(MaryDataType type, Locale locale, Voice voice)
        throws IllegalStateException {
    if (!registrationComplete)
        throw new IllegalStateException("Cannot inquire about modules while registration is ongoing");
    LinkedHashMap<MaryDataType, MaryModule> results = new LinkedHashMap<MaryDataType, MaryModule>();
    // First, get all results:
    List<List<MaryModule>> listOfLists = new LinkedList<List<MaryModule>>();
    listOfLists.add((List<MaryModule>) mkm.get(type, locale, voice));
    Locale langOnly = locale != null ? new Locale(locale.getLanguage()) : null;
    boolean haveCountry = langOnly == null ? false : !langOnly.equals(locale);
    if (haveCountry) {
        listOfLists.add((List<MaryModule>) mkm.get(type, langOnly, voice));
    }
    listOfLists.add((List<MaryModule>) mkm.get(type, locale, null));
    if (haveCountry) {
        listOfLists.add((List<MaryModule>) mkm.get(type, langOnly, null));
    }
    listOfLists.add((List<MaryModule>) mkm.get(type, null, null));
    // Now, for each mary output type, keep only the most specific module,
    // and return the list ordered by the specificity of modules (most specific first):
    for (List<MaryModule> list : listOfLists) {
        if (list != null) {
            for (MaryModule m : list) {
                if (!results.containsKey(m.outputType()))
                    results.put(m.outputType(), m);
            }
        }
    }
    List<MaryModule> returnList = new LinkedList<MaryModule>();
    for (MaryDataType t : results.keySet()) {
        returnList.add(results.get(t));
    }
    return returnList;
}

From source file:it.govpay.web.utils.Utils.java

public static Utils getInstance(Locale locale) {
    if (Utils.instance == null)
        init();//from  w w w . ja v  a 2  s .  c om

    if (locale == null)
        locale = Locale.ITALIAN;

    Utils utils = Utils.instance.get(locale.getLanguage());

    return utils != null ? utils : getInstance();
}

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

/**
 * OrderProductAttribute is configured from javascript This code needs to
 * invoke catalog objects require getProductOptionValueId
 * /*from  w w w.  j ava  2  s  . c  o  m*/
 * @param attributes
 * @param lineId
 * @param currency
 * @param request
 * @return
 * @throws Exception
 */
public static OrderProduct addAttributesFromRawObjects(List<OrderProductAttribute> attributes, OrderProduct scp,
        String currency, HttpServletRequest request) throws Exception {

    Locale loc = request.getLocale();
    String lang = loc.getLanguage();

    CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService);

    BigDecimal sumPrice = null;

    Locale locale = (Locale) request.getSession().getAttribute("WW_TRANS_I18N_LOCALE");
    if (locale == null)
        locale = request.getLocale();

    // get attributes for this product
    Collection productAttributes = cservice.getProductAttributes(scp.getProductId(), locale.getLanguage());
    Map mapAttributes = new HashMap();
    if (productAttributes != null) {

        Iterator i = productAttributes.iterator();
        while (i.hasNext()) {
            ProductAttribute p = (ProductAttribute) i.next();
            mapAttributes.put(p.getOptionValueId(), p);
        }

    }

    if (scp != null) {

        StringBuffer attributesLine = null;

        if (attributes != null) {
            attributesLine = new StringBuffer();
            int count = 0;
            Iterator i = attributes.iterator();
            while (i.hasNext()) {
                OrderProductAttribute opa = (OrderProductAttribute) i.next();
                String attrPriceText = opa.getPrice();
                BigDecimal attrPrice = null;
                if (attrPriceText != null) {
                    attrPrice = CurrencyUtil.validateCurrency(attrPriceText, currency);
                } else {
                    attrPrice = opa.getOptionValuePrice();
                }
                // get all information from the attribute
                ProductAttribute pa = (ProductAttribute) mapAttributes.get(opa.getProductOptionValueId());
                if (pa != null) {
                    if (attrPrice == null) {
                        attrPrice = pa.getOptionValuePrice();
                    }
                }
                if (attrPrice != null) {
                    opa.setOptionValuePrice(attrPrice);
                    opa.setPrice(CurrencyUtil.displayFormatedAmountNoCurrency(attrPrice, currency));
                    if (sumPrice == null) {
                        sumPrice = new BigDecimal(attrPrice.doubleValue()).setScale(2);
                    } else {

                        BigDecimal currentPrice = sumPrice;
                        sumPrice = currentPrice.add(attrPrice);
                    }
                }
                // opa.setOrderId(Long.parseLong(orderId));
                opa.setOrderProductId(scp.getProductId());
                opa.setProductAttributeIsFree(pa.isProductAttributeIsFree());

                opa.setProductOption("");
                if (StringUtils.isBlank(opa.getProductOptionValue())) {
                    opa.setProductOptionValue("");
                }

                ProductOption po = pa.getProductOption();
                Set poDescriptions = po.getDescriptions();
                if (poDescriptions != null) {
                    Iterator pi = poDescriptions.iterator();
                    while (pi.hasNext()) {
                        ProductOptionDescription pod = (ProductOptionDescription) pi.next();
                        if (pod.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) {
                            opa.setProductOption(pod.getProductOptionName());
                            break;
                        }
                    }
                }

                if (StringUtils.isBlank(opa.getProductOptionValue())) {
                    ProductOptionValue pov = pa.getProductOptionValue();
                    if (pov != null) {
                        Set povDescriptions = pov.getDescriptions();
                        if (povDescriptions != null) {
                            Iterator povi = povDescriptions.iterator();
                            while (povi.hasNext()) {
                                ProductOptionValueDescription povd = (ProductOptionValueDescription) povi
                                        .next();
                                if (povd.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) {
                                    opa.setProductOptionValue(povd.getProductOptionValueName());
                                    break;
                                }
                            }
                        }
                    }
                }
                opa.setProductAttributeWeight(pa.getProductAttributeWeight());
                if (count == 0) {
                    attributesLine.append("[ ");
                }
                attributesLine.append(opa.getProductOption()).append(" -> ")
                        .append(opa.getProductOptionValue());
                if (count + 1 == attributes.size()) {
                    attributesLine.append("]");
                } else {
                    attributesLine.append(", ");
                }
                count++;
            }
        }

        // add attribute price to productprice
        if (sumPrice != null) {
            // sumPrice = sumPrice.multiply(new
            // BigDecimal(scp.getProductQuantity()));

            // get product price
            BigDecimal productPrice = scp.getProductPrice();
            productPrice = productPrice.add(sumPrice);

            // added
            scp.setProductPrice(productPrice);

            // BigDecimal finalPrice = scp.getFinalPrice();
            BigDecimal finalPrice = productPrice.multiply(new BigDecimal(scp.getProductQuantity()));
            // finalPrice = finalPrice.add(sumPrice);
            // BigDecimal cost = scp.get

            scp.setPriceText(CurrencyUtil.displayFormatedAmountNoCurrency(productPrice, currency));
            scp.setPriceFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency));
        }

        if (attributesLine != null) {
            scp.setAttributesLine(attributesLine.toString());
        }

        Set attributesSet = new HashSet(attributes);

        scp.setOrderattributes(attributesSet);

    }

    return scp;
}

From source file:QueryConnector.java

private static String tr(String trName) {
    Locale locale = Locale.getDefault();
    Map<String, String> selectedLanguage = languages.get(locale.getLanguage());
    String value = null;//from   ww w.  j a  v  a2 s .  c o m
    if (selectedLanguage == null)
        value = languages.get(Locale.ENGLISH.getLanguage()).get(trName);
    else
        value = selectedLanguage.get(trName);
    if (value == null)
        value = "{MISSING TRANSLATION FOR '" + trName + "' KEY}";
    return value;
}

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

/**
 * OrderProductAttribute is configured from javascript This code needs to
 * invoke catalog objects because it requires getProductOptionValueId, will
 * not change any price Add attributes to product, add attribute offset
 * price to original product price//from w  w  w  . ja  va 2 s  .  co m
 * 
 * @param attributes
 * @param lineId
 * @param currency
 * @param request
 * @return
 * @throws Exception
 */
public static OrderProduct addAttributesFromRawObjects(List<OrderProductAttribute> attributes, long productId,
        String lineId, String currency, HttpServletRequest request) throws Exception {

    Locale loc = request.getLocale();
    String lang = loc.getLanguage();

    HttpSession session = request.getSession();

    Map cartLines = SessionUtil.getOrderProducts(request);

    if (cartLines == null) {
        throw new Exception("No OrderProduct exixt yet, cannot assign attributes");
    }

    OrderProduct scp = (OrderProduct) cartLines.get(lineId);

    if (scp == null) {
        throw new Exception("No OrderProduct exixt for lineId " + lineId);
    }

    CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService);

    BigDecimal sumPrice = null;

    // make sure OrderProduct and productId match
    if (scp.getProductId() == productId) {

        Locale locale = (Locale) request.getSession().getAttribute("WW_TRANS_I18N_LOCALE");
        if (locale == null)
            locale = request.getLocale();

        // get attributes for this product
        Collection productAttributes = cservice.getProductAttributes(productId, locale.getLanguage());
        Map mapAttributes = new HashMap();
        if (productAttributes != null) {

            Iterator i = productAttributes.iterator();
            while (i.hasNext()) {
                ProductAttribute p = (ProductAttribute) i.next();
                mapAttributes.put(p.getOptionValueId(), p);
            }

        }

        if (scp != null) {

            StringBuffer attributesLine = null;

            if (attributes != null) {
                attributesLine = new StringBuffer();
                int count = 0;
                Iterator i = attributes.iterator();
                while (i.hasNext()) {
                    OrderProductAttribute opa = (OrderProductAttribute) i.next();
                    String attrPriceText = opa.getPrice();
                    BigDecimal attrPrice = null;
                    if (attrPriceText != null) {
                        attrPrice = CurrencyUtil.validateCurrency(attrPriceText, currency);
                    } else {
                        attrPrice = opa.getOptionValuePrice();
                    }
                    // get all information from the attribute
                    ProductAttribute pa = (ProductAttribute) mapAttributes.get(opa.getProductOptionValueId());
                    if (pa != null) {
                        if (attrPrice == null) {
                            attrPrice = pa.getOptionValuePrice();
                        }
                    }
                    if (attrPrice != null) {
                        opa.setOptionValuePrice(attrPrice);
                        opa.setPrice(CurrencyUtil.displayFormatedAmountNoCurrency(attrPrice, currency));
                        if (sumPrice == null) {
                            sumPrice = new BigDecimal(attrPrice.doubleValue()).setScale(2);
                        } else {
                            // double pr = sumPrice.doubleValue() +
                            // attrPrice.doubleValue();
                            // sumPrice = new
                            // BigDecimal(sumPrice.doubleValue() +
                            // attrPrice.doubleValue());
                            BigDecimal currentPrice = sumPrice;
                            sumPrice = currentPrice.add(attrPrice);
                        }
                    }
                    // opa.setOrderId(Long.parseLong(orderId));
                    opa.setOrderProductId(productId);
                    opa.setProductAttributeIsFree(pa.isProductAttributeIsFree());

                    opa.setProductOption("");
                    if (StringUtils.isBlank(opa.getProductOptionValue())) {
                        opa.setProductOptionValue("");
                    }

                    ProductOption po = pa.getProductOption();
                    Set poDescriptions = po.getDescriptions();
                    if (poDescriptions != null) {
                        Iterator pi = poDescriptions.iterator();
                        while (pi.hasNext()) {
                            ProductOptionDescription pod = (ProductOptionDescription) pi.next();
                            if (pod.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(lang)) {
                                opa.setProductOption(pod.getProductOptionName());
                                break;
                            }
                        }
                    }

                    if (StringUtils.isBlank(opa.getProductOptionValue())) {
                        ProductOptionValue pov = pa.getProductOptionValue();
                        if (pov != null) {
                            Set povDescriptions = pov.getDescriptions();
                            if (povDescriptions != null) {
                                Iterator povi = povDescriptions.iterator();
                                while (povi.hasNext()) {
                                    ProductOptionValueDescription povd = (ProductOptionValueDescription) povi
                                            .next();
                                    if (povd.getId().getLanguageId() == LanguageUtil
                                            .getLanguageNumberCode(lang)) {
                                        opa.setProductOptionValue(povd.getProductOptionValueName());
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    opa.setProductAttributeWeight(pa.getProductAttributeWeight());
                    if (count == 0) {
                        attributesLine.append("[ ");
                    }
                    attributesLine.append(opa.getProductOption()).append(" -> ")
                            .append(opa.getProductOptionValue());
                    if (count + 1 == attributes.size()) {
                        attributesLine.append("]");
                    } else {
                        attributesLine.append(", ");
                    }
                    count++;
                }
            }

            // add attribute price to productprice
            if (sumPrice != null) {
                // sumPrice = sumPrice.multiply(new
                // BigDecimal(scp.getProductQuantity()));

                scp.setAttributeAdditionalCost(sumPrice);// add additional
                // attribute
                // price

                // get product price
                BigDecimal productPrice = scp.getProductPrice();
                productPrice = productPrice.add(sumPrice);

                // added
                scp.setProductPrice(productPrice);

                // BigDecimal finalPrice = scp.getFinalPrice();
                BigDecimal finalPrice = productPrice.multiply(new BigDecimal(scp.getProductQuantity()));
                // finalPrice = finalPrice.add(sumPrice);
                // BigDecimal cost = scp.get

                scp.setPriceText(CurrencyUtil.displayFormatedAmountNoCurrency(productPrice, currency));
                scp.setPriceFormated(CurrencyUtil.displayFormatedAmountWithCurrency(finalPrice, currency));
            }

            if (attributesLine != null) {
                scp.setAttributesLine(attributesLine.toString());
            }

            Set attributesSet = new HashSet(attributes);

            scp.setOrderattributes(attributesSet);

        }

    }

    return scp;
}

From source file:org.itracker.web.util.LoginUtilities.java

/**
 * Get a locale from request/*from w w  w.ja v  a  2  s. co  m*/
 * <p/>
 * <p>
 * TODO the order of retrieving locale from request should be:
 * <ol>
 * <li>request-attribute Constants.LOCALE_KEY</li>
 * <li>request-param 'loc'</li>
 * <li>session attribute <code>Constants.LOCALE_KEY</code></li>
 * <li>cookie 'loc'</li>
 * <li>request.getLocale()/request.getLocales()</li>
 * <li>ITrackerResources.DEFAULT_LOCALE</li>
 * </ol>
 * </p>
 */
@SuppressWarnings("unchecked")
public static Locale getCurrentLocale(HttpServletRequest request) {
    Locale requestLocale = null;
    HttpSession session = request.getSession(true);
    try {

        requestLocale = (Locale) request.getAttribute(Constants.LOCALE_KEY);

        if (logger.isDebugEnabled()) {
            logger.debug("getCurrentLocale: request-attribute was {}", requestLocale);
        }

        if (null == requestLocale) {
            // get locale from request param
            String loc = request.getParameter("loc");
            if (null != loc && loc.trim().length() > 1) {
                requestLocale = ITrackerResources.getLocale(loc);
            }

            logger.debug("getCurrentLocale: request-parameter was {}", loc);

        }

        if (null == requestLocale) {
            // get it from the session
            requestLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
            //            if (logger.isDebugEnabled()) {
            //               logger.debug("getCurrentLocale: session-attribute was "
            //                     + requestLocale);
            //            }
        }

        if (null == requestLocale) {
            ResourceBundle bundle = ITrackerResources.getBundle(request.getLocale());
            if (logger.isDebugEnabled()) {
                logger.debug("getCurrentLocale: trying request header locale " + request.getLocale());
            }
            if (bundle.getLocale().getLanguage().equals(request.getLocale().getLanguage())) {
                requestLocale = request.getLocale();
                if (logger.isDebugEnabled()) {
                    logger.debug("getCurrentLocale: request-locale was " + requestLocale);
                }
            }
        }

        // is there no way to detect supported locales of current
        // installation?

        if (null == requestLocale) {
            Enumeration<Locale> locales = (Enumeration<Locale>) request.getLocales();
            ResourceBundle bundle;
            Locale locale;
            while (locales.hasMoreElements()) {
                locale = locales.nextElement();
                bundle = ITrackerResources.getBundle(locale);

                logger.debug("getCurrentLocale: request-locales processing {}, bundle: {}", locale, bundle);

                if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
                    requestLocale = locale;

                    logger.debug("getCurrentLocale: request-locales locale was {}", requestLocale);

                }
            }
        }

    } finally {
        if (null == requestLocale) {
            // fall back to default locale
            requestLocale = ITrackerResources.getLocale();

            logger.debug("getCurrentLocale: fallback default locale was {}", requestLocale);

        }
        session.setAttribute(Constants.LOCALE_KEY, requestLocale);
        request.setAttribute(Constants.LOCALE_KEY, requestLocale);
        request.setAttribute("currLocale", requestLocale);

        logger.debug("getCurrentLocale: request and session was setup with {}", requestLocale);

    }

    return requestLocale;
}