List of usage examples for com.liferay.portal.kernel.util LocaleThreadLocal getSiteDefaultLocale
public static Locale getSiteDefaultLocale()
From source file:com.liferay.asset.publisher.web.internal.messaging.AssetEntriesCheckerUtil.java
License:Open Source License
private List<AssetEntry> _getAssetEntries(PortletPreferences portletPreferences, Layout layout) throws PortalException { AssetPublisherWebConfiguration assetPublisherWebConfiguration = _configurationProvider .getCompanyConfiguration(AssetPublisherWebConfiguration.class, layout.getCompanyId()); AssetEntryQuery assetEntryQuery = AssetPublisherUtil.getAssetEntryQuery(portletPreferences, layout.getGroupId(), layout, null, null); assetEntryQuery.setEnd(assetPublisherWebConfiguration.dynamicSubscriptionLimit()); assetEntryQuery.setStart(0);/*from www .j a v a 2 s . co m*/ try { SearchContext searchContext = SearchContextFactory.getInstance(new long[0], new String[0], null, layout.getCompanyId(), StringPool.BLANK, layout, LocaleThreadLocal.getSiteDefaultLocale(), layout.getGroupId(), TimeZoneThreadLocal.getDefaultTimeZone(), 0); BaseModelSearchResult<AssetEntry> baseModelSearchResult = _assetHelper.searchAssetEntries(searchContext, assetEntryQuery, 0, assetPublisherWebConfiguration.dynamicSubscriptionLimit()); return baseModelSearchResult.getBaseModels(); } catch (Exception e) { return Collections.emptyList(); } }
From source file:com.liferay.asset.service.test.AssetVocabularyServiceTest.java
License:Open Source License
@Before public void setUp() throws Exception { _group = GroupTestUtil.addGroup(); _locale = LocaleThreadLocal.getSiteDefaultLocale(); }
From source file:com.liferay.document.library.service.test.DLFileEntryTypeServiceTest.java
License:Open Source License
@Test public void testLocalizedSiteAddFileEntryType() throws Exception { Group group = GroupTestUtil.addGroup(); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); Locale locale = LocaleThreadLocal.getSiteDefaultLocale(); try {// www .j ava 2 s .com LocaleThreadLocal.setSiteDefaultLocale(LocaleUtil.SPAIN); String name = RandomTestUtil.randomString(); String description = RandomTestUtil.randomString(); DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(DLFileEntryMetadata.class.getName(), new Locale[] { LocaleUtil.SPAIN }, LocaleUtil.SPAIN); DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( TestPropsValues.getUserId(), group.getGroupId(), name, description, new long[] { ddmStructure.getStructureId() }, serviceContext); Assert.assertEquals(name, dlFileEntryType.getName(LocaleUtil.US, true)); Assert.assertEquals(description, dlFileEntryType.getDescription(LocaleUtil.US, true)); } finally { LocaleThreadLocal.setSiteDefaultLocale(locale); } }
From source file:com.liferay.document.library.service.test.DLFileEntryTypeServiceTest.java
License:Open Source License
@Test public void testLocalizedSiteUpdateFileEntryType() throws Exception { Group group = GroupTestUtil.addGroup(); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); Locale locale = LocaleThreadLocal.getSiteDefaultLocale(); try {/*from www .jav a 2 s . c o m*/ LocaleThreadLocal.setSiteDefaultLocale(LocaleUtil.SPAIN); String name = RandomTestUtil.randomString(); String description = RandomTestUtil.randomString(); DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(DLFileEntryMetadata.class.getName(), new Locale[] { LocaleUtil.SPAIN }, LocaleUtil.SPAIN); DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( TestPropsValues.getUserId(), group.getGroupId(), name, description, new long[] { ddmStructure.getStructureId() }, serviceContext); name = RandomTestUtil.randomString(); description = RandomTestUtil.randomString(); DLFileEntryTypeLocalServiceUtil.updateFileEntryType(TestPropsValues.getUserId(), dlFileEntryType.getFileEntryTypeId(), name, description, new long[] { ddmStructure.getStructureId() }, serviceContext); dlFileEntryType = DLFileEntryTypeLocalServiceUtil .getFileEntryType(dlFileEntryType.getFileEntryTypeId()); Assert.assertEquals(name, dlFileEntryType.getName(LocaleUtil.US, true)); Assert.assertEquals(description, dlFileEntryType.getDescription(LocaleUtil.US, true)); } finally { LocaleThreadLocal.setSiteDefaultLocale(locale); } }
From source file:com.liferay.dynamic.data.mapping.form.builder.internal.context.DDMFormContextToDDMFormValues.java
License:Open Source License
protected DDMFormValues deserialize(DDMForm ddmForm, String serializedFormContext) throws PortalException { JSONObject jsonObject = jsonFactory.createJSONObject(serializedFormContext); DDMFormValues ddmFormValues = new DDMFormValues(ddmForm); Locale defaultLocale = LocaleThreadLocal.getSiteDefaultLocale(); ddmFormValues.addAvailableLocale(defaultLocale); ddmFormValues.setDefaultLocale(defaultLocale); setDDMFormValuesDDMFormFieldValues(jsonObject.getJSONArray("pages"), ddmFormValues); return ddmFormValues; }
From source file:com.liferay.dynamic.data.mapping.form.builder.internal.context.DDMFormContextToDDMFormValues.java
License:Open Source License
protected Value getLocalizedValue(JSONObject jsonObject) { Value value = new LocalizedValue(LocaleThreadLocal.getSiteDefaultLocale()); Iterator<String> itr = jsonObject.keys(); while (itr.hasNext()) { String languageId = itr.next(); value.addString(LocaleUtil.fromLanguageId(languageId), jsonObject.getString(languageId)); }//from ww w. j a va 2s .c o m return value; }
From source file:com.liferay.dynamic.data.mapping.form.renderer.internal.DDMFormTemplateContextFactoryImpl.java
License:Open Source License
protected Map<String, Object> doCreate(DDMForm ddmForm, DDMFormLayout ddmFormLayout, DDMFormRenderingContext ddmFormRenderingContext) throws PortalException { Map<String, Object> templateContext = new HashMap<>(); String containerId = ddmFormRenderingContext.getContainerId(); if (Validator.isNull(containerId)) { containerId = StringUtil.randomId(); }/*from w w w .j a v a 2 s.c om*/ templateContext.put("containerId", containerId); templateContext.put("dataProviderSettings", _ddmFormTemplateContextFactoryHelper.getDataProviderSettings(ddmForm)); setDDMFormFieldsEvaluableProperty(ddmForm); templateContext.put("evaluatorURL", getDDMFormContextProviderServletURL()); List<DDMFormFieldType> ddmFormFieldTypes = _ddmFormFieldTypeServicesTracker.getDDMFormFieldTypes(); templateContext.put("fieldTypes", _ddmFormFieldTypesJSONSerializer.serialize(ddmFormFieldTypes)); templateContext.put("groupId", ddmFormRenderingContext.getGroupId()); List<Object> pages = getPages(ddmForm, ddmFormLayout, ddmFormRenderingContext); templateContext.put("pages", pages); templateContext.put("portletNamespace", ddmFormRenderingContext.getPortletNamespace()); templateContext.put("readOnly", ddmFormRenderingContext.isReadOnly()); Locale locale = ddmFormRenderingContext.getLocale(); if (locale == null) { locale = LocaleThreadLocal.getSiteDefaultLocale(); } ResourceBundle resourceBundle = getResourceBundle(locale); SoyHTMLContextValue soyHTMLContextValue = new SoyHTMLContextValue( getRequiredFieldsWarningMessageHTML(resourceBundle)); templateContext.put("requiredFieldsWarningMessageHTML", soyHTMLContextValue.getValue()); templateContext.put("rules", toObjectList(ddmForm.getDDMFormRules())); templateContext.put("showRequiredFieldsWarning", ddmFormRenderingContext.isShowRequiredFieldsWarning()); boolean showSubmitButton = ddmFormRenderingContext.isShowSubmitButton(); if (ddmFormRenderingContext.isReadOnly()) { showSubmitButton = false; } templateContext.put("showSubmitButton", showSubmitButton); templateContext.put("strings", getLanguageStringsMap(resourceBundle)); String submitLabel = GetterUtil.getString(ddmFormRenderingContext.getSubmitLabel(), LanguageUtil.get(locale, "submit")); templateContext.put("submitLabel", submitLabel); templateContext.put("templateNamespace", getTemplateNamespace(ddmFormLayout)); return templateContext; }
From source file:com.liferay.dynamic.data.mapping.form.renderer.internal.DDMFormTemplateContextFactoryTest.java
License:Open Source License
protected void setUpLocaleThreadLocal() { _originalSiteDefaultLocale = LocaleThreadLocal.getSiteDefaultLocale(); LocaleThreadLocal.setSiteDefaultLocale(LocaleUtil.US); }
From source file:com.liferay.dynamic.data.mapping.form.values.factory.internal.DDMFormValuesFactoryImpl.java
License:Open Source License
protected Set<Locale> getAvailableLocales(String[] availableLanguageIds) { Set<Locale> availableLocales = new HashSet<>(); for (String availableLanguageId : availableLanguageIds) { Locale availableLocale = LocaleUtil.fromLanguageId(availableLanguageId); availableLocales.add(availableLocale); }//from w ww. j a v a2 s .c o m if (availableLocales.isEmpty()) { availableLocales.add(LocaleThreadLocal.getSiteDefaultLocale()); } return availableLocales; }
From source file:com.liferay.dynamic.data.mapping.form.values.factory.internal.DDMFormValuesFactoryImpl.java
License:Open Source License
protected Locale getDefaultLocale(HttpServletRequest httpServletRequest) { String defaultLanguageId = ParamUtil.getString(httpServletRequest, "defaultLanguageId"); if (Validator.isNull(defaultLanguageId)) { return LocaleThreadLocal.getSiteDefaultLocale(); }// w ww . j a va 2 s . c o m return LocaleUtil.fromLanguageId(defaultLanguageId); }