Example #1
0
  /**
   * Peforms the processing associated with this action.
   *
   * @param request the HttpServletRequest instance
   * @param response the HttpServletResponse instance
   * @return the name of the next view
   */
  public View process(HttpServletRequest request, HttpServletResponse response)
      throws ServletException {
    Blog blog = (Blog) getModel().get(Constants.BLOG_KEY);
    String email = request.getParameter("email");
    email = StringUtils.filterHTML(email);
    if (email != null && email.length() > 0) {
      blog.getEmailSubscriptionList().addEmailAddress(email);
      blog.info(email + " has subscribed to this blog.");

      getModel().put("email", email);
      return new SubscribedView();
    }

    return new SubscribeView();
  }
  /**
   * Peforms the processing associated with this action.
   *
   * @param request the HttpServletRequest instance
   * @param response the HttpServletResponse instance
   * @return the name of the next view
   */
  public View process(HttpServletRequest request, HttpServletResponse response)
      throws ServletException {
    Blog blog = (Blog) getModel().get(Constants.BLOG_KEY);
    String id = request.getParameter("entry");
    String confirm = request.getParameter("confirm");
    String submit = request.getParameter("submit");

    BlogService service = new BlogService();
    BlogEntry blogEntry = null;
    try {
      blogEntry = service.getBlogEntry(blog, id);
    } catch (BlogServiceException e) {
      throw new ServletException(e);
    }

    if (blogEntry == null) {
      return new NotFoundView();
    }

    if (submit.equals("Edit")) {
      return new ForwardView("/editBlogEntry.secureaction?entry=" + id);
    } else if (submit.equals("Publish") || submit.equals("Unpublish")) {
      getModel().put(Constants.BLOG_ENTRY_KEY, blogEntry);
      return new PublishBlogEntryView();
    } else if (submit.equals("Clone")) {
      return new ForwardView("/addBlogEntry.secureaction?entryToClone=" + blogEntry.getId());
    } else if (confirm != null && confirm.equals("true")) {
      if (submit.equalsIgnoreCase("Remove")) {
        try {
          service.removeBlogEntry(blogEntry);
          blog.info(
              "Blog entry \"" + StringUtils.transformHTML(blogEntry.getTitle()) + "\" removed.");
        } catch (BlogServiceException be) {
          throw new ServletException(be);
        }

        return new ForwardView("/viewHomePage.action");
      }
    }

    return new RedirectView(blogEntry.getLocalPermalink());
  }