Search in sources :

Example 1 with ValidatorException

use of javax.portlet.ValidatorException in project SimpleContentPortlet by Jasig.

the class PortletPreferencesContentDaoImplTest method testValidatorError.

@Test
public void testValidatorError() throws IOException {
    try {
        doThrow(new ValidatorException("", null)).when(preferences).store();
        contentDao.saveContent(request, content, null);
        Assert.fail("Should have thrown an exception");
    } catch (ValidatorException e) {
        Assert.fail("Validator exception should have been converted to a ContentPersistenceException");
    } catch (ContentPersistenceException e) {
    }
}
Also used : ValidatorException(javax.portlet.ValidatorException) ContentPersistenceException(org.jasig.portlet.cms.mvc.exception.ContentPersistenceException) Test(org.junit.Test)

Example 2 with ValidatorException

use of javax.portlet.ValidatorException 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);
    }
}
Also used : ValidatorException(javax.portlet.ValidatorException) PortletPreferences(javax.portlet.PortletPreferences) IOException(java.io.IOException) ReadOnlyException(javax.portlet.ReadOnlyException) ContentPersistenceException(org.jasig.portlet.cms.mvc.exception.ContentPersistenceException)

Aggregations

ValidatorException (javax.portlet.ValidatorException)2 ContentPersistenceException (org.jasig.portlet.cms.mvc.exception.ContentPersistenceException)2 IOException (java.io.IOException)1 PortletPreferences (javax.portlet.PortletPreferences)1 ReadOnlyException (javax.portlet.ReadOnlyException)1 Test (org.junit.Test)1