Package net.sourceforge.pebble.domain

Examples of net.sourceforge.pebble.domain.Comment


   */
  public void testNoFollowAddedToComments() throws Exception {
    ContentDecoratorContext context = new ContentDecoratorContext();
    context.setView(ContentDecoratorContext.DETAIL_VIEW);

    Comment comment1 = blogEntry.createComment("title1", "body1", "author", "email", "website", "avatar", "127.0.0.1");
    blogEntry.addComment(comment1);
    Comment comment2 = blogEntry.createComment("title2", "body2", "author", "email", "website", "avatar", "127.0.0.1");
    blogEntry.addComment(comment2);

    comment1.setBody("<p>Here is some body.</p>");
    comment2.setBody("<p>Here is some body again.</p>");
    decorator.decorate(context, comment1);
    decorator.decorate(context, comment2);
    assertEquals("<p>Here is some body.</p>", comment1.getBody());
    assertEquals("<p>Here is some body again.</p>", comment2.getBody());

    comment1.setBody("<p>Here is a <a href=\"http://www.google.com\">a link</a>.</p>");
    comment2.setBody("<p>Here is a <a href=http://www.google.com>a link</a> again.</p>");
    decorator.decorate(context, comment1);
    decorator.decorate(context, comment2);
    assertEquals("<p>Here is a <a href=\"http://www.google.com\" rel=\"nofollow\">a link</a>.</p>", comment1.getBody());
    assertEquals("<p>Here is a <a href=http://www.google.com rel=\"nofollow\">a link</a> again.</p>", comment2.getBody());

    comment1.setBody("<p>Here is a <a href=\"ftp://www.google.com\">a link</a>.</p>");
    comment2.setBody("<p>Here is a <a href=\"mailto://www.google.com\">a link</a> again.</p>");
    decorator.decorate(context, comment1);
    decorator.decorate(context, comment2);
    assertEquals("<p>Here is a <a href=\"ftp://www.google.com\" rel=\"nofollow\">a link</a>.</p>", comment1.getBody());
    assertEquals("<p>Here is a <a href=\"mailto://www.google.com\" rel=\"nofollow\">a link</a> again.</p>", comment2.getBody());

    comment1.setBody("<p>Here is a <a href=\"http://www.google.com\">a link</a> and <a href=\"http://www.yahoo.com\">another</a>.</p>");
    comment2.setBody("<p>Here is some body again.</p>");
    decorator.decorate(context, comment1);
    decorator.decorate(context, comment2);
    assertEquals("<p>Here is a <a href=\"http://www.google.com\" rel=\"nofollow\">a link</a> and <a href=\"http://www.yahoo.com\" rel=\"nofollow\">another</a>.</p>", comment1.getBody());
    assertEquals("<p>Here is some body again.</p>", comment2.getBody());

    // test that we don't add an extra nofollow if one is present already
    comment1.setBody("<p>Here is a <a href=\"http://www.google.com\">a link</a> and <a href=\"http://www.yahoo.com\" rel=\"nofollow\">another</a>.</p>");
    decorator.decorate(context, comment1);
    decorator.decorate(context, comment2);
View Full Code Here


    BlogEntry blogEntry = new BlogEntry(blog);
    blogEntry.setDate(new Date(100000));
    blogEntry.setPublished(false);
    service.putBlogEntry(blogEntry);

    Comment comment = blogEntry.createComment("title", "body", "author", "email", "website", "avatar", "127.0.0.1");
    blogEntry.addComment(comment);
    service.putBlogEntry(blogEntry);

    String commentId = comment.getGuid();
    assertTrue(blog.getResponseIndex().getApprovedResponses().contains(commentId));

    // now execute the action
    request.setParameter("entry", blogEntry.getId());
    request.setParameter("publishDate", "as-is");
View Full Code Here

    BlogEntry blogEntry = new BlogEntry(blog);
    blogEntry.setDate(new Date(100000));
    blogEntry.setPublished(false);
    service.putBlogEntry(blogEntry);

    Comment comment = blogEntry.createComment("title", "body", "author", "email", "website", "avatar", "127.0.0.1");
    blogEntry.addComment(comment);
    service.putBlogEntry(blogEntry);

    String commentId = comment.getGuid();
    assertTrue(blog.getResponseIndex().getApprovedResponses().contains(commentId));

    // now execute the action
    request.setParameter("entry", blogEntry.getId());
    request.setParameter("publishDate", "now");
View Full Code Here

   * @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 blogEntry;
    Comment comment;

    String entry = request.getParameter("entry");
    String rememberMe = request.getParameter("rememberMe");
    String submitType = request.getParameter("submit");

    BlogService service = new BlogService();
    try {
      blogEntry = service.getBlogEntry(blog, entry);
    } catch (BlogServiceException e) {
      throw new ServletException(e);
    }
    if (blogEntry == null) {
      // just send back a 404 - this is probably somebody looking for a way
      // to send comment spam ;-)
      log.info("ignoring saveComment with no related blog entry (spam) from " + request.getRemoteAddr());
      return new NotFoundView();
    } else if (!blogEntry.isCommentsEnabled()) {
      return new CommentConfirmationView();
    }

    comment = createComment(request, blogEntry);
    ValidationContext context = validateComment(comment);

    // are we previewing or adding the comment?
    String previewButton = I18n.getMessage(blog, "comment.previewButton");

    ContentDecoratorContext decoratorContext = new ContentDecoratorContext();
    decoratorContext.setView(ContentDecoratorContext.DETAIL_VIEW);
    decoratorContext.setMedia(ContentDecoratorContext.HTML_PAGE);

    Comment decoratedComment = (Comment)comment.clone();
    blog.getContentDecoratorChain().decorate(decoratorContext, decoratedComment);
    getModel().put("decoratedComment", decoratedComment);
    getModel().put("undecoratedComment", comment);
    getModel().put("rememberMe", rememberMe);
    getModel().put(Constants.BLOG_ENTRY_KEY, blogEntry);
    getModel().put(Constants.COMMENT_KEY, comment);
    request.getSession().setAttribute("rememberMe", request.getParameter("rememberMe"));

    if (submitType == null || submitType.equalsIgnoreCase(previewButton) || context.hasErrors()) {
      return new CommentFormView();
    } else {
      CommentConfirmationStrategy strategy = blog.getCommentConfirmationStrategy();

      Comment clonedComment = (Comment)comment.clone();
      request.getSession().setAttribute(Constants.COMMENT_KEY, comment);

      if (strategy.confirmationRequired(clonedComment)) {
        strategy.setupConfirmation(request);
        return new ConfirmCommentView();
View Full Code Here

          if (!commentBodyLine.equals("-----")) {
            commentBody.append("<br />");
          }
        }

        Comment comment = entry.createComment(null, commentBody.toString(), commentAuthor, commentEmail, commentUrl, "", commentIpAddress, commentDate, State.APPROVED);
        entry.addComment(comment);
      } else if (line.equals("PING:")) {
        String pingTitle = reader.readLine().substring("TITLE: ".length());
        String pingUrl = reader.readLine().substring("URL: ".length());
        String pingIpAddress = reader.readLine().substring("IP: ".length());
View Full Code Here

   * Called when a comment has been added.
   *
   * @param event a CommentEvent instance
   */
  public void commentAdded(CommentEvent event) {
    Comment comment = event.getComment();
    if (comment.isApproved()) {
      sendNotification(comment);
    } else if (comment.isPending()) {
      sendApprovalRequest(comment);
    }
  }
View Full Code Here

   * Called when a comment has been approved.
   *
   * @param event a CommentEvent instance
   */
  public void commentApproved(CommentEvent event) {
    Comment comment = event.getComment();
    sendNotification(comment);
  }
View Full Code Here

    message += " | ";
    message += "<a href=\"" + blog.getUrl() + "removeEmailAddress.action?entry=" + comment.getBlogEntry().getId() + "&email=" + EMAIL_ADDRESS_TOKEN + "\">Opt-out</a>";

    Collection to = getEmailAddresses(comment);
    Iterator it = comment.getBlogEntry().getComments().iterator();
    Comment blogComment;
    while (it.hasNext()) {
      blogComment = (Comment) it.next();
      if (blogComment.getEmail() != null && blogComment.getEmail().length() > 0) {
        to.add(blogComment.getEmail());
      }
    }

    // now send personalized e-mails to the blog owner and everybody
    // that left a comment specifying their e-mail address
View Full Code Here

   */
  public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
    if (!SecurityUtils.isUserAuthorisedForBlogAsBlogContributor(blogEntry.getBlog())) {
      List comments = blogEntry.getComments();
      for (int i = comments.size()-1; i >= 0; i--) {
        Comment comment = (Comment)comments.get(i);
        if (!comment.isApproved()) {
          blogEntry.removeComment(comment.getId());
        }
      }

      List trackBacks = blogEntry.getTrackBacks();
      for (int i = trackBacks.size()-1; i >= 0; i--) {
View Full Code Here

   * Called when a comment has been added.
   *
   * @param event a CommentEvent instance
   */
  public void commentAdded(CommentEvent event) {
    Comment comment = event.getComment();
    AuditTrail.log("Comment \"" + comment.getTitle() + "\" from " + comment.getAuthor() + " (" + comment.getGuid() + ") added");
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.pebble.domain.Comment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.