當前位置: 首頁>>代碼示例>>Java>>正文


Java StringUtils.parseLocaleString方法代碼示例

本文整理匯總了Java中org.springframework.util.StringUtils.parseLocaleString方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.parseLocaleString方法的具體用法?Java StringUtils.parseLocaleString怎麽用?Java StringUtils.parseLocaleString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.util.StringUtils的用法示例。


在下文中一共展示了StringUtils.parseLocaleString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseLocaleCookieIfNecessary

import org.springframework.util.StringUtils; //導入方法依賴的package包/類
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, "%22", "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = (!"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null);
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            (locale != null ? locale: determineDefaultLocale(request)));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            (timeZone != null ? timeZone : determineDefaultTimeZone(request)));
    }
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:36,代碼來源:AngularCookieLocaleResolver.java

示例2: parseLocaleCookieIfNecessary

import org.springframework.util.StringUtils; //導入方法依賴的package包/類
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, "%22", "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = !"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null;
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            locale != null ? locale: determineDefaultLocale(request));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            timeZone != null ? timeZone : determineDefaultTimeZone(request));
    }
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:36,代碼來源:AngularCookieLocaleResolver.java

示例3: setAsText

import org.springframework.util.StringUtils; //導入方法依賴的package包/類
@Override
public void setAsText(String text) throws IllegalArgumentException {
	Assert.hasText(text, "'text' must not be empty");
	ResourceBundle bundle;
	String rawBaseName = text.trim();
	int indexOfBaseNameSeparator = rawBaseName.indexOf(BASE_NAME_SEPARATOR);
	if (indexOfBaseNameSeparator == -1) {
		bundle = ResourceBundle.getBundle(rawBaseName);
	} else {
		// it potentially has locale information
		String baseName = rawBaseName.substring(0, indexOfBaseNameSeparator);
		if (!StringUtils.hasText(baseName)) {
			throw new IllegalArgumentException("Bad ResourceBundle name : received '" + text + "' as argument to 'setAsText(String value)'.");
		}
		String localeString = rawBaseName.substring(indexOfBaseNameSeparator + 1);
		Locale locale = StringUtils.parseLocaleString(localeString);
		bundle = (StringUtils.hasText(localeString))
				? ResourceBundle.getBundle(baseName, locale)
				: ResourceBundle.getBundle(baseName);
	}
	setValue(bundle);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:ResourceBundleEditor.java

示例4: getLocaleForUser

import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
 * Gets the specified user's preferred locale, if available.
 * 
 * @param user the username of the user whose locale is sought.
 * @return the preferred locale for that user, if available, else <tt>null</tt>. The result would be <tt>null</tt>
 *         e.g. if the user does not exist in the system.
 */
private Locale getLocaleForUser(final String user)
{
    Locale locale = null;
    String localeString = null;
    
    // get primary tenant for the specified user.
    //
    // This can have one of (at least) 3 values currently:
    // 1. In single-tenant (community/enterprise) this will be the empty string.
    // 2. In the cloud, for a username such as this: [email protected]:
    //    2A. If the acme.com tenant exists in the system, the primary domain is "acme.com"
    //    2B. Id the acme.xom tenant does not exist in the system, the primary domain is null.
    String domain = tenantService.getPrimaryDomain(user);
    
    if (domain != null) 
    { 
        // If the domain is not null, then the user exists in the system and we may get a preferred locale.
        localeString = TenantUtil.runAsSystemTenant(new TenantRunAsWork<String>()
        {
            public String doWork() throws Exception
            {
                return (String) preferenceService.getPreference(user, "locale");
            }
        }, domain);
    }
    else
    {
        // If the domain is null, then the beahviour here varies depending on whether it's a single tenant or multi-tenant cloud.
        if (personExists(user))
        {
            localeString = AuthenticationUtil.runAsSystem(new RunAsWork<String>()
            {
                public String doWork() throws Exception 
                {
                    return (String) preferenceService.getPreference(user, "locale");
                };
            }); 
        }
        // else leave it as null - there's no tenant, no user for that username, so we can't get a preferred locale.
    }
    
    if (localeString != null)
    {
        locale = StringUtils.parseLocaleString(localeString);
    }

    return locale;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:56,代碼來源:MailActionExecuter.java


注:本文中的org.springframework.util.StringUtils.parseLocaleString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。