public boolean execute(Context context) {
    BlogContext blogContext = (BlogContext) context;
    RenderRequest renderRequest = blogContext.getRenderRequest();

    PolicyCMServer cmServer = blogContext.getPolicyCMServer();

    ContentId blogId = blogContext.getBlogContentId();

    BlogForm blogForm = populateBlogForm(renderRequest);
    ModelWrite localModel = blogContext.getTopModel().getLocal();
    localModel.setAttribute("blogForm", blogForm);

    if (!(blogFormValidator.validate(blogContext, blogForm))) {
      return false;
    }

    BlogPolicy blog = null;
    try {
      blog = (BlogPolicy) cmServer.createContentVersion(blogId.getLatestCommittedVersionId());

      blog.setName(blogForm.getBlogName());
      blog.setPathSegmentString(blogForm.getBlogAddress());
      blog.setDescription(blogForm.getBlogDescription());

      cmServer.commitContent(blog);

      blogContext.getLocalModel().setAttribute("content", blog);

    } catch (UrlPathSegmentAlreadyExistsException e) {
      handleError(blogContext, blog, RenderControllerBlog.WEB_ALIAS_EXISTS_ERROR);
    } catch (InvalidUrlPathSegmentException e) {
      handleError(blogContext, blog, RenderControllerBlog.FIELD_REQUIRED_BLOG_ADDRESS);
    } catch (CMException e) {
      LOG.log(Level.WARNING, "Error while updating blog content.", e);
      handleError(blogContext, blog, RenderControllerBlog.INTERNAL_SERVER_ERROR);
    }
    return true;
  }
Esempio n. 2
0
 public void add(int index, ContentId contentId, ContentId referenceMetaDataId) {
   try {
     contentList.add(index, new ContentReference(contentId, referenceMetaDataId));
   } catch (CMException e) {
     throw new CMRuntimeException(
         "While adding "
             + contentId.getContentIdString()
             + " to "
             + this
             + ": "
             + e.getMessage(),
         e);
   }
 }
 @SuppressWarnings("deprecation")
 public boolean accept(ContentId contentId) {
   return contentId.getVersion() != VersionedContentId.META_DATA_VERSION;
 }