本文整理汇总了Java中org.springframework.extensions.surf.util.I18NUtil.setContentLocale方法的典型用法代码示例。如果您正苦于以下问题:Java I18NUtil.setContentLocale方法的具体用法?Java I18NUtil.setContentLocale怎么用?Java I18NUtil.setContentLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.extensions.surf.util.I18NUtil
的用法示例。
在下文中一共展示了I18NUtil.setContentLocale方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testShallowFilesAndFoldersListWithLocale
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void testShallowFilesAndFoldersListWithLocale() throws Exception
{
Locale savedLocale = I18NUtil.getContentLocaleOrNull();
try
{
I18NUtil.setContentLocale(Locale.CANADA);
List<FileInfo> files = fileFolderService.list(workingRootNodeRef);
// check
String[] expectedNames = new String[]
{ NAME_L0_FILE_A, NAME_L0_FILE_B, NAME_L0_FOLDER_A, NAME_L0_FOLDER_B, NAME_L0_FOLDER_C };
checkFileList(files, 2, 3, expectedNames);
}
finally
{
I18NUtil.setContentLocale(savedLocale);
}
}
示例2: processTemplate
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplate(java.lang.String, java.lang.String, java.lang.Object, java.util.Locale)
*/
private void processTemplate(String engine, String template, Object model, Writer out, Locale locale)
throws TemplateException
{
Locale currentLocale = I18NUtil.getLocaleOrNull();
Locale currentContentLocale = I18NUtil.getContentLocaleOrNull();
try
{
// set locale for cases where message method is used inside of template
I18NUtil.setLocale(locale);
// execute template processor
TemplateProcessor processor = getTemplateProcessor(engine);
processor.process(template, model, out, locale);
}
catch (TemplateException terr)
{
throw terr;
}
catch (Throwable err)
{
throw new TemplateException(err.getMessage(), err);
}
finally
{
I18NUtil.setLocale(currentLocale);
I18NUtil.setContentLocale(currentContentLocale);
}
}
示例3: onTearDown
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@Override
protected void onTearDown() throws Exception
{
super.onTearDown();
I18NUtil.setContentLocale(contentLocaleToRestore);
I18NUtil.setLocale(localeToRestore);
}
示例4: testGetType
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
/**
* Validates <a href="https://issues.alfresco.com/jira/browse/ALFCOM-2655">ACT-7225</a>
*/
public void testGetType() throws Exception
{
Locale savedLocale = I18NUtil.getContentLocaleOrNull();
try
{
I18NUtil.setContentLocale(Locale.CANADA);
FileFolderServiceType type = fileFolderService.getType(ContentModel.TYPE_FOLDER);
assertEquals("Type incorrect for folder", FileFolderServiceType.FOLDER, type);
}
finally
{
I18NUtil.setContentLocale(savedLocale);
}
}
示例5: testMLValuesOnCreate
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void testMLValuesOnCreate() throws Exception
{
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
fillProperties(BaseNodeServiceTest.TYPE_QNAME_TEST_MANY_PROPERTIES, properties);
// Replace the MLText value with a plain string
properties.put(BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, "Bonjour");
// Now switch to French
I18NUtil.setContentLocale(Locale.FRENCH);
// Create a node with the value
NodeRef nodeRef = nodeService.createNode(
rootNodeRef,
BaseNodeServiceTest.ASSOC_TYPE_QNAME_TEST_CHILDREN,
QName.createQName(BaseNodeServiceTest.NAMESPACE, getName()),
BaseNodeServiceTest.TYPE_QNAME_TEST_MANY_PROPERTIES,
properties).getChildRef();
// Now switch to English
I18NUtil.setContentLocale(Locale.ENGLISH);
// Set the english property
nodeService.setProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, "Hello");
// Switch back to French and get the value
I18NUtil.setContentLocale(Locale.FRENCH);
assertEquals(
"Expected French value property",
"Bonjour",
nodeService.getProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE));
// Switch back to English and get the value
I18NUtil.setContentLocale(Locale.ENGLISH);
assertEquals(
"Expected English value property",
"Hello",
nodeService.getProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE));
}
示例6: testMLValuesOnAddAspect
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void testMLValuesOnAddAspect() throws Exception
{
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
fillProperties(BaseNodeServiceTest.TYPE_QNAME_TEST_MANY_PROPERTIES, properties);
// Replace the MLText value with a plain string
properties.put(BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, "Bonjour");
// Now switch to French
I18NUtil.setContentLocale(Locale.FRENCH);
// Add an aspect
NodeRef nodeRef = rootNodeRef;
nodeService.addAspect(
nodeRef,
BaseNodeServiceTest.ASPECT_QNAME_TEST_TITLED,
properties);
// Now switch to English
I18NUtil.setContentLocale(Locale.ENGLISH);
// Set the english property
nodeService.setProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, "Hello");
// Switch back to French and get the value
I18NUtil.setContentLocale(Locale.FRENCH);
assertEquals(
"Expected French value property",
"Bonjour",
nodeService.getProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE));
// Switch back to English and get the value
I18NUtil.setContentLocale(Locale.ENGLISH);
assertEquals(
"Expected English value property",
"Hello",
nodeService.getProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE));
}
示例7: testMLValuesOnAddProperties
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void testMLValuesOnAddProperties() throws Exception
{
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
fillProperties(BaseNodeServiceTest.TYPE_QNAME_TEST_MANY_PROPERTIES, properties);
// Replace the MLText value with a plain string
properties.put(BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, "Bonjour");
// Now switch to French
I18NUtil.setContentLocale(Locale.FRENCH);
// Add an aspect
NodeRef nodeRef = rootNodeRef;
nodeService.addProperties(nodeRef, properties);
// Now switch to English
I18NUtil.setContentLocale(Locale.ENGLISH);
// Set the english property
nodeService.setProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE, "Hello");
// Switch back to French and get the value
I18NUtil.setContentLocale(Locale.FRENCH);
assertEquals(
"Expected French value property",
"Bonjour",
nodeService.getProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE));
// Switch back to English and get the value
I18NUtil.setContentLocale(Locale.ENGLISH);
assertEquals(
"Expected English value property",
"Hello",
nodeService.getProperty(nodeRef, BaseNodeServiceTest.PROP_QNAME_ML_TEXT_VALUE));
}
示例8: setContentLocale
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void setContentLocale(Locale locale)
{
I18NUtil.setContentLocale(locale);
}
示例9: testMLText
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void testMLText() throws Exception
{
NodeRef rootNode = nodeService.getRootNode(storeRef);
NodeRef folderNodeRef = nodeService.createNode(
rootNode,
ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN,
ContentModel.TYPE_FOLDER).getChildRef();
FileInfo exportFolder = fileFolderService.create(folderNodeRef, "export", ContentModel.TYPE_FOLDER);
FileInfo content = fileFolderService.create(exportFolder.getNodeRef(), "file", ContentModel.TYPE_CONTENT);
MLText title = new MLText();
title.addValue(Locale.ENGLISH, null);
title.addValue(Locale.FRENCH, "bonjour");
nodeService.setProperty(content.getNodeRef(), ContentModel.PROP_TITLE, title);
nodeService.setProperty(content.getNodeRef(), ContentModel.PROP_NAME, "file");
FileInfo importFolder = fileFolderService.create(folderNodeRef, "import", ContentModel.TYPE_FOLDER);
// export
File acpFile = exportContent(exportFolder.getNodeRef());
// import
FileInfo importFolderFileInfo = importContent(acpFile, importFolder.getNodeRef());
assertNotNull(importFolderFileInfo);
NodeRef importedFileNode = fileFolderService.searchSimple(importFolderFileInfo.getNodeRef(), "file");
assertNotNull("Couldn't find imported file: file", importedFileNode);
Locale currentLocale = I18NUtil.getContentLocale();
try
{
I18NUtil.setContentLocale(Locale.ENGLISH);
String importedTitle = (String)nodeService.getProperty(importedFileNode, ContentModel.PROP_TITLE);
assertNull(importedTitle);
I18NUtil.setContentLocale(Locale.FRENCH);
importedTitle = (String)nodeService.getProperty(importedFileNode, ContentModel.PROP_TITLE);
assertNotNull(importedTitle);
assertEquals("bonjour", importedTitle);
}
finally
{
I18NUtil.setContentLocale(currentLocale);
}
}
示例10: setUp
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception
{
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
transactionService = serviceRegistry.getTransactionService();
nodeService = serviceRegistry.getNodeService();
fileFolderService = serviceRegistry.getFileFolderService();
permissionService = serviceRegistry.getPermissionService();
authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
tenantService = (TenantService) ctx.getBean("tenantService");
cociService = serviceRegistry.getCheckOutCheckInService();
// start the transaction
txn = transactionService.getUserTransaction();
txn.begin();
// downgrade integrity
IntegrityChecker.setWarnInTransaction();
// authenticate
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
// create a test store
StoreRef storeRef = nodeService
.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
rootNodeRef = nodeService.getRootNode(storeRef);
// create a folder to import into
workingRootNodeRef = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
ContentModel.TYPE_FOLDER).getChildRef();
// import the test data
ImporterService importerService = serviceRegistry.getImporterService();
Location importLocation = new Location(workingRootNodeRef);
InputStream is = getClass().getClassLoader().getResourceAsStream(IMPORT_VIEW);
if (is == null)
{
throw new NullPointerException("Test resource not found: " + IMPORT_VIEW);
}
Reader reader = new InputStreamReader(is);
importerService.importView(reader, importLocation, null, null);
// Load test model
DictionaryBootstrap bootstrap = new DictionaryBootstrap();
List<String> bootstrapModels = new ArrayList<String>();
bootstrapModels.add("org/alfresco/repo/model/filefolder/testModel.xml");
List<String> labels = new ArrayList<String>();
bootstrap.setModels(bootstrapModels);
bootstrap.setLabels(labels);
bootstrap.setDictionaryDAO(dictionaryDAO);
bootstrap.setTenantService(tenantService);
bootstrap.bootstrap();
workingRootNodeRef1 = nodeService.createNode(
rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.ALFRESCO_URI, "working root1"),
QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "folder")).getChildRef();
nodeService.createNode(
workingRootNodeRef1,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.ALFRESCO_URI, "node1"),
ContentModel.TYPE_CONTENT).getChildRef();
nodeService.createNode(
workingRootNodeRef1,
QName.createQName("http://www.alfresco.org/test/filefoldertest/1.0", "contains1"),
QName.createQName(NamespaceService.ALFRESCO_URI, "node2"),
ContentModel.TYPE_CONTENT).getChildRef();
// Make sure we hit the MLTranslationInterceptor, which is part of the Foundation API
// See MNT-9114: FileFolderService method not registered in MLTranslationInterceptor
I18NUtil.setContentLocale(Locale.ENGLISH);
}
示例11: testPatterns
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
public void testPatterns()
{
// sanity checks only (see also GetChildrenCannedQueryTest)
I18NUtil.setContentLocale(Locale.CANADA);
// test 1
PagingRequest pagingRequest = new PagingRequest(100, null);
PagingResults<FileInfo> pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L0*", null, null, pagingRequest);
assertNotNull(pagingResults);
assertFalse(pagingResults.hasMoreItems());
assertNull(pagingResults.getTotalResultCount());
List<FileInfo> files = pagingResults.getPage();
// check
String[] expectedNames = new String[]
{ NAME_L0_FILE_A, NAME_L0_FILE_B, NAME_L0_FOLDER_A, NAME_L0_FOLDER_B, NAME_L0_FOLDER_C };
checkFileList(files, 2, 3, expectedNames);
// test 2
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L1*", null, null, pagingRequest);
assertNotNull(pagingResults);
assertFalse(pagingResults.hasMoreItems());
assertNull(pagingResults.getTotalResultCount());
files = pagingResults.getPage();
// check
expectedNames = new String[]
{ };
checkFileList(files, 0, 0, expectedNames);
// test 3
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L0*File*", null, null, pagingRequest);
assertNotNull(pagingResults);
assertFalse(pagingResults.hasMoreItems());
assertNull(pagingResults.getTotalResultCount());
files = pagingResults.getPage();
// check
expectedNames = new String[]
{ NAME_L0_FILE_A, NAME_L0_FILE_B };
checkFileList(files, 2, 0, expectedNames);
}
示例12: onTearDownInTransaction
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@Override
protected void onTearDownInTransaction() throws Exception
{
super.onTearDownInTransaction();
I18NUtil.setContentLocale(null);
}
示例13: testMLTextCollectionUpdatedForCorrectLanguage
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testMLTextCollectionUpdatedForCorrectLanguage()
{
Locale.setDefault(Locale.UK);
I18NUtil.setContentLocale(Locale.UK);
I18NUtil.setLocale(Locale.UK);
MLPropertyInterceptor.setMLAware(true);
ArrayList<Serializable> values = new ArrayList<Serializable>();
values.add(new MLText(Locale.UK, "en_GB text"));
values.add(new MLText(Locale.US, "en_US text"));
values.add(new MLText(Locale.FRANCE, "fr_FR text"));
// Set the property with no MLText filtering
nodeService.setProperty(rootNodeRef, PROP_QNAME_MULTI_ML_VALUE, values);
// Pre-test check
List<Serializable> checkValues = (List<Serializable>) nodeService.getProperty(
rootNodeRef, PROP_QNAME_MULTI_ML_VALUE);
assertEquals("Expected 3 MLText values back", 3, checkValues.size());
assertEquals("en_GB text", ((MLText) checkValues.get(0)).getValue(Locale.UK));
assertEquals("en_US text", ((MLText) checkValues.get(1)).getValue(Locale.US));
assertEquals("fr_FR text", ((MLText) checkValues.get(2)).getValue(Locale.FRANCE));
// Enable MLText filtering - as this is how the repo will be used.
MLPropertyInterceptor.setMLAware(false);
// Filtering will result in a list containing en_GB only
checkValues = (List<Serializable>) nodeService.getProperty(
rootNodeRef,
PROP_QNAME_MULTI_ML_VALUE);
assertEquals("Expected 1 MLText values back", 1, checkValues.size());
assertEquals("en_GB text", (String) checkValues.get(0));
// Update the property, only this time using a different English variant
Locale.setDefault(Locale.US); // en_US
values.clear();
values.add("text 1 added using en_US");
values.add("text 2 added using en_US");
values.add("text 3 added using en_US");
values.add("text 4 added using en_US");
nodeService.setProperty(rootNodeRef, PROP_QNAME_MULTI_ML_VALUE, values);
// Check that the text was updated correctly
MLPropertyInterceptor.setMLAware(true); // no filtering - see real MLText
checkValues = (List<Serializable>) nodeService.getProperty(
rootNodeRef,
PROP_QNAME_MULTI_ML_VALUE);
assertEquals("Expected 3 MLText values back", 4, checkValues.size());
MLText mlText = ((MLText) checkValues.get(0));
assertEquals("en_GB should be replaced with new, not added to", 1, mlText.size());
assertEquals("text 1 added using en_US", mlText.getValue(Locale.ENGLISH));
mlText = ((MLText) checkValues.get(1));
assertEquals("en_US should be replaced with new, not added to", 1, mlText.size());
assertEquals("text 2 added using en_US", mlText.getValue(Locale.ENGLISH));
mlText = ((MLText) checkValues.get(2));
assertEquals("en_US should be added to fr_FR", 2, mlText.size());
assertEquals("fr_FR text", mlText.getValue(Locale.FRANCE));
assertEquals("text 3 added using en_US", mlText.getValue(Locale.ENGLISH));
mlText = ((MLText) checkValues.get(3));
assertEquals("entirely new text value should be added", 1, mlText.size());
assertEquals("text 4 added using en_US", mlText.getValue(Locale.ENGLISH));
}
示例14: testMultiValueMLTextProperties
import org.springframework.extensions.surf.util.I18NUtil; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void testMultiValueMLTextProperties() throws Exception
{
NodeRef nodeRef = nodeService.createNode(
rootNodeRef,
ASSOC_TYPE_QNAME_TEST_CHILDREN,
QName.createQName("pathA"),
TYPE_QNAME_TEST_MANY_ML_PROPERTIES).getChildRef();
// Create MLText properties and add to a collection
List<MLText> mlTextCollection = new ArrayList<MLText>(2);
MLText mlText0 = new MLText();
mlText0.addValue(Locale.ENGLISH, "Hello");
mlText0.addValue(Locale.FRENCH, "Bonjour");
mlTextCollection.add(mlText0);
MLText mlText1 = new MLText();
mlText1.addValue(Locale.ENGLISH, "Bye bye");
mlText1.addValue(Locale.FRENCH, "Au revoir");
mlTextCollection.add(mlText1);
nodeService.setProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE, (Serializable) mlTextCollection);
I18NUtil.setContentLocale(Locale.ENGLISH);
Collection<String> mlTextCollectionCheck = (Collection<String>) nodeService.getProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE);
assertEquals("MLText collection didn't come back correctly.", Arrays.asList(new String[]{"Hello", "Bye bye"}), mlTextCollectionCheck);
I18NUtil.setContentLocale(Locale.FRENCH);
mlTextCollectionCheck = (Collection<String>) nodeService.getProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE);
assertEquals("MLText collection didn't come back correctly.", Arrays.asList(new String[]{"Bonjour", "Au revoir"}), mlTextCollectionCheck);
I18NUtil.setContentLocale(Locale.GERMAN);
nodeService.setProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE, (Serializable)Arrays.asList(new String[]{"eins", "zwei", "drie", "vier"}));
I18NUtil.setContentLocale(Locale.ENGLISH);
mlTextCollectionCheck = (Collection<String>) nodeService.getProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE);
assertEquals("MLText collection didn't come back correctly.", Arrays.asList(new String[]{"Hello", "Bye bye"}), mlTextCollectionCheck);
I18NUtil.setContentLocale(Locale.FRENCH);
mlTextCollectionCheck = (Collection<String>) nodeService.getProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE);
assertEquals("MLText collection didn't come back correctly.", Arrays.asList(new String[]{"Bonjour", "Au revoir"}), mlTextCollectionCheck);
I18NUtil.setContentLocale(Locale.GERMAN);
mlTextCollectionCheck = (Collection<String>) nodeService.getProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE);
assertEquals("MLText collection didn't come back correctly.", Arrays.asList(new String[]{"eins", "zwei", "drie", "vier"}), mlTextCollectionCheck);
I18NUtil.setContentLocale(Locale.GERMAN);
nodeService.setProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE, (Serializable)Arrays.asList(new String[]{"eins"}));
I18NUtil.setContentLocale(Locale.ENGLISH);
mlTextCollectionCheck = (Collection<String>) nodeService.getProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE);
assertEquals("MLText collection didn't come back correctly.", Arrays.asList(new String[]{"Hello", "Bye bye"}), mlTextCollectionCheck);
I18NUtil.setContentLocale(Locale.FRENCH);
mlTextCollectionCheck = (Collection<String>) nodeService.getProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE);
assertEquals("MLText collection didn't come back correctly.", Arrays.asList(new String[]{"Bonjour", "Au revoir"}), mlTextCollectionCheck);
I18NUtil.setContentLocale(Locale.GERMAN);
mlTextCollectionCheck = (Collection<String>) nodeService.getProperty(nodeRef, PROP_QNAME_MULTI_ML_VALUE);
assertEquals("MLText collection didn't come back correctly.", Arrays.asList(new String[]{"eins"}), mlTextCollectionCheck);
}