use of javax.portlet.ReadOnlyException in project SimpleContentPortlet by Jasig.
the class PortletPreferencesContentDaoImplTest method testReadOnlyError.
@Test
public void testReadOnlyError() {
try {
doThrow(new ReadOnlyException("")).when(preferences).setValue(PortletPreferencesContentDaoImpl.CONTENT_KEY, content);
contentDao.saveContent(request, content, null);
Assert.fail("Should have thrown an exception");
} catch (ReadOnlyException e) {
Assert.fail("Read-only exception should have been converted to a ContentPersistenceException");
} catch (ContentPersistenceException e) {
}
}
use of javax.portlet.ReadOnlyException in project SimpleContentPortlet by Jasig.
the class PortletPreferencesContentDaoImpl method saveContent.
/*
* (non-Javadoc)
* @see org.jasig.portlet.cms.service.dao.IContentDao#saveContent(javax.portlet.ActionRequest, java.lang.String, java.lang.String)
*/
public void saveContent(ActionRequest request, String content, String localeKey) {
try {
PortletPreferences preferences = request.getPreferences();
if (StringUtils.isNotBlank(localeKey)) {
preferences.setValue(getLocaleSpecificKey(localeKey), content);
} else {
preferences.setValue(CONTENT_KEY, content);
}
preferences.store();
} catch (ReadOnlyException e) {
throw new ContentPersistenceException("Failed to save read-only preference", e);
} catch (ValidatorException e) {
throw new ContentPersistenceException("Portlet preferences validation error while attempting to persist portlet content", e);
} catch (IOException e) {
throw new ContentPersistenceException("IO error while attempting to persist portlet content", e);
}
}
use of javax.portlet.ReadOnlyException in project uPortal by Jasig.
the class AbstractPortletPreferencesImpl method setValues.
@Override
public final void setValues(String key, String[] values) throws ReadOnlyException {
Assert.notNull(key, "Preference Key cannot be null");
final Map<String, IPortletPreference> targetPortletPreferences = this.getTargetPortletPreferences();
// Check if there is a base preference for the key
final Map<String, IPortletPreference> basePortletPreferences = this.getBasePortletPreferences();
final IPortletPreference basePreference = basePortletPreferences.get(key);
if (basePreference != null) {
if (this.isReadOnly(basePreference)) {
throw new ReadOnlyException("Preference '" + key + "' is read only");
}
// if the set value matches base value, delete any target pref
if (Arrays.equals(values, basePreference.getValues())) {
this.reset(key);
return;
}
}
IPortletPreference portletPreference = targetPortletPreferences.get(key);
// No target preference exists yet, create it and then update the composite map
if (portletPreference == null) {
portletPreference = new PortletPreferenceImpl(key, false, values != null ? values.clone() : null);
targetPortletPreferences.put(key, portletPreference);
final Map<String, IPortletPreference> compositePortletPreferences = this.getCompositePortletPreferences();
compositePortletPreferences.put(key, portletPreference);
this.modified = true;
} else // Update the existing preference if the values array is different
if (!Arrays.equals(values, portletPreference.getValues())) {
portletPreference.setValues(values != null ? values.clone() : null);
this.modified = true;
}
}
use of javax.portlet.ReadOnlyException in project uPortal by Jasig.
the class AbstractPortletPreferencesImpl method reset.
@Override
public final void reset(String key) throws ReadOnlyException {
final Map<String, IPortletPreference> basePortletPreferences = this.getBasePortletPreferences();
final IPortletPreference basePreference = basePortletPreferences.get(key);
if (this.isReadOnly(basePreference)) {
throw new ReadOnlyException("Preference '" + key + "' is read only");
}
final Map<String, IPortletPreference> targetPortletPreferences = this.getTargetPortletPreferences();
final IPortletPreference removed = targetPortletPreferences.remove(key);
// There was a target preference with that key, update the composite preferences map
if (removed != null) {
final Map<String, IPortletPreference> compositePortletPreferences = this.getCompositePortletPreferences();
if (basePreference != null) {
compositePortletPreferences.put(key, basePreference);
} else {
compositePortletPreferences.remove(key);
}
this.modified = true;
}
}
Aggregations