Exemple #1
0
  public void printComment(
      SimplePageComment comment,
      UIContainer tofill,
      boolean highlight,
      boolean anonymous,
      boolean showModifiers,
      CommentsViewParameters params,
      SimplePageItem commentsItem,
      SimplePage currentPage) {
    if (canEditPage && itemToPageowner != null && comment.getItemId() != lastTitle) {
      UIBranchContainer commentContainer = UIBranchContainer.make(tofill, "commentList:");
      UIOutput.make(
          commentContainer,
          "commentTitle",
          messageLocator
              .getMessage("simplepage.comments-grading")
              .replace("{}", itemToPageowner.get(comment.getItemId())));
      lastTitle = comment.getItemId();
    }

    // print title if this is a comment on a different page. Normally this
    // shold only happen for subpages of student pages
    String pageTitle = null;
    if (currentPage.getPageId() != comment.getPageId()) {
      SimplePage commentPage = simplePageBean.getPage(comment.getPageId());
      pageTitle = commentPage.getTitle();
    }

    UIBranchContainer commentContainer = UIBranchContainer.make(tofill, "commentList:");
    UIOutput.make(commentContainer, "commentDiv");
    if (highlight) commentContainer.decorate(new UIStyleDecorator("highlight-comment"));

    if (!filter && params.author != null && params.author.equals(comment.getAuthor())) {
      commentContainer.decorate(new UIStyleDecorator("backgroundHighlight"));
    }

    String author;

    if (!anonymous) {
      try {
        User user = UserDirectoryService.getUser(comment.getAuthor());
        author = user.getDisplayName();
      } catch (Exception ex) {
        author = messageLocator.getMessage("simplepage.comment-unknown-user");
        ex.printStackTrace();
      }
    } else {
      author = anonymousLookup.get(comment.getAuthor());

      if (comment.getAuthor().equals(owner)) {
        author = messageLocator.getMessage("simplepage.comment-author-owner");
      }

      if (author == null) author = "Anonymous User"; // Shouldn't ever occur

      if (simplePageBean.getEditPrivs() == 0) {
        try {
          User user = UserDirectoryService.getUser(comment.getAuthor());
          author += " (" + user.getDisplayName() + ")";
        } catch (Exception ex) {
          author += " (" + messageLocator.getMessage("simplepage.comment-unknown-user") + ")";
        }
      } else if (comment.getAuthor().equals(currentUserId)) {
        author += " (" + messageLocator.getMessage("simplepage.comment-you") + ")";
      }
    }

    UIOutput authorOutput = UIOutput.make(commentContainer, "userId", author);

    if (comment.getAuthor().equals(currentUserId)) {
      authorOutput.decorate(new UIStyleDecorator("specialCommenter"));
      authorOutput.decorate(new UIStyleDecorator("personalComment"));
    } else if (comment.getAuthor().equals(owner)) {
      authorOutput.decorate(new UIStyleDecorator("specialCommenter"));
      authorOutput.decorate(new UIStyleDecorator("ownerComment"));
    }

    if (pageTitle != null) UIOutput.make(commentContainer, "pageTitle", pageTitle);

    String timeDifference = getTimeDifference(comment.getTimePosted().getTime());

    UIOutput.make(commentContainer, "timePosted", timeDifference);

    if (showModifiers) {
      UIOutput.make(commentContainer, "deleteSpan");

      CommentsViewParameters eParams = (CommentsViewParameters) params.copy();
      eParams.placementId = params.placementId;
      eParams.deleteComment = comment.getUUID();
      eParams.pageId = params.pageId;
      eParams.siteId = params.siteId;

      UIInternalLink.make(commentContainer, "deleteCommentURL", eParams);
      UIOutput.make(commentContainer, "deleteComment")
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator.getMessage("simplepage.comment-delete").replace("{}", author)));
      UIOutput.make(commentContainer, "editComment")
          .decorate(
              new UIFreeAttributeDecorator("onclick", "edit($(this), " + comment.getId() + ");"))
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator.getMessage("simplepage.comment-edit").replace("{}", author)));

      if (!filter && simplePageBean.getEditPrivs() == 0 && commentsItem.getGradebookId() != null) {
        UIOutput.make(commentContainer, "gradingSpan");
        UIOutput.make(commentContainer, "commentsUUID", comment.getUUID());
        UIOutput.make(
            commentContainer,
            "commentPoints",
            (comment.getPoints() == null ? "" : String.valueOf(comment.getPoints())));
        UIOutput.make(commentContainer, "pointsBox")
            .decorate(
                new UIFreeAttributeDecorator(
                    "title",
                    messageLocator
                        .getMessage("simplepage.grade-for-student")
                        .replace("{}", author)));

        UIOutput.make(commentContainer, "maxpoints", " / " + commentsItem.getGradebookPoints());
        UIOutput.make(commentContainer, "authorUUID", comment.getAuthor());
      }
    }

    if (filter && simplePageBean.getEditPrivs() == 0) {
      UIOutput.make(commentContainer, "contextSpan");

      // because this is called via /faces, the full Sakai context is not set up.
      // in particular, UIInternalLink will generate the wrong thing. Thus we
      // make up a full URL ourselves.
      String pars =
          "/portal/tool/"
              + URLEncoder.encode(params.placementId)
              + "/ShowPage?path=none"
              + "&author="
              + URLEncoder.encode(comment.getAuthor());
      // Need to provide the item ID
      if (!params.studentContentItem && params.pageItemId != -1L) {
        pars += "&itemId=" + URLEncoder.encode(Long.toString(params.pageItemId));
      }
      UILink contextLink =
          UILink.make(
              commentContainer,
              "contextLink",
              messageLocator.getMessage("simplepage.show-context"),
              pars);
      if (itemToPageowner == null)
        contextLink.decorate(
            new UIFreeAttributeDecorator(
                "title",
                messageLocator
                    .getMessage("simplepage.context-link-title-1")
                    .replace("{}", author)));
      else
        contextLink.decorate(
            new UIFreeAttributeDecorator(
                "title",
                messageLocator
                    .getMessage("simplepage.context-link-title-2")
                    .replace("{1}", author)
                    .replace("{2}", itemToPageowner.get(comment.getItemId()))));
    }

    String dateString = df.format(comment.getTimePosted());

    if (!filter)
      UIOutput.make(commentContainer, "replyTo")
          .decorate(
              new UIFreeAttributeDecorator(
                  "onclick",
                  "replyToComment($(this),'"
                      + messageLocator
                          .getMessage("simplepage.in-reply-to")
                          .replace("{1}", author)
                          .replace("{2}", dateString)
                      + "')"))
          .decorate(
              new UIFreeAttributeDecorator(
                  "title",
                  messageLocator.getMessage("simplepage.comment-reply").replace("{}", author)));

    if (!comment.getHtml()) {
      UIOutput.make(commentContainer, "comment", comment.getComment());
    } else {
      UIVerbatim.make(commentContainer, "comment", comment.getComment());
    }
  }