Package com.alibaba.citrus.util.i18n

Examples of com.alibaba.citrus.util.i18n.LocaleInfo


     *
     * @return 当前request parameters中的locale设置
     */
    private LocaleInfo getLocaleInfoFromParameter() {
        String localeName = getRequest().getParameter(paramKey);
        LocaleInfo localeInfo = null;

        if (!isEmpty(localeName)) {
            localeInfo = LocaleInfo.parse(localeName);

            if (!LocaleUtil.isLocaleSupported(localeInfo.getLocale())
                || !LocaleUtil.isCharsetSupported(localeInfo.getCharset().name())) {
                log.warn("Invalid locale " + localeInfo + " from request parameters");

                localeInfo = new LocaleInfo(defaultLocale, defaultCharset);
            }
        }

        return localeInfo;
    }
View Full Code Here


     * ����locale��
     */
    @Override
    public void prepare() {
        // ���ȴ�session��ȡ��input charset�������õ�request�У��Ա��һ������request parameters��
        LocaleInfo locale = getLocaleFromSession();

        try {
            // ��ͼ��queryString��ȡ��inputCharset
            String queryString = getRequest().getQueryString();
            String inputCharset = locale.getCharset().name();

            if (queryString != null) {
                Matcher matcher = inputCharsetPattern.matcher(queryString);

                if (matcher.find()) {
                    String charset = null;

                    if (matcher.groupCount() >= 2) {
                        charset = matcher.group(2);
                    }

                    if (LocaleUtil.isCharsetSupported(charset)) {
                        inputCharset = charset;
                    } else {
                        log.warn("Specified input charset is not supported: " + charset);
                    }
                }
            }

            getRequest().setCharacterEncoding(inputCharset);

            log.debug("Set INPUT charset to " + inputCharset);
        } catch (UnsupportedEncodingException e) {
            try {
                getRequest().setCharacterEncoding(CHARSET_DEFAULT);

                log.warn("Unknown charset " + locale.getCharset() + ".  Set INPUT charset to " + CHARSET_DEFAULT);
            } catch (UnsupportedEncodingException ee) {
                log.error("Failed to set INPUT charset to " + locale.getCharset());
            }
        }

        // ��parameter��ȡlocale��Ϣ��������ڣ������õ�cookie�С�
        if (PARAMETER_SET_TO_DEFAULT_VALUE.equalsIgnoreCase(getRequest().getParameter(paramKey))) {
            HttpSession session = getRequest().getSession(false); // ���session�����ڣ�Ҳ���ô���

            if (session != null) {
                session.removeAttribute(sessionKey);
            }

            locale = new LocaleInfo(defaultLocale, defaultCharset);

            log.debug("Reset OUTPUT locale:charset to " + locale);
        } else {
            // ��ͼ��queryString��ȡ��outputCharset
            String queryString = getRequest().getQueryString();
            String outputCharset = null;

            if (queryString != null) {
                Matcher matcher = outputCharsetPattern.matcher(queryString);

                if (matcher.find()) {
                    String charset = null;

                    if (matcher.groupCount() >= 2) {
                        charset = matcher.group(2);
                    }

                    if (LocaleUtil.isCharsetSupported(charset)) {
                        outputCharset = charset;
                    } else {
                        log.warn("Specified output charset is not supported: " + charset);
                    }
                }
            }

            // ���parameter��ָ����locale����ȡ�ò�����֮
            LocaleInfo paramLocale = getLocaleFromParameter();

            if (paramLocale != null) {
                getRequest().getSession().setAttribute(sessionKey, paramLocale.toString());

                // ��parameter�е�locale��Ϣ����cookie����Ϣ��
                locale = paramLocale;
            }

            if (outputCharset != null) {
                locale = new LocaleInfo(locale.getLocale(), outputCharset);
            }
        }

        // �������������locale��Ϣ��
        getResponse().setLocale(locale.getLocale());
View Full Code Here

     * @return ��ǰsession�е�locale����
     */
    private LocaleInfo getLocaleFromSession() {
        HttpSession session = getRequest().getSession(false); // ���session�����ڣ�Ҳ���ô�����
        String localeName = session == null ? null : (String) getRequest().getSession().getAttribute(sessionKey);
        LocaleInfo locale = null;

        if (isEmpty(localeName)) {
            locale = new LocaleInfo(defaultLocale, defaultCharset);
        } else {
            locale = LocaleInfo.parse(localeName);

            if (!LocaleUtil.isLocaleSupported(locale.getLocale())
                    || !LocaleUtil.isCharsetSupported(locale.getCharset().name())) {
                log.warn("Invalid locale " + locale + " from session");

                locale = new LocaleInfo(defaultLocale, defaultCharset);
            }
        }

        return locale;
    }
View Full Code Here

     *
     * @return ��ǰrequest parameters�е�locale����
     */
    private LocaleInfo getLocaleFromParameter() {
        String localeName = getRequest().getParameter(paramKey);
        LocaleInfo locale = null;

        if (!isEmpty(localeName)) {
            locale = LocaleInfo.parse(localeName);

            if (!LocaleUtil.isLocaleSupported(locale.getLocale())
                    || !LocaleUtil.isCharsetSupported(locale.getCharset().name())) {
                log.warn("Invalid locale " + locale + " from request parameters");

                locale = new LocaleInfo(defaultLocale, defaultCharset);
            }
        }

        return locale;
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.util.i18n.LocaleInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.