private void initKeywords() { List<IPortletPreference> portletPreferences = this.portletDefinition.getPortletPreferences(); for (IPortletPreference pref : portletPreferences) { if (MARKETPLACE_KEYWORDS_PREF.equalsIgnoreCase(pref.getName())) { this.keywords = new ArrayList<String>(Arrays.asList(pref.getValues())); break; } } }
@Override public IPortletPreference apply(IPortletPreference newPreference) { if (newPreference == null) { return null; } final String name = newPreference.getName(); for (final IPortletPreference oldPreference : portletPreferences) { if (name.equals(oldPreference.getName())) { // Don't add the new preference, just replace the existing one when a match is // found oldPreference.setValues(newPreference.getValues()); oldPreference.setReadOnly(newPreference.isReadOnly()); return null; } } return newPreference; } }
@Test public void testNullSetValueValues() throws ReadOnlyException, ValidatorException, IOException { portletPreferences.setValues("key", null); portletPreferences.store(); assertEquals(1, this.storedPrefs.size()); final IPortletPreference pref = this.storedPrefs.get("key"); assertNotNull(pref); assertEquals("key", pref.getName()); assertNull(pref.getValues()); assertFalse(pref.isReadOnly()); }
@Override protected void loadTargetPortletPreferences( IPortletEntity portletEntity, Map<String, IPortletPreference> targetPortletPreferences) { final List<IPortletPreference> entityPreferences = portletEntity.getPortletPreferences(); for (final IPortletPreference preference : entityPreferences) { targetPortletPreferences.put(preference.getName(), preference); } }
@Override public String[] apply(IPortletPreference input) { return input.getValues(); } });
protected boolean isReadOnly(IPortletPreference portletPreference) { return portletPreference != null && portletPreference.isReadOnly(); }
@Test public void testNullEntryInValues() throws ReadOnlyException, ValidatorException, IOException { portletPreferences.setValues("key", new String[] {null}); portletPreferences.store(); assertEquals(1, this.storedPrefs.size()); final IPortletPreference pref = this.storedPrefs.get("key"); assertNotNull(pref); assertEquals("key", pref.getName()); assertArrayEquals(new String[] {null}, pref.getValues()); assertFalse(pref.isReadOnly()); }
@Override protected void loadTargetPortletPreferences( IPortletDefinition portletDefinition, Map<String, IPortletPreference> targetPortletPreferences) { final List<IPortletPreference> entityPreferences = portletDefinition.getPortletPreferences(); for (final IPortletPreference preference : entityPreferences) { targetPortletPreferences.put(preference.getName(), preference); } }
@Override public String[] apply(IPortletPreference input) { return input.getValues(); } });
protected boolean isReadOnly(IPortletPreference portletPreference) { return portletPreference != null && portletPreference.isReadOnly(); }
@Test public void testNullSetValueValue() throws ReadOnlyException, ValidatorException, IOException { portletPreferences.setValue("key", null); portletPreferences.store(); assertEquals(1, this.storedPrefs.size()); final IPortletPreference pref = this.storedPrefs.get("key"); assertNotNull(pref); assertEquals("key", pref.getName()); assertArrayEquals(new String[] {null}, pref.getValues()); assertFalse(pref.isReadOnly()); }
private void initShortURL() { List<IPortletPreference> portletPreferences = this.portletDefinition.getPortletPreferences(); for (IPortletPreference pref : portletPreferences) { if (MARKETPLACE_SHORT_LINK_PREF.equalsIgnoreCase(pref.getName()) && pref.getValues().length == 1) { setShortURL(pref.getValues()[0]); break; } } }
new LinkedHashMap<String, IPortletPreference>(); for (final IPortletPreference preference : this.portletPreferences) { oldPreferences.put(preference.getName(), preference); final String name = preference.getName(); existingPreference.setValues(preference.getValues()); existingPreference.setReadOnly(preference.isReadOnly()); this.portletPreferences.add(existingPreference);
@Override protected void loadTargetPortletPreferences( IPortletDefinition portletDefinition, Map<String, IPortletPreference> targetPortletPreferences) { final List<IPortletPreference> entityPreferences = portletDefinition.getPortletPreferences(); for (final IPortletPreference preference : entityPreferences) { targetPortletPreferences.put(preference.getName(), preference); } }
@Override public final String getValue(String key, String def) { final IPortletPreference portletPreference = this.getPortletPreference(key); if (portletPreference != null) { final String[] values = portletPreference.getValues(); if (values == null || values.length == 0) { return def; } return values[0]; } return def; }
@Override public final boolean isReadOnly(String key) { final IPortletPreference portletPreference = this.getPortletPreference(key); return portletPreference != null && portletPreference.isReadOnly(); }
@Test public void testSetUpdateExisting() throws ReadOnlyException, ValidatorException, IOException { addPref(basePrefs, "key", false, new String[] {"default"}); // Set a modified value portletPreferences.setValues("key", new String[] {"modified"}); // Initial store, check that correct stored map is created portletPreferences.store(); // Actually "store" the stored prefs this.targetPrefs = new LinkedHashMap<String, IPortletPreference>(this.storedPrefs); assertEquals(1, this.storedPrefs.size()); IPortletPreference pref = this.storedPrefs.get("key"); assertNotNull(pref); assertEquals("key", pref.getName()); assertArrayEquals(new String[] {"modified"}, pref.getValues()); assertFalse(pref.isReadOnly()); // Set a modified value portletPreferences.setValues("key", null); // Initial store, check that correct stored map is created portletPreferences.store(); // Actually "store" the stored prefs this.targetPrefs = new LinkedHashMap<String, IPortletPreference>(this.storedPrefs); assertEquals(1, this.storedPrefs.size()); pref = this.storedPrefs.get("key"); assertNotNull(pref); assertEquals("key", pref.getName()); assertArrayEquals(null, pref.getValues()); assertFalse(pref.isReadOnly()); }
private void initShortURL() { List<IPortletPreference> portletPreferences = this.portletDefinition.getPortletPreferences(); for (IPortletPreference pref : portletPreferences) { if (MARKETPLACE_SHORT_LINK_PREF.equalsIgnoreCase(pref.getName()) && pref.getValues().length == 1) { setShortURL(pref.getValues()[0]); break; } } }