Examples of LocaleInfo


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

     * ����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

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

     * @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

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

     *
     * @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

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

    /** 设置locale、输入charset、输出charset。 */
    @Override
    public void prepare() {
        // 首先从session中取得localeInfo,如果不存在,则取得默认值。
        LocaleInfo localeInfo = getLocaleInfoFromSessionOrGetTheDefaultValue();

        // 匹配request uri
        SetLocaleOverrider overrider = getMatchedOverrider();

        // 将input charset设置到request中,以便进一步解析request parameters。
        setInputCharsetToRequest(localeInfo.getCharset().name(), overrider);

        // 现在已经可以安全地调用getParameter()方法,以解析参数了,因为input charset已经被设置。
        // 从parameter中取locale信息,如果存在,则设置到cookie中。
        if (PARAMETER_SET_TO_DEFAULT_VALUE.equalsIgnoreCase(getRequest().getParameter(paramKey))) {
            localeInfo = resetLocaleInfoInSession();
        } else {
            String outputCharset = getOutputCharsetFromQueryString();

            if (outputCharset == null) {
                outputCharset = getOutputCharsetOverridden(overrider);
            }

            // 如果parameter中指明了locale,则取得并保存之
            LocaleInfo paramLocale = getLocaleInfoFromParameter();

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

                // 用parameter中的locale信息覆盖session中的localeInfo信息。
                localeInfo = paramLocale;
            }

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

        // 设置用于输出的locale信息。
        getResponse().setLocale(localeInfo.getLocale());
View Full Code Here

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

     * @return 当前session中的locale设置或默认值
     */
    private LocaleInfo getLocaleInfoFromSessionOrGetTheDefaultValue() {
        HttpSession session = getRequest().getSession(false); // 如果session不存在,也不用创建。
        String localeName = session == null ? null : (String) getRequest().getSession().getAttribute(sessionKey);
        LocaleInfo localeInfo;

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

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

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

        return localeInfo;
    }
View Full Code Here

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

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

        LocaleInfo localeInfo = new LocaleInfo(defaultLocale, defaultCharset);

        log.debug("Reset OUTPUT locale:charset to " + localeInfo);

        return localeInfo;
    }
View Full Code Here

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

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

    /** 设置locale、输入charset、输出charset。 */
    @Override
    public void prepare() {
        // 首先从session中取得localeInfo,如果不存在,则取得默认值。
        LocaleInfo localeInfo = getLocaleInfoFromSessionOrGetTheDefaultValue();

        // 匹配request uri
        SetLocaleOverrider overrider = getMatchedOverrider();

        // 将input charset设置到request中,以便进一步解析request parameters。
        setInputCharsetToRequest(localeInfo.getCharset().name(), overrider);

        // 现在已经可以安全地调用getParameter()方法,以解析参数了,因为input charset已经被设置。
        // 从parameter中取locale信息,如果存在,则设置到cookie中。
        if (PARAMETER_SET_TO_DEFAULT_VALUE.equalsIgnoreCase(getRequest().getParameter(paramKey))) {
            localeInfo = resetLocaleInfoInSession();
        } else {
            String outputCharset = getOutputCharsetFromQueryString();

            if (outputCharset == null) {
                outputCharset = getOutputCharsetOverridden(overrider);
            }

            // 如果parameter中指明了locale,则取得并保存之
            LocaleInfo paramLocale = getLocaleInfoFromParameter();

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

                // 用parameter中的locale信息覆盖session中的localeInfo信息。
                localeInfo = paramLocale;
            }

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

        // 设置用于输出的locale信息。
        getResponse().setLocale(localeInfo.getLocale());
View Full Code Here

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

     * @return 当前session中的locale设置或默认值
     */
    private LocaleInfo getLocaleInfoFromSessionOrGetTheDefaultValue() {
        HttpSession session = getRequest().getSession(false); // 如果session不存在,也不用创建。
        String localeName = session == null ? null : (String) getRequest().getSession().getAttribute(sessionKey);
        LocaleInfo localeInfo;

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

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

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

        return localeInfo;
    }
View Full Code Here

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

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

        LocaleInfo localeInfo = new LocaleInfo(defaultLocale, defaultCharset);

        log.debug("Reset OUTPUT locale:charset to " + localeInfo);

        return localeInfo;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.