List of usage examples for com.liferay.portal.kernel.util LocalizationUtil getPreferencesValue
public static String getPreferencesValue(PortletPreferences preferences, String key, String languageId)
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. j av a 2s .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.fmdp.webform.portlet.WebFormPortlet.java
License:Open Source License
protected void exportData(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); String portletId = PortalUtil.getPortletId(resourceRequest); PortletPermissionUtil.check(themeDisplay.getPermissionChecker(), themeDisplay.getPlid(), portletId, ActionKeys.CONFIGURATION);//from ww w.ja v a2s. c o m PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(resourceRequest); String databaseTableName = preferences.getValue("databaseTableName", StringPool.BLANK); String title = preferences.getValue("title", "no-title"); StringBundler sb = new StringBundler(); List<String> fieldLabels = new ArrayList<String>(); for (int i = 1; true; i++) { String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); String localizedfieldLabel = LocalizationUtil.getPreferencesValue(preferences, "fieldLabel" + i, themeDisplay.getLanguageId()); if (Validator.isNull(fieldLabel)) { break; } fieldLabels.add(fieldLabel); sb.append(getCSVFormattedValue(localizedfieldLabel)); sb.append(PortletPropsValues.CSV_SEPARATOR); } fieldLabels.add("email-from"); sb.append(getCSVFormattedValue("email-from")); sb.append(PortletPropsValues.CSV_SEPARATOR); fieldLabels.add("email-sent-on"); sb.append(getCSVFormattedValue("email-sent-on")); sb.append(PortletPropsValues.CSV_SEPARATOR); sb.setIndex(sb.index() - 1); sb.append(CharPool.NEW_LINE); if (Validator.isNotNull(databaseTableName)) { List<ExpandoRow> rows = ExpandoRowLocalServiceUtil.getRows(themeDisplay.getCompanyId(), WebFormUtil.class.getName(), databaseTableName, QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (ExpandoRow row : rows) { for (String fieldName : fieldLabels) { String data = ExpandoValueLocalServiceUtil.getData(themeDisplay.getCompanyId(), WebFormUtil.class.getName(), databaseTableName, fieldName, row.getClassPK(), StringPool.BLANK); sb.append(getCSVFormattedValue(data)); sb.append(PortletPropsValues.CSV_SEPARATOR); } sb.setIndex(sb.index() - 1); sb.append(CharPool.NEW_LINE); } } String fileName = title + ".csv"; byte[] bytes = sb.toString().getBytes(); String contentType = ContentTypes.APPLICATION_TEXT; PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileName, bytes, contentType); }
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 w ww.jav a 2 s .c o m 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); }
From source file:com.liferay.webform.portlet.WebFormPortlet.java
License:Open Source License
protected void exportData(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); String portletId = PortalUtil.getPortletId(resourceRequest); PortletPermissionUtil.check(themeDisplay.getPermissionChecker(), themeDisplay.getPlid(), portletId, ActionKeys.CONFIGURATION);//from ww w .j av a2 s . c o m PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(resourceRequest); String databaseTableName = preferences.getValue("databaseTableName", StringPool.BLANK); String title = preferences.getValue("title", "no-title"); StringBundler sb = new StringBundler(); List<String> fieldLabels = new ArrayList<String>(); for (int i = 1; true; i++) { String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); String localizedfieldLabel = LocalizationUtil.getPreferencesValue(preferences, "fieldLabel" + i, themeDisplay.getLanguageId()); if (Validator.isNull(fieldLabel)) { break; } fieldLabels.add(fieldLabel); sb.append(getCSVFormattedValue(localizedfieldLabel)); sb.append(PortletPropsValues.CSV_SEPARATOR); } sb.setIndex(sb.index() - 1); sb.append(CharPool.NEW_LINE); if (Validator.isNotNull(databaseTableName)) { List<ExpandoRow> rows = ExpandoRowLocalServiceUtil.getRows(themeDisplay.getCompanyId(), WebFormUtil.class.getName(), databaseTableName, QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (ExpandoRow row : rows) { for (String fieldName : fieldLabels) { String data = ExpandoValueLocalServiceUtil.getData(themeDisplay.getCompanyId(), WebFormUtil.class.getName(), databaseTableName, fieldName, row.getClassPK(), StringPool.BLANK); sb.append(getCSVFormattedValue(data)); sb.append(PortletPropsValues.CSV_SEPARATOR); } sb.setIndex(sb.index() - 1); sb.append(CharPool.NEW_LINE); } } String fileName = title + ".csv"; byte[] bytes = sb.toString().getBytes(); String contentType = ContentTypes.APPLICATION_TEXT; PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileName, bytes, contentType); }
From source file:org.gfbio.ContactFormToHelpdeskPortlet.java
License:Open Source License
protected void exportData(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); String portletId = PortalUtil.getPortletId(resourceRequest); PortletPermissionUtil.check(themeDisplay.getPermissionChecker(), themeDisplay.getPlid(), portletId, ActionKeys.CONFIGURATION);/*from w w w . j av a 2 s . co m*/ PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(resourceRequest); String databaseTableName = preferences.getValue("databaseTableName", StringPool.BLANK); String title = preferences.getValue("title", "no-title"); StringBuilder sb = new StringBuilder(); List<String> fieldLabels = new ArrayList<String>(); for (int i = 1; true; i++) { String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); String localizedfieldLabel = LocalizationUtil.getPreferencesValue(preferences, "fieldLabel" + i, themeDisplay.getLanguageId()); if (Validator.isNull(fieldLabel)) { break; } fieldLabels.add(fieldLabel); sb.append("\""); sb.append(localizedfieldLabel.replaceAll("\"", "\\\"")); sb.append("\";"); } sb.deleteCharAt(sb.length() - 1); sb.append("\n"); if (Validator.isNotNull(databaseTableName)) { List<ExpandoRow> rows = ExpandoRowLocalServiceUtil.getRows(themeDisplay.getCompanyId(), WebFormUtil.class.getName(), databaseTableName, QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (ExpandoRow row : rows) { for (String fieldName : fieldLabels) { String data = ExpandoValueLocalServiceUtil.getData(themeDisplay.getCompanyId(), WebFormUtil.class.getName(), databaseTableName, fieldName, row.getClassPK(), StringPool.BLANK); data = data.replaceAll("\"", "\\\""); sb.append("\""); sb.append(data); sb.append("\";"); } sb.deleteCharAt(sb.length() - 1); sb.append("\n"); } } String fileName = title + ".csv"; byte[] bytes = sb.toString().getBytes(); String contentType = ContentTypes.APPLICATION_TEXT; PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileName, bytes, contentType); }