Java Code Examples for org.springframework.extensions.surf.util.I18NUtil#setLocale()
The following examples show how to use
org.springframework.extensions.surf.util.I18NUtil#setLocale() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionFormProcessorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * REPO-2253 Community: ALF-21854 Action parameter lookup for "de_DE" falls back to "root" locale instead of "de" */ @Test 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); } }
Example 2
Source File: ActionDefinitionImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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); } }
Example 3
Source File: MetadataEncryptorTests.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Clean up the test thread */ @Override protected void tearDown() { AuthenticationUtil.clearCurrentSecurityContext(); I18NUtil.setLocale(null); }
Example 4
Source File: ExporterComponentTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@After public void after() { I18NUtil.setContentLocale(contentLocaleToRestore); I18NUtil.setLocale(localeToRestore); authenticationComponent.clearCurrentSecurityContext(); }
Example 5
Source File: ExporterComponentTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void dumpNodeStore(Locale locale) { System.out.println(locale.getDisplayLanguage() + " LOCALE: "); I18NUtil.setLocale(locale); System.out.println(NodeStoreInspector.dumpNodeStore((NodeService) applicationContext.getBean("NodeService"), storeRef)); }
Example 6
Source File: LocaleDAOTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
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); }
Example 7
Source File: TemplateServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * @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); } }
Example 8
Source File: FullNodeServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@After public void after() { super.after(); I18NUtil.setContentLocale(contentLocaleToRestore); I18NUtil.setLocale(localeToRestore); }
Example 9
Source File: CopyServiceImplUnitTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private void restoreLocale() { I18NUtil.setLocale(preservedLocale); copyOfLabelTranslated = I18NUtil.getMessage(COPY_OF_LABEL, ""); }
Example 10
Source File: ClearLocaleComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void process(ResponseBuilder rb) throws IOException { I18NUtil.setLocale(null); }
Example 11
Source File: BaseNodeServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Commit @Test public void testPropertyLocaleBehaviour() throws Exception { Map<QName, Serializable> properties = new HashMap<QName, Serializable>(17); properties.put(PROP_QNAME_BOOLEAN_VALUE, true); properties.put(PROP_QNAME_INTEGER_VALUE, 123); properties.put(PROP_QNAME_LONG_VALUE, 123L); properties.put(PROP_QNAME_FLOAT_VALUE, 123.0F); properties.put(PROP_QNAME_DOUBLE_VALUE, 123.0); properties.put(PROP_QNAME_STRING_VALUE, "123.0"); properties.put(PROP_QNAME_ML_TEXT_VALUE, new MLText("This is ML text in the default language")); properties.put(PROP_QNAME_DATE_VALUE, new Date()); // Get the check values Map<QName, Serializable> expectedProperties = new HashMap<QName, Serializable>(properties); getExpectedPropertyValues(expectedProperties); Locale.setDefault(Locale.JAPANESE); // create a new node NodeRef nodeRef = nodeService.createNode( rootNodeRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName("pathA"), TYPE_QNAME_TEST_MANY_PROPERTIES, properties).getChildRef(); // Check the properties again Map<QName, Serializable> checkProperties = nodeService.getProperties(nodeRef); checkProperties(checkProperties, expectedProperties); // Change the locale and set the properties again I18NUtil.setLocale(Locale.US); nodeService.setProperties(nodeRef, properties); // Check the properties again checkProperties = nodeService.getProperties(nodeRef); checkProperties(checkProperties, expectedProperties); // Change the locale and set the properties again I18NUtil.setLocale(Locale.UK); nodeService.setProperties(nodeRef, properties); // Check the properties again checkProperties = nodeService.getProperties(nodeRef); checkProperties(checkProperties, expectedProperties); // Change the locale and set the properties again I18NUtil.setLocale(Locale.US); nodeService.addProperties(nodeRef, properties); // Check the properties again checkProperties = nodeService.getProperties(nodeRef); checkProperties(checkProperties, expectedProperties); // Change the locale and set the properties again I18NUtil.setLocale(Locale.UK); nodeService.addProperties(nodeRef, properties); // Check the properties again checkProperties = nodeService.getProperties(nodeRef); checkProperties(checkProperties, expectedProperties); // Change the locale and set the properties again I18NUtil.setLocale(Locale.US); nodeService.setProperty(nodeRef, PROP_QNAME_DATE_VALUE, properties.get(PROP_QNAME_DATE_VALUE)); // Check the properties again checkProperties = nodeService.getProperties(nodeRef); checkProperties(checkProperties, expectedProperties); // Change the locale and set the properties again I18NUtil.setLocale(Locale.UK); nodeService.setProperty(nodeRef, PROP_QNAME_DATE_VALUE, properties.get(PROP_QNAME_DATE_VALUE)); // Check the properties again checkProperties = nodeService.getProperties(nodeRef); checkProperties(checkProperties, expectedProperties); }
Example 12
Source File: FullNodeServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Test @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)); }
Example 13
Source File: NodeServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void testLocaleSupport() throws Exception { // Ensure that the root node has the default locale Locale locale = (Locale) nodeService.getProperty(rootNodeRef, ContentModel.PROP_LOCALE); assertNotNull("Locale property must occur on every node", locale); assertEquals("Expected default locale on the root node", I18NUtil.getLocale(), locale); assertTrue("Every node must have sys:localized", nodeService.hasAspect(rootNodeRef, ContentModel.ASPECT_LOCALIZED)); // Now switch to a specific locale and create a new node I18NUtil.setLocale(Locale.CANADA_FRENCH); // Create a node using an explicit locale NodeRef nodeRef1 = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER, Collections.singletonMap(ContentModel.PROP_LOCALE, (Serializable)Locale.GERMAN)).getChildRef(); assertTrue("Every node must have sys:localized", nodeService.hasAspect(nodeRef1, ContentModel.ASPECT_LOCALIZED)); assertEquals( "Didn't set the explicit locale during create. ", Locale.GERMAN, nodeService.getProperty(nodeRef1, ContentModel.PROP_LOCALE)); // Create a node using the thread's locale NodeRef nodeRef2 = nodeService.createNode( rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER).getChildRef(); assertTrue("Every node must have sys:localized", nodeService.hasAspect(nodeRef2, ContentModel.ASPECT_LOCALIZED)); assertEquals( "Didn't set the locale during create. ", Locale.CANADA_FRENCH, nodeService.getProperty(nodeRef2, ContentModel.PROP_LOCALE)); // Switch Locale and modify ml:text property I18NUtil.setLocale(Locale.CHINESE); nodeService.setProperty(nodeRef2, ContentModel.PROP_DESCRIPTION, "Chinese description"); I18NUtil.setLocale(Locale.FRENCH); nodeService.setProperty(nodeRef2, ContentModel.PROP_DESCRIPTION, "French description"); // Expect that we have MLText (if we are ML aware) boolean wasMLAware = MLPropertyInterceptor.setMLAware(true); try { MLText checkDescription = (MLText) nodeService.getProperty(nodeRef2, ContentModel.PROP_DESCRIPTION); assertEquals("Chinese description", checkDescription.getValue(Locale.CHINESE)); assertEquals("French description", checkDescription.getValue(Locale.FRENCH)); } finally { MLPropertyInterceptor.setMLAware(wasMLAware); } // But the node locale must not have changed assertEquals( "Node modification should not affect node locale. ", Locale.CANADA_FRENCH, nodeService.getProperty(nodeRef2, ContentModel.PROP_LOCALE)); // Now explicitly set the node's locale nodeService.setProperty(nodeRef2, ContentModel.PROP_LOCALE, Locale.ITALY); assertEquals( "Node locale must be settable. ", Locale.ITALY, nodeService.getProperty(nodeRef2, ContentModel.PROP_LOCALE)); // But mltext must be unchanged assertEquals( "Canada-French must be closest to French. ", "French description", nodeService.getProperty(nodeRef2, ContentModel.PROP_DESCRIPTION)); // Finally, ensure that setting Locale to 'null' is takes the node back to its original locale nodeService.setProperty(nodeRef2, ContentModel.PROP_LOCALE, null); assertEquals( "Node locale set to 'null' does nothing. ", Locale.ITALY, nodeService.getProperty(nodeRef2, ContentModel.PROP_LOCALE)); nodeService.removeProperty(nodeRef2, ContentModel.PROP_LOCALE); assertEquals( "Node locale removal does nothing. ", Locale.ITALY, nodeService.getProperty(nodeRef2, ContentModel.PROP_LOCALE)); // Mass-set the properties, changing the locale in the process Map<QName, Serializable> props = nodeService.getProperties(nodeRef2); props.put(ContentModel.PROP_LOCALE, Locale.GERMAN); nodeService.setProperties(nodeRef2, props); assertEquals( "Node locale not set in setProperties(). ", Locale.GERMAN, nodeService.getProperty(nodeRef2, ContentModel.PROP_LOCALE)); }
Example 14
Source File: NodeServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Clean up the test thread */ @AfterClass public static void tearDown() { AuthenticationUtil.clearCurrentSecurityContext(); I18NUtil.setLocale(null); }
Example 15
Source File: NodeServiceTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@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(); personService = serviceRegistry.getPersonService(); contentService = serviceRegistry.getContentService(); permissionService = serviceRegistry.getPermissionService(); 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(); } }); }
Example 16
Source File: CopyServiceImplUnitTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private void switchLocale(Locale newLocale) { I18NUtil.setLocale(newLocale); copyOfLabelTranslated = I18NUtil.getMessage(COPY_OF_LABEL, ""); }
Example 17
Source File: FileFolderServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@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)); }
Example 18
Source File: SiteServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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. */ @Test 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 } }
Example 19
Source File: MessageServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void setLocale(Locale locale) { I18NUtil.setLocale(locale); }
Example 20
Source File: TenantWebScriptServlet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { if (logger.isDebugEnabled()) logger.debug("Processing tenant request (" + req.getMethod() + ") " + req.getRequestURL() + (req.getQueryString() != null ? "?" + req.getQueryString() : "")); if (req.getCharacterEncoding() == null) { req.setCharacterEncoding("UTF-8"); } setLanguageFromRequestHeader(req); try { WebScriptServletRuntime runtime = getRuntime(req, res); runtime.executeScript(); } catch (IllegalStateException e) { if(e.getMessage().contains("getOutputStream() has already been called for this response")) { if(logger.isDebugEnabled()) { logger.warn("Client has cut off communication", e); } else { logger.warn("Client has cut off communication"); } } else { throw e; } } finally { // clear threadlocal I18NUtil.setLocale(null); // clear authentication and tenant context AuthenticationUtil.clearCurrentSecurityContext(); } }