public void processActionReset(String action,ActionRequest request, ActionResponse response) throws PortletException, IOException { // TODO: Check Role log.debug("Removing preferences...."); clearSession(request); PortletSession pSession = request.getPortletSession(true); PortletPreferences prefs = request.getPreferences(); try { prefs.reset("sakai.descriptor"); for (String element : fieldList) { prefs.reset("imsti."+element); prefs.reset("sakai:imsti."+element); } log.debug("Preference removed"); } catch (ReadOnlyException e) { setErrorMessage(request, rb.getString("error.modify.prefs")) ; return; } prefs.store(); // Go back to the main edit page pSession.setAttribute("sakai.view", "edit"); }
@Override public void store(final PortletPreferences preferences, final String key, final JournalArticle article) throws ReadOnlyException { String articleResourceUuid = null; String articleId = null; if (article != null) { try { articleResourceUuid = article.getArticleResourceUuid(); articleId = article.getArticleId(); } catch (final PortalException | SystemException e) { log.error("Could not load article resource id for article {}", article.getArticleId(), e); } } preferences.setValue(key + RESOURCE_UUID_SUFFIX, articleResourceUuid); preferences.setValue(key + ARTICLE_ID_SUFFIX, articleId); }
protected TestResult checkSetPreferenceSingleValue(PortletRequest request) { TestResult result = new TestResult(); result.setDescription("Ensure a single preference value can be set."); result.setSpecPLT("14.1"); PortletPreferences preferences = request.getPreferences(); try { preferences.setValue("TEST", "TEST_VALUE"); } catch (ReadOnlyException ex) { TestUtils.failOnException("Unable to set preference value.", ex, result); return result; } String value = preferences.getValue("TEST", DEF_VALUE); if (value != null && value.equals("TEST_VALUE")) { result.setReturnCode(TestResult.PASSED); } else { TestUtils.failOnAssertion("preference value", value, "TEST_VALUE", result); } return result; }
protected TestResult checkSetPreferenceNull(PortletRequest request) { TestResult result = new TestResult(); result.setDescription("Ensure a preference value can be set to null."); result.setSpecPLT("14.1"); PortletPreferences preferences = request.getPreferences(); try { preferences.setValue("TEST", null); } catch (ReadOnlyException ex) { TestUtils.failOnException("Unable to set preference value.", ex, result); return result; } String value = preferences.getValue("TEST", DEF_VALUE); // see PLUTO-609: behavioral change! if (null == value) { result.setReturnCode(TestResult.PASSED); } else { TestUtils.failOnAssertion("preference value", value, null, result); } return result; }
protected TestResult checkSetPreferencesReturnsFirst(PortletRequest request) { TestResult result = new TestResult(); result.setDescription("Ensure the first value set to a given " + "preference is returned first by PortletPreferences.getValue()."); result.setSpecPLT("14.1"); PortletPreferences preferences = request.getPreferences(); try { preferences.setValues("TEST", new String[] { "FIRST", "SECOND" }); } catch (ReadOnlyException ex) { TestUtils.failOnException("Unable to set preference values.", ex, result); return result; } String value = preferences.getValue("TEST", DEF_VALUE); if (value != null && value.equals("FIRST")) { result.setReturnCode(TestResult.PASSED); } else { TestUtils.failOnAssertion("preference value", value, "FIRST", result); } return result; }
public void setValues(String key, String... values) throws ReadOnlyException { if (isReadOnly(key)) { throw new ReadOnlyException(EXCEPTIONS.getString( "error.preference.readonly", key)); } if (values == null) { values = new String[0]; } PortletPreference pref = preferences.get(key); if (pref != null) { pref.setValues(values); } else { pref = new PortletPreferenceImpl(key, values); preferences.put(key, pref); } }
public void reset(String key) throws ReadOnlyException { // Read-only preferences cannot be reset. if (isReadOnly(key)) { throw new ReadOnlyException(EXCEPTIONS.getString( "error.preference.readonly", key)); } // Try to reset preference to the default values. PortletPreference p = defaultPreferences.get(key); if (p != null) { if (LOG.isTraceEnabled()) { LOG.trace("Resetting preference for key: " + key); } preferences.put(key,p.clone()); } // Remove preference if default values are not defined (PLT.14.1). else { if (LOG.isTraceEnabled()) { LOG.trace("Resetting preference to null for key: " + key); } preferences.remove(key); } }
public static PortletPreferences deleteVoiceCommand(ActionRequest request, String voiceCommand) throws PortalException, SystemException, ReadOnlyException, ValidatorException, IOException { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long plid = themeDisplay.getLayout().getPlid(); long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT; int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT; long companyId = themeDisplay.getCompanyId(); PortletPreferences preference = request.getPreferences(); Map<String, String[]> preferencesMap = new HashMap<String, String[]>(preference.getMap()); preferencesMap.remove(voiceCommand); PortletPreferencesLocalServiceUtil.deletePortletPreferences(ownerId, ownerType, plid, SpeechConstants.PORTLET_NAMESPACE); preference = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId, ownerType, plid, SpeechConstants.PORTLET_NAMESPACE); for (Map.Entry<String, String[]> entry : preferencesMap.entrySet()) { preference.setValue(entry.getKey(), entry.getValue()[0]); } preference.store(); return preference; }
/** * Resets or removes the value associated with the specified key. * <p/> * If this implementation supports stored defaults, and there is such * a default for the specified preference, the given key will be * reset to the stored default. * <p/> * If there is no default available the key will be removed. * * @param key to reset * @throws java.lang.IllegalArgumentException * if key is <code>null</code>. * @throws javax.portlet.ReadOnlyException * if this preference cannot be modified for this request */ public void reset(String key) throws ReadOnlyException { if (key == null) throw new IllegalArgumentException("key is NULL"); PersistencePreferenceAttribute ppa = (PersistencePreferenceAttribute) attributes.get(key); if (ppa != null) { if (ppa.isReadOnly()) throw new ReadOnlyException("PortletPreference is read-only!"); Preference defaultPref = (Preference) defaultPrefsMap.get(key); if (defaultPref != null) { Value[] defvals = defaultPref.getValue(); String[] vals = new String[defvals.length]; for (int i = 0; i < defvals.length; i++) { vals[i] = defvals[i].getContent(); } ppa.setAValues(vals); } else { attributes.remove(key); } } }
@Override public SearchResultsContainer search(PortletRequest request, PortletResponse response, String tabId, int pageOffset, boolean isLoadMore) throws ReadOnlyException, ValidatorException, IOException, SearchException { FlashlightSearchConfiguration config = this.readConfiguration(request.getPreferences()); Map<String, FlashlightSearchConfigurationTab> tabs = config.getTabs(); FacetedSearcher searcher = this.facetedSearcherManager.createFacetedSearcher(); LinkedHashMap<FlashlightSearchConfigurationTab, SearchPage> resultMap = new LinkedHashMap<>(tabs.size()); for(FlashlightSearchConfigurationTab tab : tabs.values()) { int pageSize; int loadMoreSize; if(tab.getId().equals(tabId)) { pageSize = tab.getFullPageSize(); } else { pageSize = tab.getPageSize(); } if(isLoadMore) { loadMoreSize = tab.getLoadMorePageSize(); } else { loadMoreSize = 0; } resultMap.put(tab, this.search(request, response, config, tab, searcher, pageOffset, pageSize, loadMoreSize)); } return new SearchResultsContainer(resultMap); }
@Override public void saveGlobalSettings(String adtUuid, boolean doSearchOnStartup, String doSearchOnStartupKeywords, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException { if(Validator.isNull(doSearchOnStartupKeywords)) { doSearchOnStartupKeywords = FlashlightSearchService.CONFIGURATION_DEFAULT_SEARCH_KEYWORDS; } preferences.setValue(CONF_KEY_ADT_UUID, adtUuid); preferences.setValue(CONF_KEY_DO_SEARCH_ON_STARTUP, Boolean.toString(doSearchOnStartup)); preferences.setValue(CONF_KEY_DO_SEARCH_ON_STARTUP_KEYWORDS, doSearchOnStartupKeywords); preferences.store(); }
@Override public void saveSearchFacetConfig(FlashlightSearchConfigurationTab configurationTab, SearchFacet searchFacet, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException { String tabId = configurationTab.getId(); String facetConfigKey = format(CONF_KEY_FORMAT_SEARCH_FACET, tabId, searchFacet.getClass().getName()); preferences.setValue(facetConfigKey, searchFacet.getData().toJSONString()); preferences.store(); }
@Override public void setValues(String key, String[] values) throws ReadOnlyException { Assert.notNull(key, "Key must not be null"); if (isReadOnly(key)) { throw new ReadOnlyException("Preference '" + key + "' is read-only"); } this.preferences.put(key, values); }
@Override public void reset(String key) throws ReadOnlyException { Assert.notNull(key, "Key must not be null"); if (isReadOnly(key)) { throw new ReadOnlyException("Preference '" + key + "' is read-only"); } this.preferences.remove(key); }
@Action public Response saveSettings(String enableStoreData,String invitationUrl) throws ReadOnlyException, IOException, ValidatorException { portletPreferences.setValue(ENABLE_STORE_DATA,enableStoreData); portletPreferences.setValue(INVITATION_URL,invitationUrl); portletPreferences.store(); return JuZExoInviteFriendFrontendApplication_.index().with(JuzuPortlet.PORTLET_MODE, PortletMode.VIEW); }
/** * Stores the values of this bean into the preferences and stays in the current portlet mode. */ public void store() { try { final PortletPreferences portletPreferences = getPortletPreferences(); store(portletPreferences); portletPreferences.store(); } catch (final ReadOnlyException | ValidatorException | IOException e) { log.error("Could not store portlet preferences", e); } }
@Override public void store(final PortletPreferences preferences, final String key, final E value) throws ReadOnlyException { if (value == null) { preferences.setValue(key, null); } else { preferences.reset(key); PreferenceFieldRegistry.store(preferences, key + '.', value); } }
@Override public void store(final PortletPreferences preferences, final String key, final Map<K, V> values) throws ReadOnlyException { int index = 0; if (values != null) { for (final Map.Entry<K, V> entry : values.entrySet()) { this.keyHandler.store(preferences, key + '.' + index + 'k', entry.getKey()); this.valueHandler.store(preferences, key + '.' + index + 'v', entry.getValue()); index++; } } preferences.setValue(key + ".length", String.valueOf(index)); }
@Override public void store(final PortletPreferences preferences, final String key, final Serializable value) throws ReadOnlyException { if (value == null) { preferences.setValue(key, null); } else { try { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); new ObjectOutputStream(buffer).writeObject(value); preferences.setValue(key, DatatypeConverter.printBase64Binary(buffer.toByteArray())); } catch (final IOException e) { log.error("Could not serialize object for preferences: " + value, e); } } }
@Override public void store(final PortletPreferences preferences, final String key, final Collection<E> values) throws ReadOnlyException { int index = 0; if (values != null) { for (final E element : values) { this.elementHandler.store(preferences, key + '.' + index, element); index++; } } preferences.setValue(key + ".length", String.valueOf(index)); }
private void initForm() { form = new Form<Void>("form") { private static final long serialVersionUID = 1L; @Override protected void onSubmit() { PortletPreferences prefs = UIUtils.getPortletPreferences(); HtmlStripper htmlStripper = new HtmlStripper(); try { prefs.setValue("titulo", tituloProjetoLei.getModelObject()); prefs.setValue("tituloDescricao", tituloDescricaoProjeto.getModelObject()); prefs.setValue("descricaoProjeto", htmlStripper.strip(descricaoProjeto.getModelObject())); prefs.setValue("habilitaPlugins", habilitaPlugins.getModelObject().toString()); prefs.setValue("habilitaSugestoes", habilitaSugestoes.getModelObject().toString()); info("Alterações realizadas com sucesso!"); getRequestCycle().setRequestTarget(new RedirectRequestTarget(viewUrl)); } catch (ReadOnlyException e) { error("Erro ao gravar alterações"); return; } try { prefs.store(); } catch (ValidatorException e) { error("Erro ao gravar alterações"); } catch (IOException e) { error("Erro ao gravar alterações"); } } }; add(form); }
public void setValues(String key, String[] values) throws ReadOnlyException { Assert.notNull(key, "Key must not be null"); if (isReadOnly(key)) { throw new ReadOnlyException("Preference '" + key + "' is read-only"); } this.preferences.put(key, values); }
public void reset(String key) throws ReadOnlyException { Assert.notNull(key, "Key must not be null"); if (isReadOnly(key)) { throw new ReadOnlyException("Preference '" + key + "' is read-only"); } this.preferences.remove(key); }
protected TestResult checkSetPreferenceMultiValues(PortletRequest request) { TestResult result = new TestResult(); result.setDescription("Ensure multiple preference values can be set."); result.setSpecPLT("14.1"); PortletPreferences preferences = request.getPreferences(); try { preferences.setValues("TEST", new String[] {"ONE", "ANOTHER"}); } catch (ReadOnlyException ex) { TestUtils.failOnException("Unable to set preference values.", ex, result); return result; } String[] values = preferences.getValues("TEST", new String[] { DEF_VALUE }); if (values != null && values.length == 2 && values[0].equals("ONE") && values[1].equals("ANOTHER")) { result.setReturnCode(TestResult.PASSED); } else if (values == null) { TestUtils.failOnAssertion("preference values", values, new String[] { "ONE", "ANOTHER" }, result); } else if (values.length != 2) { TestUtils.failOnAssertion("length of preference values", String.valueOf(values.length), String.valueOf(2), result); } else { TestUtils.failOnAssertion("preference values", values, new String[] { "ONE", "ANOTHER" }, result); } return result; }
public void setValue(String key, String value) throws ReadOnlyException { if (isReadOnly(key)) { throw new ReadOnlyException(EXCEPTIONS.getString( "error.preference.readonly", key)); } PortletPreference pref = preferences.get(key); String[] values = value == null ? new String[0] : new String[] { value }; if (pref != null) { pref.setValues(values); } else { pref = new PortletPreferenceImpl(key, values); preferences.put(key, pref); } }
public void saveMaximumRatings(SetOfOpinion tmpSetOfOpinionWithOnlyMaxValues, ActionRequest actionRequest) throws ReadOnlyException, ValidatorException, IOException { javax.portlet.PortletPreferences prefs = actionRequest.getPreferences(); if(tmpSetOfOpinionWithOnlyMaxValues.validateMaxValues()){ prefs.setValue("maximumRatingPerUser", Integer.toString(tmpSetOfOpinionWithOnlyMaxValues.getNumberOfMaximumScoresByUser())); prefs.setValue("maximumOfRatingPerSubtopic", Integer.toString(tmpSetOfOpinionWithOnlyMaxValues.getNumberOfMaximumScoreBySubtopic())); prefs.store(); } else { SessionErrors.add(actionRequest, "maximumsInputNotValid"); } }
@Override public FlashlightSearchConfiguration readConfiguration(PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException { return this.storageEngine.readConfiguration(preferences); }
@Override public void saveGlobalSettings(String adtUuid, boolean doSearchOnStartup, String doSearchOnStartupKeywords, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException { this.storageEngine.saveGlobalSettings(adtUuid, doSearchOnStartup, doSearchOnStartupKeywords, preferences); }
@Override public void saveConfigurationTab(FlashlightSearchConfigurationTab configurationTab, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException { this.storageEngine.saveConfigurationTab(configurationTab, preferences); }
@Override public void saveSearchFacetConfig(FlashlightSearchConfigurationTab configurationTab, SearchFacet searchFacet, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException { this.storageEngine.saveSearchFacetConfig(configurationTab, searchFacet, preferences); }
@Override public void deleteConfigurationTab(String tabId, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException { this.storageEngine.deleteConfigurationTab(tabId, preferences); }
@Override public void deleteConfigurationTab(String tabId, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException { // First, delete any reference to this tab List<String> tabIds = Arrays.asList(preferences.getValues(CONF_KEY_TABS, EMPTY_ARRAY)) .stream() .filter(tab -> !tab.equals(tabId)) .collect(Collectors.toList()); preferences.setValues(CONF_KEY_TABS, tabIds.toArray(new String[tabIds.size()])); // Then, flush out any singular value String assetTypeKey = format(CONF_KEY_FORMAT_ASSET_TYPE, tabId); String journalArticleViewTemplateKey = format(CONF_KEY_FORMAT_JOURNAL_ARTICLE_VIEW_TEMPLATE, tabId); String orderKey = format(CONF_KEY_FORMAT_ORDER, tabId); String pageSizeKey = format(CONF_KEY_FORMAT_PAGE_SIZE, tabId); String fullPageSizeKey = format(CONF_KEY_FORMAT_FULL_PAGE_SIZE, tabId); String loadMoreSizeKey = format(CONF_KEY_FORMAT_LOAD_MORE_PAGE_SIZE, tabId); String sortByKey = format(CONF_KEY_FORMAT_SORT_BY, tabId); String sortReverseKey = format(CONF_KEY_FORMAT_SORT_REVERSE, tabId); preferences.reset(orderKey); preferences.reset(assetTypeKey); preferences.reset(journalArticleViewTemplateKey); preferences.reset(pageSizeKey); preferences.reset(fullPageSizeKey); preferences.reset(loadMoreSizeKey); preferences.reset(sortByKey); preferences.reset(sortReverseKey); // Finally, flush out composed values Enumeration<String> prefKeys = preferences.getNames(); Pattern journalArticleTemplatesKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_JOURNAL_ARTICLE_TEMPLATES, tabId)); Pattern dlFileEntryTemplatesKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_DL_FILE_ENTRY_TYPE_TEMPLATES, tabId)); Pattern titleKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_TITLE, tabId)); Pattern searchFacetPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_SEARCH_FACET, tabId)); while(prefKeys.hasMoreElements()) { String key = prefKeys.nextElement(); boolean journalArticleTemplatesMatches = journalArticleTemplatesKeyPattern.matcher(key).matches(); boolean dlFileEntryTemplatesMatches = dlFileEntryTemplatesKeyPattern.matcher(key).matches(); boolean titleMatches = titleKeyPattern.matcher(key).matches(); boolean searchFacetMatches = searchFacetPattern.matcher(key).matches(); if(journalArticleTemplatesMatches || dlFileEntryTemplatesMatches || titleMatches || searchFacetMatches) { preferences.reset(key); } } preferences.store(); }
@Override public void setValue(String key, String value) throws ReadOnlyException { setValues(key, new String[] {value}); }
@Override public void store(final PortletPreferences preferences, final String key, final E value) throws ReadOnlyException { preferences.setValue(key, value == null ? null : value.name()); }