本文整理汇总了Java中org.springframework.extensions.surf.util.I18NUtil.setLocale方法的典型用法代码示例。如果您正苦于以下问题:Java I18NUtil.setLocale方法的具体用法?Java I18NUtil.setLocale怎么用?Java I18NUtil.setLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.extensions.surf.util.I18NUtil
的用法示例。
在下文中一共展示了I18NUtil.setLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGenerateFormWithSpecificLocale
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 testGenerateFormWithSpecificLocale()
{
final Locale originalLocale = I18NUtil.getLocale();
try
{
I18NUtil.setLocale(Locale.GERMANY); // de-DE
transactionHelper.doInTransaction(() -> {
Form form = formService.getForm(new Item(ActionFormProcessor.ITEM_KIND, "transform"));
// Field definitions keyed by name.
Map<String, FieldDefinition> fieldDefMap = form.getFieldDefinitions().stream().
collect(Collectors.toMap(FieldDefinition::getName, Function.identity()));
assertEquals("Zielordner", fieldDefMap.get(TransformActionExecuter.PARAM_DESTINATION_FOLDER).getLabel());
assertEquals("MIME-Type", fieldDefMap.get(TransformActionExecuter.PARAM_MIME_TYPE).getLabel());
return null;
});
}
finally
{
I18NUtil.setLocale(originalLocale);
}
}
示例2: onTearDown
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@Override
protected void onTearDown() throws Exception
{
super.onTearDown();
I18NUtil.setContentLocale(contentLocaleToRestore);
I18NUtil.setLocale(localeToRestore);
}
示例3: dumpNodeStore
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
private void dumpNodeStore(Locale locale)
{
System.out.println(locale.getDisplayLanguage() + " LOCALE: ");
I18NUtil.setLocale(locale);
System.out.println(NodeStoreInspector.dumpNodeStore((NodeService) applicationContext.getBean("NodeService"), storeRef));
}
示例4: tearDown
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* Clean up the test thread
*/
@Override
protected void tearDown()
{
AuthenticationUtil.clearCurrentSecurityContext();
I18NUtil.setLocale(null);
}
示例5: 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);
}
}
示例6: testCheckLocalizedParamDefintionWithConstraint
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* MNT-15802
*/
public void testCheckLocalizedParamDefintionWithConstraint()
{
// test for other than default locale
I18NUtil.setLocale(Locale.GERMAN);
ActionDefinition actionDef = executer.getActionDefinition();
List<ParameterDefinition> paramDef = actionDef.getParameterDefinitions();
assertNotNull(paramDef);
String constraintName = paramDef.get(0).getParameterConstraintName();
assertNotNull(constraintName);
assertEquals(AddFeaturesActionExecuter.PARAM_CONSTRAINT, constraintName);
// test for other than default locale
I18NUtil.setLocale(Locale.ITALY);
actionDef = executer.getActionDefinition();
paramDef = actionDef.getParameterDefinitions();
assertNotNull(paramDef);
constraintName = paramDef.get(0).getParameterConstraintName();
assertNotNull(constraintName);
assertEquals(AddFeaturesActionExecuter.PARAM_CONSTRAINT, constraintName);
I18NUtil.setLocale(Locale.getDefault());
}
示例7: 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);
}
示例8: setUp
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception
{
// Re-set the current locale to be the default
Locale.setDefault(Locale.ENGLISH);
I18NUtil.setLocale(Locale.getDefault());
}
示例9: testI18NBehaviour
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void testI18NBehaviour()
{
// Ensure that the bundle is present on the classpath
String baseResourceAsProperty = BASE_RESOURCE_NAME.replace('.', '/') + ".properties";
URL baseResourceURL = AlfrescoRuntimeExceptionTest.class.getClassLoader().getResource(baseResourceAsProperty);
assertNotNull(baseResourceURL);
baseResourceAsProperty = BASE_RESOURCE_NAME.replace('.', '/') + "_fr_FR" + ".properties";
baseResourceURL = AlfrescoRuntimeExceptionTest.class.getClassLoader().getResource(baseResourceAsProperty);
assertNotNull(baseResourceURL);
// Ensure we can load it as a resource bundle
ResourceBundle properties = ResourceBundle.getBundle(BASE_RESOURCE_NAME);
assertNotNull(properties);
properties = ResourceBundle.getBundle(BASE_RESOURCE_NAME, new Locale("fr", "FR"));
assertNotNull(properties);
// From here on in, we use Spring
// Register the bundle
I18NUtil.registerResourceBundle(BASE_RESOURCE_NAME);
AlfrescoRuntimeException exception1 = new AlfrescoRuntimeException(MSG_PARAMS, new Object[]{PARAM_VALUE});
assertTrue(exception1.getMessage().contains(VALUE_PARAMS));
AlfrescoRuntimeException exception3 = new AlfrescoRuntimeException(MSG_ERROR);
assertTrue(exception3.getMessage().contains(VALUE_ERROR));
// Change the locale and re-test
I18NUtil.setLocale(new Locale("fr", "FR"));
AlfrescoRuntimeException exception2 = new AlfrescoRuntimeException(MSG_PARAMS, new Object[]{PARAM_VALUE});
assertTrue(exception2.getMessage().contains(VALUE_FR_PARAMS));
AlfrescoRuntimeException exception4 = new AlfrescoRuntimeException(MSG_ERROR);
assertTrue(exception4.getMessage().contains(VALUE_FR_ERROR));
AlfrescoRuntimeException exception5 = new AlfrescoRuntimeException(NON_I18NED_MSG);
assertTrue(exception5.getMessage().contains(NON_I18NED_MSG));
// MNT-13028
String param1 = PARAM_VALUE + "_1";
String param2 = PARAM_VALUE + "_2";
String param3 = PARAM_VALUE + "_3";
AlfrescoRuntimeException exception6 = new AlfrescoRuntimeException(NON_EXISTING_MSG, new Object[]{param1, param2, param3});
String message6 = exception6.getMessage();
assertTrue(message6.contains(NON_EXISTING_MSG));
assertTrue(message6.contains(param1));
assertTrue(message6.contains(param2));
assertTrue(message6.contains(param3));
}
示例10: setLocale
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* Sets current Locale from string
*/
public void setLocale(String localeStr)
{
Locale newLocale = I18NUtil.parseLocale(localeStr);
I18NUtil.setLocale(newLocale);
}
示例11: setLocale
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void setLocale(Locale locale)
{
I18NUtil.setLocale(locale);
}
示例12: testCreateSite
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* This test method ensures that public sites can be created and that their site info is correct.
* It also tests that a duplicate site cannot be created.
*/
public void testCreateSite() throws Exception
{
// Create a public site
String mySiteTest = "mySiteTest" + UUID.randomUUID();
SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, mySiteTest, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, mySiteTest, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
String name = "!£$%^&*()_+=-[]{}";
//Calls deprecated method (still creates a public Site)
siteInfo = this.siteService.createSite(TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, true);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
siteInfo = this.siteService.getSite(name);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
name = "éÃóúÃ�ÉÃ�ÓÚ";
siteInfo = this.siteService.createSite(TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
siteInfo = this.siteService.getSite(name);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
NodeRef siteNodeRef = siteInfo.getNodeRef();
assertEquals(siteInfo.getShortName(), this.siteService.getSiteShortName(siteNodeRef));
// Localize the title and description
Locale locale = Locale.getDefault();
try
{
I18NUtil.setLocale(Locale.FRENCH);
nodeService.setProperty(siteNodeRef, ContentModel.PROP_TITLE, "Localized-title");
nodeService.setProperty(siteNodeRef, ContentModel.PROP_DESCRIPTION, "Localized-description");
siteInfo = this.siteService.getSite(name);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, "Localized-title", "Localized-description", SiteVisibility.PUBLIC);
}
finally
{
I18NUtil.setLocale(locale);
}
// Test for duplicate site error
try
{
this.siteService.createSite(TEST_SITE_PRESET, mySiteTest, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
fail("Shouldn't allow duplicate site short names.");
}
catch (AlfrescoRuntimeException exception)
{
// Expected
}
try
{
//Create a site with an invalid site type
this.siteService.createSite(TEST_SITE_PRESET, "InvalidSiteType", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC, ServiceRegistry.CMIS_SERVICE);
fail("Shouldn't allow invalid site type.");
}
catch (SiteServiceException ssexception)
{
// Expected
}
}
示例13: testGetLocalizedSibling
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public void testGetLocalizedSibling() throws Exception
{
FileInfo base = fileFolderService.create(workingRootNodeRef, "Something.ftl", ContentModel.TYPE_CONTENT);
NodeRef node = base.getNodeRef();
NodeRef nodeFr = fileFolderService.create(workingRootNodeRef, "Something_fr.ftl", ContentModel.TYPE_CONTENT).getNodeRef();
NodeRef nodeFrFr = fileFolderService.create(workingRootNodeRef, "Something_fr_FR..ftl", ContentModel.TYPE_CONTENT).getNodeRef();
NodeRef nodeEn = fileFolderService.create(workingRootNodeRef, "Something_en.ftl", ContentModel.TYPE_CONTENT).getNodeRef();
NodeRef nodeEnUs = fileFolderService.create(workingRootNodeRef, "Something_en_US.ftl", ContentModel.TYPE_CONTENT).getNodeRef();
I18NUtil.setLocale(Locale.US);
assertEquals("Match fail for " + I18NUtil.getLocale(), nodeEnUs, fileFolderService.getLocalizedSibling(node));
I18NUtil.setLocale(Locale.UK);
assertEquals("Match fail for " + I18NUtil.getLocale(), nodeEn, fileFolderService.getLocalizedSibling(node));
I18NUtil.setLocale(Locale.CHINESE);
assertEquals("Match fail for " + I18NUtil.getLocale(), node, fileFolderService.getLocalizedSibling(node));
// Now use French as the base and check that the original is returned
I18NUtil.setLocale(Locale.US);
assertEquals("Match fail for " + I18NUtil.getLocale(), nodeFr, fileFolderService.getLocalizedSibling(nodeFr));
I18NUtil.setLocale(Locale.UK);
assertEquals("Match fail for " + I18NUtil.getLocale(), nodeFr, fileFolderService.getLocalizedSibling(nodeFr));
I18NUtil.setLocale(Locale.CHINESE);
assertEquals("Match fail for " + I18NUtil.getLocale(), nodeFr, fileFolderService.getLocalizedSibling(nodeFr));
// Check that extensions like .get.html.ftl work
FileInfo mbase = fileFolderService.create(workingRootNodeRef, "Another.get.html.ftl", ContentModel.TYPE_CONTENT);
NodeRef mnode = mbase.getNodeRef();
NodeRef mnodeFr = fileFolderService.create(workingRootNodeRef, "Another_fr.get.html.ftl", ContentModel.TYPE_CONTENT).getNodeRef();
// Should get the base version, except for when French
I18NUtil.setLocale(Locale.UK);
assertEquals("Match fail for " + I18NUtil.getLocale(), mnode, fileFolderService.getLocalizedSibling(mnode));
I18NUtil.setLocale(Locale.FRENCH);
assertEquals("Match fail for " + I18NUtil.getLocale(), mnodeFr, fileFolderService.getLocalizedSibling(mnode));
I18NUtil.setLocale(Locale.CHINESE);
assertEquals("Match fail for " + I18NUtil.getLocale(), mnode, fileFolderService.getLocalizedSibling(mnode));
I18NUtil.setLocale(Locale.US);
assertEquals("Match fail for " + I18NUtil.getLocale(), mnode, fileFolderService.getLocalizedSibling(mnode));
}
示例14: testCopyMLText
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* https://issues.alfresco.com/jira/browse/ALF-3119
*
* Test copying of MLText values.
*/
public void testCopyMLText()
{
// Create a folder and content node
Map<QName, Serializable> propsFolder = new HashMap<QName, Serializable>(1);
propsFolder.put(ContentModel.PROP_NAME, "tempFolder");
NodeRef folderNode = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "tempFolder"), ContentModel.TYPE_FOLDER, propsFolder).getChildRef();
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, "myDoc.txt");
String FRENCH_DESCRIPTION = "french description";
String GERMAN_DESCRIPTION = "german description";
String ITALY_DESCRIPTION = "italy description";
String DEFAULT_DESCRIPTION = "default description";
MLText description = new MLText();
description.addValue(Locale.getDefault(), DEFAULT_DESCRIPTION);
description.addValue(Locale.FRANCE, FRENCH_DESCRIPTION);
description.addValue(Locale.GERMAN, GERMAN_DESCRIPTION);
description.addValue(Locale.ITALY, ITALY_DESCRIPTION);
props.put(ContentModel.PROP_DESCRIPTION, description);
NodeRef contentNode = nodeService.createNode(folderNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDoc.txt"), ContentModel.TYPE_CONTENT, props).getChildRef();
NodeRef copy = copyService.copyAndRename(contentNode, folderNode, ContentModel.ASSOC_CONTAINS, null, false);
assertEquals("Copy of myDoc.txt", nodeService.getProperty(copy, ContentModel.PROP_NAME));
QName copyQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Copy of myDoc.txt");
assertEquals(copyQName, nodeService.getPrimaryParent(copy).getQName());
// Test uses DB Node Service.
Serializable desc = nodeService.getProperty(copy, ContentModel.PROP_DESCRIPTION);
if(desc instanceof MLText)
{
// Using a node service without a MLProperty interceptor
MLText value = (MLText)desc;
assertEquals("French description is wrong", FRENCH_DESCRIPTION, value.get(Locale.FRANCE));
assertEquals("German description is wrong", GERMAN_DESCRIPTION, value.get(Locale.GERMAN));
}
else
{
I18NUtil.setLocale(Locale.FRANCE);
assertEquals("French description is wrong", FRENCH_DESCRIPTION, nodeService.getProperty(copy, ContentModel.PROP_DESCRIPTION));
I18NUtil.setLocale(Locale.GERMAN);
assertEquals("German description is wrong", GERMAN_DESCRIPTION, nodeService.getProperty(copy, ContentModel.PROP_DESCRIPTION));
}
}
示例15: setup
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@BeforeClass public static void setup() throws Exception
{
I18NUtil.setLocale(null);
serviceRegistry = (ServiceRegistry) APP_CONTEXT_INIT.getApplicationContext().getBean(ServiceRegistry.SERVICE_REGISTRY);
nodeService = serviceRegistry.getNodeService();
nodeIndexer = (NodeIndexer) APP_CONTEXT_INIT.getApplicationContext().getBean("nodeIndexer");
nodeDAO = (NodeDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("nodeDAO");
txnService = serviceRegistry.getTransactionService();
policyComponent = (PolicyComponent) APP_CONTEXT_INIT.getApplicationContext().getBean("policyComponent");
cannedQueryDAOForTesting = (CannedQueryDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("cannedQueryDAOForTesting");
// Get the caches for later testing
nodesCache = (SimpleCache<Serializable, ValueHolder<Serializable>>) APP_CONTEXT_INIT.getApplicationContext().getBean("node.nodesSharedCache");
propsCache = (SimpleCache<Serializable, ValueHolder<Serializable>>) APP_CONTEXT_INIT.getApplicationContext().getBean("node.propertiesSharedCache");
aspectsCache = (SimpleCache<Serializable, ValueHolder<Serializable>>) APP_CONTEXT_INIT.getApplicationContext().getBean("node.aspectsSharedCache");
// Clear the caches to remove fluff
nodesCache.clear();
propsCache.clear();
aspectsCache.clear();
AuthenticationUtil.setRunAsUserSystem();
// create a first store directly
RetryingTransactionCallback<NodeRef> createStoreWork = new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute()
{
StoreRef storeRef = nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE,
"Test_" + System.nanoTime());
return nodeService.getRootNode(storeRef);
}
};
rootNodeRef = txnService.getRetryingTransactionHelper().doInTransaction(createStoreWork);
final QNameDAO qnameDAO = (QNameDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("qnameDAO");
deletedTypeQNameId = txnService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Long>()
{
@Override
public Long execute() throws Throwable
{
return qnameDAO.getOrCreateQName(ContentModel.TYPE_DELETED).getFirst();
}
});
}