Exemplo n.º 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);
    BlogEntry blogEntryToClone = null;

    String entryToClone = request.getParameter("entryToClone");
    if (entryToClone != null && entryToClone.length() > 0) {
      BlogService service = new BlogService();
      try {
        blogEntryToClone = service.getBlogEntry(blog, entryToClone);
      } catch (BlogServiceException e) {
        throw new ServletException(e);
      }
    }

    BlogEntry entry = new BlogEntry(blog);
    if (blogEntryToClone != null) {
      entry.setTitle(blogEntryToClone.getTitle());
      entry.setSubtitle(blogEntryToClone.getSubtitle());
      entry.setBody(blogEntryToClone.getBody());
      entry.setExcerpt(blogEntryToClone.getExcerpt());
      entry.setTimeZoneId(blogEntryToClone.getTimeZoneId());
      entry.setCommentsEnabled(blogEntryToClone.isCommentsEnabled());
      entry.setTrackBacksEnabled(blogEntryToClone.isTrackBacksEnabled());

      // copy the categories
      Iterator it = blogEntryToClone.getCategories().iterator();
      while (it.hasNext()) {
        entry.addCategory((Category) it.next());
      }

      entry.setTags(blogEntryToClone.getTags());
    } else {
      entry.setTitle("Title");
      entry.setBody("<p>\n\n</p>");
    }

    entry.setAuthor(SecurityUtils.getUsername());

    getModel().put(Constants.BLOG_ENTRY_KEY, entry);

    return new BlogEntryFormView();
  }
Exemplo n.º 2
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 {
    try {
      SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
      PebbleUserDetails currentUserDetails = SecurityUtils.getUserDetails();
      String password1 = request.getParameter("password1");
      String password2 = request.getParameter("password2");
      String submit = request.getParameter("submit");

      // can the user change their user details?
      if (!currentUserDetails.isDetailsUpdateable()) {
        return new ForbiddenView();
      }

      if (submit == null || submit.length() == 0) {
        return new ChangePasswordView();
      }

      ValidationContext validationContext = new ValidationContext();

      if (password1 == null || password1.length() == 0) {
        validationContext.addError("Password can not be empty");
      } else if (!password1.equals(password2)) {
        validationContext.addError("Passwords do not match");
      }

      if (!validationContext.hasErrors()) {
        realm.changePassword(currentUserDetails.getUsername(), password1);

        return new PasswordChangedView();
      }

      getModel().put("validationContext", validationContext);
      return new ChangePasswordView();
    } catch (SecurityRealmException e) {
      throw new ServletException(e);
    }
  }