List of usage examples for com.liferay.portal.kernel.util LocalizationUtil setLocalizedPreferencesValues
public static void setLocalizedPreferencesValues(PortletRequest portletRequest, PortletPreferences preferences, String parameter) throws Exception
From source file:com.fmdp.webform.action.ConfigurationActionImpl.java
License:Open Source License
@Override public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { validateFields(actionRequest);/*from w w w .ja v a 2 s .c om*/ // boolean uploadToDM = ParamUtil.getBoolean(actionRequest, // "uploadToDM"); // String uploadDiskDir = ParamUtil.getString( // actionRequest, "uploadDiskDir"); long newFolderId = ParamUtil.getLong(actionRequest, "newFolderId"); if (!SessionErrors.isEmpty(actionRequest)) { return; } Locale defaultLocale = LocaleUtil.getDefault(); String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale); boolean updateFields = ParamUtil.getBoolean(actionRequest, "updateFields"); String portletResource = ParamUtil.getString(actionRequest, "portletResource"); PortletPreferences preferences = actionRequest.getPreferences(); // preferences.setValue("uploadToDisk", String.valueOf(uploadToDisk)); // preferences.setValue("uploadDiskDir", uploadDiskDir); LocalizationUtil.setLocalizedPreferencesValues(actionRequest, preferences, "title"); LocalizationUtil.setLocalizedPreferencesValues(actionRequest, preferences, "description"); if (updateFields) { int i = 1; boolean uploadToDisk = ParamUtil.getBoolean(actionRequest, "uploadToDisk"); boolean uploadToDM = ParamUtil.getBoolean(actionRequest, "uploadToDM"); boolean uploadIsWanted = uploadToDisk || uploadToDM; boolean isFileUpload = false; int howManyFileUploadFields = 0; String databaseTableName = WebFormUtil.getNewDatabaseTableName(portletResource); preferences.setValue("databaseTableName", databaseTableName); preferences.setValue("uploadToDisk", String.valueOf(uploadToDisk)); preferences.setValue("uploadToDM", String.valueOf(uploadToDM)); preferences.setValue("newFolderId", String.valueOf(newFolderId)); int[] formFieldsIndexes = StringUtil.split(ParamUtil.getString(actionRequest, "formFieldsIndexes"), 0); for (int formFieldsIndex : formFieldsIndexes) { Map<Locale, String> fieldLabelMap = LocalizationUtil.getLocalizationMap(actionRequest, "fieldLabel" + formFieldsIndex); if (Validator.isNull(fieldLabelMap.get(defaultLocale))) { continue; } String fieldType = ParamUtil.getString(actionRequest, "fieldType" + formFieldsIndex); if ("file".equals(fieldType)) { isFileUpload = true; howManyFileUploadFields++; } if (howManyFileUploadFields > 1) { SessionErrors.add(actionRequest, "tooManyFileUploadFields" + i); } boolean fieldOptional = ParamUtil.getBoolean(actionRequest, "fieldOptional" + formFieldsIndex); Map<Locale, String> fieldOptionsMap = LocalizationUtil.getLocalizationMap(actionRequest, "fieldOptions" + formFieldsIndex); String fieldValidationScript = ParamUtil.getString(actionRequest, "fieldValidationScript" + formFieldsIndex); String fieldValidationErrorMessage = ParamUtil.getString(actionRequest, "fieldValidationErrorMessage" + formFieldsIndex); if (Validator.isNotNull(fieldValidationScript) ^ Validator.isNotNull(fieldValidationErrorMessage)) { SessionErrors.add(actionRequest, "validationDefinitionInvalid" + i); } updateModifiedLocales("fieldLabel" + i, fieldLabelMap, preferences); updateModifiedLocales("fieldOptions" + i, fieldOptionsMap, preferences); preferences.setValue("fieldType" + i, fieldType); preferences.setValue("fieldOptional" + i, String.valueOf(fieldOptional)); preferences.setValue("fieldValidationScript" + i, fieldValidationScript); preferences.setValue("fieldValidationErrorMessage" + i, fieldValidationErrorMessage); i++; } preferences.setValue("isFileUpload", String.valueOf(isFileUpload)); if (!uploadIsWanted && isFileUpload) { SessionErrors.add(actionRequest, "uploadMethodUndefined"); } if (!SessionErrors.isEmpty(actionRequest)) { return; } // Clear previous preferences that are now blank String fieldLabel = LocalizationUtil.getPreferencesValue(preferences, "fieldLabel" + i, defaultLanguageId); while (Validator.isNotNull(fieldLabel)) { Map<Locale, String> fieldLabelMap = LocalizationUtil.getLocalizationMap(actionRequest, "fieldLabel" + i); for (Locale locale : fieldLabelMap.keySet()) { String languageId = LocaleUtil.toLanguageId(locale); LocalizationUtil.setPreferencesValue(preferences, "fieldLabel" + i, languageId, StringPool.BLANK); LocalizationUtil.setPreferencesValue(preferences, "fieldOptions" + i, languageId, StringPool.BLANK); } preferences.setValue("fieldType" + i, StringPool.BLANK); preferences.setValue("fieldOptional" + i, StringPool.BLANK); preferences.setValue("fieldValidationScript" + i, StringPool.BLANK); preferences.setValue("fieldValidationErrorMessage" + i, StringPool.BLANK); i++; fieldLabel = LocalizationUtil.getPreferencesValue(preferences, "fieldLabel" + i, defaultLanguageId); } } if (SessionErrors.isEmpty(actionRequest)) { preferences.store(); } super.processAction(portletConfig, actionRequest, actionResponse); }
From source file:com.liferay.portlet.usersadmin.action.EditOrganizationAction.java
License:Open Source License
protected Organization updateOrganization(ActionRequest actionRequest) throws Exception { long organizationId = ParamUtil.getLong(actionRequest, "organizationId"); long parentOrganizationId = ParamUtil.getLong(actionRequest, "parentOrganizationSearchContainerPrimaryKeys", OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID); String name = ParamUtil.getString(actionRequest, "name"); boolean recursable = ParamUtil.getBoolean(actionRequest, "recursable"); int statusId = ParamUtil.getInteger(actionRequest, "statusId"); String type = ParamUtil.getString(actionRequest, "type"); long regionId = ParamUtil.getLong(actionRequest, "regionId"); long countryId = ParamUtil.getLong(actionRequest, "countryId"); String comments = ParamUtil.getString(actionRequest, "comments"); boolean site = ParamUtil.getBoolean(actionRequest, "site"); List<Address> addresses = UsersAdminUtil.getAddresses(actionRequest); List<EmailAddress> emailAddresses = UsersAdminUtil.getEmailAddresses(actionRequest); List<OrgLabor> orgLabors = UsersAdminUtil.getOrgLabors(actionRequest); List<Phone> phones = UsersAdminUtil.getPhones(actionRequest); List<Website> websites = UsersAdminUtil.getWebsites(actionRequest); ServiceContext serviceContext = ServiceContextFactory.getInstance(Organization.class.getName(), actionRequest);/*from w w w. j a va2 s.co m*/ Organization organization = null; if (organizationId <= 0) { // Add organization organization = OrganizationServiceUtil.addOrganization(parentOrganizationId, name, type, recursable, regionId, countryId, statusId, comments, site, addresses, emailAddresses, orgLabors, phones, websites, serviceContext); } else { // Update organization organization = OrganizationServiceUtil.updateOrganization(organizationId, parentOrganizationId, name, type, recursable, regionId, countryId, statusId, comments, site, addresses, emailAddresses, orgLabors, phones, websites, serviceContext); boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo"); if (deleteLogo) { OrganizationServiceUtil.deleteLogo(organization.getOrganizationId()); } } // Layout set prototypes long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId"); long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId"); SitesUtil.applyLayoutSetPrototypes(organization.getGroup(), publicLayoutSetPrototypeId, privateLayoutSetPrototypeId, serviceContext); // Reminder queries String reminderQueries = actionRequest.getParameter("reminderQueries"); PortletPreferences preferences = organization.getPreferences(); LocalizationUtil.setLocalizedPreferencesValues(actionRequest, preferences, "reminderQueries"); preferences.setValue("reminderQueries", reminderQueries); preferences.store(); return organization; }
From source file:com.liferay.users.admin.web.internal.portlet.action.EditOrganizationMVCActionCommand.java
License:Open Source License
protected Organization updateOrganization(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long organizationId = ParamUtil.getLong(actionRequest, "organizationId"); long parentOrganizationId = ParamUtil.getLong(actionRequest, "parentOrganizationSearchContainerPrimaryKeys", OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID); String name = ParamUtil.getString(actionRequest, "name"); long statusId = ParamUtil.getLong(actionRequest, "statusId"); String type = ParamUtil.getString(actionRequest, "type"); long regionId = ParamUtil.getLong(actionRequest, "regionId"); long countryId = ParamUtil.getLong(actionRequest, "countryId"); String comments = ParamUtil.getString(actionRequest, "comments"); boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo"); byte[] logoBytes = null; long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); if (fileEntryId > 0) { FileEntry fileEntry = _dlAppLocalService.getFileEntry(fileEntryId); logoBytes = FileUtil.getBytes(fileEntry.getContentStream()); }// w ww .ja v a 2s . c o m boolean site = ParamUtil.getBoolean(actionRequest, "site"); List<Address> addresses = UsersAdminUtil.getAddresses(actionRequest); List<EmailAddress> emailAddresses = UsersAdminUtil.getEmailAddresses(actionRequest); List<OrgLabor> orgLabors = UsersAdminUtil.getOrgLabors(actionRequest); List<Phone> phones = UsersAdminUtil.getPhones(actionRequest); List<Website> websites = UsersAdminUtil.getWebsites(actionRequest); ServiceContext serviceContext = ServiceContextFactory.getInstance(Organization.class.getName(), actionRequest); Organization organization = null; if (organizationId <= 0) { // Add organization organization = _organizationService.addOrganization(parentOrganizationId, name, type, regionId, countryId, statusId, comments, site, addresses, emailAddresses, orgLabors, phones, websites, serviceContext); } else { // Update organization organization = _organizationService.updateOrganization(organizationId, parentOrganizationId, name, type, regionId, countryId, statusId, comments, !deleteLogo, logoBytes, site, addresses, emailAddresses, orgLabors, phones, websites, serviceContext); } // Layout set prototypes long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId"); long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId"); boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(actionRequest, "publicLayoutSetPrototypeLinkEnabled", publicLayoutSetPrototypeId > 0); boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(actionRequest, "privateLayoutSetPrototypeLinkEnabled", privateLayoutSetPrototypeId > 0); Group organizationGroup = organization.getGroup(); if (GroupPermissionUtil.contains(themeDisplay.getPermissionChecker(), organizationGroup, ActionKeys.UPDATE)) { SitesUtil.updateLayoutSetPrototypesLinks(organizationGroup, publicLayoutSetPrototypeId, privateLayoutSetPrototypeId, publicLayoutSetPrototypeLinkEnabled, privateLayoutSetPrototypeLinkEnabled); } // Reminder queries String reminderQueries = actionRequest.getParameter("reminderQueries"); PortletPreferences portletPreferences = organization.getPreferences(); LocalizationUtil.setLocalizedPreferencesValues(actionRequest, portletPreferences, "reminderQueries"); portletPreferences.setValue("reminderQueries", reminderQueries); portletPreferences.store(); return organization; }
From source file:com.liferay.webform.action.ConfigurationActionImpl.java
License:Open Source License
@Override public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { validateFields(actionRequest);/*from ww w . j av a 2 s . c om*/ if (!SessionErrors.isEmpty(actionRequest)) { return; } Locale defaultLocale = LocaleUtil.getDefault(); String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale); boolean updateFields = ParamUtil.getBoolean(actionRequest, "updateFields"); String portletResource = ParamUtil.getString(actionRequest, "portletResource"); PortletPreferences preferences = actionRequest.getPreferences(); LocalizationUtil.setLocalizedPreferencesValues(actionRequest, preferences, "title"); LocalizationUtil.setLocalizedPreferencesValues(actionRequest, preferences, "description"); if (updateFields) { int i = 1; String databaseTableName = WebFormUtil.getNewDatabaseTableName(portletResource); preferences.setValue("databaseTableName", databaseTableName); int[] formFieldsIndexes = StringUtil.split(ParamUtil.getString(actionRequest, "formFieldsIndexes"), 0); for (int formFieldsIndex : formFieldsIndexes) { Map<Locale, String> fieldLabelMap = LocalizationUtil.getLocalizationMap(actionRequest, "fieldLabel" + formFieldsIndex); if (Validator.isNull(fieldLabelMap.get(defaultLocale))) { continue; } String fieldType = ParamUtil.getString(actionRequest, "fieldType" + formFieldsIndex); boolean fieldOptional = ParamUtil.getBoolean(actionRequest, "fieldOptional" + formFieldsIndex); Map<Locale, String> fieldOptionsMap = LocalizationUtil.getLocalizationMap(actionRequest, "fieldOptions" + formFieldsIndex); String fieldValidationScript = ParamUtil.getString(actionRequest, "fieldValidationScript" + formFieldsIndex); String fieldValidationErrorMessage = ParamUtil.getString(actionRequest, "fieldValidationErrorMessage" + formFieldsIndex); if (Validator.isNotNull(fieldValidationScript) ^ Validator.isNotNull(fieldValidationErrorMessage)) { SessionErrors.add(actionRequest, "validationDefinitionInvalid" + i); } updateModifiedLocales("fieldLabel" + i, fieldLabelMap, preferences); updateModifiedLocales("fieldOptions" + i, fieldOptionsMap, preferences); preferences.setValue("fieldType" + i, fieldType); preferences.setValue("fieldOptional" + i, String.valueOf(fieldOptional)); preferences.setValue("fieldValidationScript" + i, fieldValidationScript); preferences.setValue("fieldValidationErrorMessage" + i, fieldValidationErrorMessage); i++; } if (!SessionErrors.isEmpty(actionRequest)) { return; } // Clear previous preferences that are now blank String fieldLabel = LocalizationUtil.getPreferencesValue(preferences, "fieldLabel" + i, defaultLanguageId); while (Validator.isNotNull(fieldLabel)) { Map<Locale, String> fieldLabelMap = LocalizationUtil.getLocalizationMap(actionRequest, "fieldLabel" + i); for (Locale locale : fieldLabelMap.keySet()) { String languageId = LocaleUtil.toLanguageId(locale); LocalizationUtil.setPreferencesValue(preferences, "fieldLabel" + i, languageId, StringPool.BLANK); LocalizationUtil.setPreferencesValue(preferences, "fieldOptions" + i, languageId, StringPool.BLANK); } preferences.setValue("fieldType" + i, StringPool.BLANK); preferences.setValue("fieldOptional" + i, StringPool.BLANK); preferences.setValue("fieldValidationScript" + i, StringPool.BLANK); preferences.setValue("fieldValidationErrorMessage" + i, StringPool.BLANK); i++; fieldLabel = LocalizationUtil.getPreferencesValue(preferences, "fieldLabel" + i, defaultLanguageId); } } if (SessionErrors.isEmpty(actionRequest)) { preferences.store(); } super.processAction(portletConfig, actionRequest, actionResponse); }