本文整理汇总了Java中org.springframework.extensions.surf.util.I18NUtil.getLocale方法的典型用法代码示例。如果您正苦于以下问题:Java I18NUtil.getLocale方法的具体用法?Java I18NUtil.getLocale怎么用?Java I18NUtil.getLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.extensions.surf.util.I18NUtil
的用法示例。
在下文中一共展示了I18NUtil.getLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ContentData
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* Create a compound set of data representing a single instance of <i>content</i>.
* <p>
* In order to ensure data integrity, the {@link #getMimetype() mimetype}
* must be set if the {@link #getContentUrl() content URL} is set.
*
* @param contentUrl the content URL. If this value is non-null, then the
* <b>mimetype</b> must be supplied.
* @param mimetype the content mimetype. This is mandatory if the <b>contentUrl</b> is specified.
* @param size the content size.
* @param encoding the content encoding. This is mandatory if the <b>contentUrl</b> is specified.
* @param locale the locale of the content (may be <tt>null</tt>). If <tt>null</tt>, the
* {@link I18NUtil#getLocale() default locale} will be used.
*/
public ContentData(String contentUrl, String mimetype, long size, String encoding, Locale locale)
{
if (contentUrl != null && (mimetype == null || mimetype.length() == 0))
{
mimetype = MimetypeMap.MIMETYPE_BINARY;
}
checkContentUrl(contentUrl, mimetype, encoding);
this.contentUrl = contentUrl;
this.mimetype = mimetype;
this.size = size;
this.encoding = encoding;
if (locale == null)
{
locale = I18NUtil.getLocale();
}
this.locale = locale;
}
示例2: extractLocale
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
private Locale extractLocale(BasicSearchParameters searchParameters)
{
Locale locale = I18NUtil.getLocale();
if (searchParameters.getLocales().size() > 0)
{
locale = searchParameters.getLocales().get(0);
}
return locale;
}
示例3: getLocalizedSibling
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@Override
public NodeRef getLocalizedSibling(NodeRef nodeRef)
{
Locale userLocale = I18NUtil.getLocale();
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
// Work out the base name we are working with
Pair<String, String> split = getExtension(name, false);
String base = split.getFirst();
String ext = split.getSecond();
NodeRef resultNodeRef = nodeRef;
// Search for siblings with the same name
Control resourceHelper = Control.getControl(Control.FORMAT_DEFAULT);
List<Locale> candidateLocales = resourceHelper.getCandidateLocales(base, userLocale);
for (Locale candidateLocale : candidateLocales)
{
String filename = resourceHelper.toBundleName(base, candidateLocale) + "." + ext;
// Attempt to find the file
NodeRef foundNodeRef = searchSimple(parentNodeRef, filename);
if (foundNodeRef != null) // TODO: Check for read permissions
{
resultNodeRef = foundNodeRef;
break;
}
}
// Done
return resultNodeRef;
}
示例4: AbstractContentAccessor
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* @param contentUrl the content URL
*/
protected AbstractContentAccessor(String contentUrl)
{
ParameterCheck.mandatoryString("contentUrl", contentUrl);
if (contentUrl == null || contentUrl.length() == 0)
{
throw new IllegalArgumentException("contentUrl is invalid:" + contentUrl);
}
this.contentUrl = contentUrl;
// the default encoding is Java's default encoding
encoding = "UTF-8";
// the default locale
locale = I18NUtil.getLocale();
}
示例5: getClosestLocale
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public Locale getClosestLocale(Collection<?> collection)
{
if (collection.size() == 0)
{
return null;
}
// Use the available keys as options
HashSet<Locale> locales = new HashSet<Locale>();
for(Object o : collection)
{
MLText mlText = (MLText)o;
locales.addAll(mlText.keySet());
}
// Try the content locale
Locale locale = I18NUtil.getContentLocale();
Locale match = I18NUtil.getNearestLocale(locale, locales);
if (match == null)
{
// Try just the content locale language
locale = I18NUtil.getContentLocaleLang();
match = I18NUtil.getNearestLocale(locale, locales);
if (match == null)
{
// No close matches for the locale - go for the default locale
locale = I18NUtil.getLocale();
match = I18NUtil.getNearestLocale(locale, locales);
if (match == null)
{
// just get any locale
match = I18NUtil.getNearestLocale(null, locales);
}
}
}
return match;
}
示例6: setParameterDefinitions
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* Set the parameter definitions for the rule item
*
* @param parameterDefinitions the parameter definitions
*/
public void setParameterDefinitions(List<ParameterDefinition> parameterDefinitions)
{
Locale currentLocale = I18NUtil.getLocale();
new HashMap<Locale, Map<String, ParameterDefinition>>();
if (hasDuplicateNames(parameterDefinitions) == true)
{
throw new RuleServiceException(ERR_NAME_DUPLICATION);
}
this.parameterDefinitions.put(currentLocale, parameterDefinitions);
createParamDefinitionsByName();
}
示例7: getLocalePair
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public Pair<Long, Locale> getLocalePair(Long id)
{
if (id == null)
{
throw new IllegalArgumentException("Cannot look up entity by null ID.");
}
Pair<Long, String> entityPair = localeEntityCache.getByKey(id);
if (entityPair == null)
{
throw new DataIntegrityViolationException("No locale exists for ID " + id);
}
String localeStr = entityPair.getSecond();
// Convert the locale string to a locale
Locale locale = null;
if (LocaleEntity.DEFAULT_LOCALE_SUBSTITUTE.equals(localeStr))
{
locale = I18NUtil.getLocale();
}
else
{
locale = DefaultTypeConverter.INSTANCE.convert(Locale.class, entityPair.getSecond());
}
return new Pair<Long, Locale>(id, locale);
}
示例8: getOrCreateLocalePairImpl
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* Find or create the locale pair
*
* @param locale the locale to get or <tt>null</tt> to indicate the
* {@link LocaleEntity#DEFAULT_LOCALE_SUBSTITUTE default locale}.
* @return Returns the locale pair (ID, Locale), never <tt>null
*/
private Pair<Long, Locale> getOrCreateLocalePairImpl(Locale locale)
{
// Null means look for the default
final String localeStr;
if (locale == null)
{
localeStr = LocaleEntity.DEFAULT_LOCALE_SUBSTITUTE;
locale = I18NUtil.getLocale();
}
else
{
localeStr = DefaultTypeConverter.INSTANCE.convert(String.class, locale);
}
if (localeStr == null)
{
throw new IllegalArgumentException("Cannot look up entity by null locale.");
}
Pair<Long, String> entityPair = localeEntityCache.getOrCreateByValue(localeStr);
if (entityPair == null)
{
throw new RuntimeException("Locale should have been created.");
}
return new Pair<Long, Locale>(entityPair.getFirst(), locale);
}
示例9: getDefaultValue
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* Retrieves a default value from the set of available locales.<br/>
*
* @see I18NUtil#getLocale()
* @see #getClosestValue(Locale)
*/
public String getDefaultValue()
{
// Shortcut so that we don't have to go and get the current locale
if (this.size() == 0)
{
return null;
}
// There is some hope of getting a match
Locale locale = I18NUtil.getLocale();
return getClosestValue(locale);
}
示例10: getUserLocaleOrDefault
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* Gets the user's locale.
*
* @param userId the user id
* @return the default locale or the user's preferred locale, if available
*/
public Locale getUserLocaleOrDefault(String userId)
{
if (userId != null && personService.personExists(userId))
{
String localeString = AuthenticationUtil.runAsSystem(() -> (String) preferenceService.getPreference(userId, "locale"));
if (localeString != null)
{
return I18NUtil.parseLocale(localeString);
}
}
return I18NUtil.getLocale();
}
示例11: getClosestValue
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* The given locale is used to search for a matching value according to:
* <ul>
* <li>An exact locale match</li>
* <li>A match of locale ISO language codes</li>
* <li>The value for the locale provided in the {@link MLText#MLText(Locale, String) constructor}</li>
* <li>An arbitrary value</li>
* <li><tt>null</tt></li>
* </ul>
*
* @param locale the locale to use as the starting point of the value search
* @return Returns a default <tt>String</tt> value or null if one isn't available.
* <tt>null</tt> will only be returned if there are no values associated with
* this instance. With or without a match, the return value may be <tt>null</tt>,
* depending on the values associated with the locales.
*/
public String getClosestValue(Locale locale)
{
if (this.size() == 0)
{
return null;
}
// Use the available keys as options
Set<Locale> options = keySet();
// Get a match
Locale match = I18NUtil.getNearestLocale(locale, options);
if (match == null)
{
// No close matches for the locale - go for the default locale
locale = I18NUtil.getLocale();
match = I18NUtil.getNearestLocale(locale, options);
if (match == null)
{
// just get any locale
match = I18NUtil.getNearestLocale(null, options);
}
}
// Did we get a match
if (match == null)
{
// We could find no locale matches
return null;
}
else
{
return get(match);
}
}
示例12: onSetUp
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@Override
protected void onSetUp() throws Exception
{
super.onSetUp();
contentLocaleToRestore = I18NUtil.getContentLocale();
localeToRestore = I18NUtil.getLocale();
}
示例13: testStringIntoMLTextProperty
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* Ensure that plain strings going into MLText properties is handled
*/
@SuppressWarnings("unchecked")
public void testStringIntoMLTextProperty() throws Exception
{
String text = "Hello";
nodeService.setProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE, text);
Serializable mlTextCheck = nodeService.getProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE);
assertTrue("Plain string insertion should be returned as MLText", mlTextCheck instanceof MLText);
Locale defaultLocale = I18NUtil.getLocale();
MLText mlTextCheck2 = (MLText) mlTextCheck;
String mlTextDefaultCheck = mlTextCheck2.getDefaultValue();
assertEquals("Default MLText value was not set correctly", text, mlTextDefaultCheck);
// Reset the property
nodeService.setProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE, null);
Serializable nullValueCheck = nodeService.getProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE);
// Now, just pass a String in
nodeService.setProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE, text);
// Now update the property with some MLText
MLText mlText = new MLText();
mlText.addValue(Locale.ENGLISH, "Very good!");
mlText.addValue(Locale.FRENCH, "Très bon!");
mlText.addValue(Locale.GERMAN, "Sehr gut!");
nodeService.setProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE, mlText);
// Get it back and check
mlTextCheck = nodeService.getProperty(rootNodeRef, PROP_QNAME_ML_TEXT_VALUE);
assertEquals("Setting of MLText over String failed.", mlText, mlTextCheck);
}
示例14: testParameterDefinitionLocaleFallback
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* REPO-2253: Community: ALF-21854 Action parameter lookup for "de_DE" falls back to "root" locale instead of "de"
*/
public void testParameterDefinitionLocaleFallback()
{
Locale originalLocale = I18NUtil.getLocale();
try
{
ActionDefinitionImpl actionDef = new ActionDefinitionImpl(NAME);
Map<Locale, List<ParameterDefinition>> localizedParams = new HashMap<>();
localizedParams.put(Locale.ROOT, exampleFieldList("English Label"));
localizedParams.put(Locale.ENGLISH, exampleFieldList("English Label"));
localizedParams.put(Locale.UK, exampleFieldList("UK-specific Label"));
localizedParams.put(Locale.GERMAN, exampleFieldList("German Label"));
actionDef.setLocalizedParameterDefinitions(localizedParams);
I18NUtil.setLocale(null);
assertEquals("English Label", actionDef.getParameterDefintion("example-field").getDisplayLabel());
I18NUtil.setLocale(Locale.ENGLISH);
assertEquals("English Label", actionDef.getParameterDefintion("example-field").getDisplayLabel());
// en-GB does not need to fallback to en
I18NUtil.setLocale(Locale.UK);
assertEquals("UK-specific Label", actionDef.getParameterDefintion("example-field").getDisplayLabel());
I18NUtil.setLocale(Locale.GERMAN);
assertEquals("German Label", actionDef.getParameterDefintion("example-field").getDisplayLabel());
I18NUtil.setLocale(Locale.GERMANY);
// de-DE falls back to de
assertEquals("German Label", actionDef.getParameterDefintion("example-field").getDisplayLabel());
}
finally
{
I18NUtil.setLocale(originalLocale);
}
}
示例15: testDefaultLocale
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void testDefaultLocale() throws Exception
{
RetryingTransactionCallback<Pair<Long, Locale>> callback = new RetryingTransactionCallback<Pair<Long, Locale>>()
{
public Pair<Long, Locale> execute() throws Throwable
{
// What is the thread's default locale?
Locale defaultLocale = I18NUtil.getLocale();
// Now make it
Pair<Long, Locale> localePair = localeDAO.getOrCreateDefaultLocalePair();
assertNotNull("Default locale should now exist", localePair);
assertEquals(
"The default locale returned must match the current thread's default locale",
defaultLocale, localePair.getSecond());
// Done
return localePair;
}
};
// Check that the default locale is handled properly
txnHelper.doInTransaction(callback);
// Now change the default locale
I18NUtil.setLocale(Locale.CANADA_FRENCH);
// Repeat
txnHelper.doInTransaction(callback);
}