Examples of LocaleInfo


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��
     */
    @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.caucho.quercus.env.LocaleInfo

  public static Value setlocale(Env env,
                                int category,
                                Value localeArg,
                                Value []fallback)
  {
    LocaleInfo localeInfo = env.getLocaleInfo();

    if (localeArg instanceof ArrayValue) {
      for (Value value : ((ArrayValue) localeArg).values()) {
        QuercusLocale locale = setLocale(localeInfo,
                                         category,
View Full Code Here

Examples of com.caucho.quercus.env.LocaleInfo

  public static Value setlocale(Env env,
                                int category,
                                Value localeArg,
                                Value []fallback)
  {
    LocaleInfo localeInfo = env.getLocaleInfo();

    if (localeArg instanceof ArrayValue) {
      for (Value value : ((ArrayValue) localeArg).values()) {
        QuercusLocale locale = setLocale(localeInfo,
                                         category,
View Full Code Here

Examples of com.caucho.quercus.env.LocaleInfo

  public static Value setlocale(Env env,
                                int category,
                                Value localeArg,
                                Value []fallback)
  {
    LocaleInfo localeInfo = env.getLocaleInfo();

    if (localeArg instanceof ArrayValue) {
      for (Value value : ((ArrayValue) localeArg).values()) {
        QuercusLocale locale = setLocale(localeInfo,
                                         category,
View Full Code Here

Examples of com.google.gwt.i18n.client.LocaleInfo

     *            Format string e.g. "d M yyyy"
     * @return The date string where the month names have been replaced by the
     *         browser locale version
     */
    private String parseMonthName(String enteredDate, String formatString) {
        LocaleInfo browserLocale = LocaleInfo.getCurrentLocale();
        if (browserLocale.getLocaleName().equals(getLocale())) {
            // No conversion needs to be done when locales match
            return enteredDate;
        }
        String[] browserMonthNames = browserLocale.getDateTimeConstants()
                .months();
        String[] browserShortMonthNames = browserLocale.getDateTimeConstants()
                .shortMonths();

        if (formatString.contains("MMMM")) {
            // Full month name
            for (int i = 0; i < 12; i++) {
View Full Code Here

Examples of com.google.gwt.i18n.client.LocaleInfo

     *            Format string e.g. "d M yyyy"
     * @return The date string where the month names have been replaced by the
     *         browser locale version
     */
    private String parseMonthName(String enteredDate, String formatString) {
        LocaleInfo browserLocale = LocaleInfo.getCurrentLocale();
        if (browserLocale.getLocaleName().equals(getLocale())) {
            // No conversion needs to be done when locales match
            return enteredDate;
        }
        String[] browserMonthNames = browserLocale.getDateTimeConstants()
                .months();
        String[] browserShortMonthNames = browserLocale.getDateTimeConstants()
                .shortMonths();

        if (formatString.contains("MMMM")) {
            // Full month name
            for (int i = 0; i < 12; i++) {
View Full Code Here

Examples of com.google.gwt.i18n.client.LocaleInfo

     *            Format string e.g. "d M yyyy"
     * @return The date string where the month names have been replaced by the
     *         browser locale version
     */
    private String parseMonthName(String enteredDate, String formatString) {
        LocaleInfo browserLocale = LocaleInfo.getCurrentLocale();
        if (browserLocale.getLocaleName().equals(getLocale())) {
            // No conversion needs to be done when locales match
            return enteredDate;
        }
        String[] browserMonthNames = browserLocale.getDateTimeConstants()
                .months();
        String[] browserShortMonthNames = browserLocale.getDateTimeConstants()
                .shortMonths();

        if (formatString.contains("MMMM")) {
            // Full month name
            for (int i = 0; i < 12; i++) {
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.