public static Comment createComment(
      ObjectFactory objectFactory,
      URI baseUri,
      Document doc,
      com.xpn.xwiki.api.Object xwikiComment,
      XWiki xwikiApi,
      Boolean withPrettyNames) {
    Comment comment = objectFactory.createComment();
    comment.setId(xwikiComment.getNumber());

    com.xpn.xwiki.api.Property property = xwikiComment.getProperty("author");
    if (property != null) {
      comment.setAuthor((String) property.getValue());
      if (withPrettyNames) {
        comment.setAuthorName(xwikiApi.getUserName((String) property.getValue(), false));
      }
    }

    property = xwikiComment.getProperty("date");
    if (property != null) {
      Calendar calendar = Calendar.getInstance();
      calendar.setTime((Date) property.getValue());
      comment.setDate(calendar);
    }

    property = xwikiComment.getProperty("highlight");
    if (property != null) {
      comment.setHighlight((String) property.getValue());
    }

    property = xwikiComment.getProperty("comment");
    if (property != null) {
      comment.setText((String) property.getValue());
    }

    property = xwikiComment.getProperty("replyto");
    if (property != null) {
      comment.setReplyTo((Integer) property.getValue());
    }

    String pageUri = uri(baseUri, PageResource.class, doc.getWiki(), doc.getSpace(), doc.getName());
    Link pageLink = objectFactory.createLink();
    pageLink.setHref(pageUri);
    pageLink.setRel(Relations.PAGE);
    comment.getLinks().add(pageLink);

    return comment;
  }
  /* This method is used to fill the "common part" of a Page and a PageSummary */
  private static void fillPageSummary(
      PageSummary pageSummary,
      ObjectFactory objectFactory,
      URI baseUri,
      Document doc,
      boolean useVersion,
      XWiki xwikiApi,
      Boolean withPrettyNames)
      throws XWikiException {
    pageSummary.setWiki(doc.getWiki());
    pageSummary.setFullName(doc.getFullName());
    pageSummary.setId(doc.getPrefixedFullName());
    pageSummary.setSpace(doc.getSpace());
    pageSummary.setName(doc.getName());
    pageSummary.setTitle(doc.getDisplayTitle());
    pageSummary.setXwikiRelativeUrl(doc.getURL("view"));
    pageSummary.setXwikiAbsoluteUrl(doc.getExternalURL("view"));
    pageSummary.setTranslations(createTranslations(objectFactory, baseUri, doc));
    pageSummary.setSyntax(doc.getSyntaxId());
    pageSummary.setVersion(doc.getVersion());
    pageSummary.setAuthor(doc.getAuthor());
    if (withPrettyNames) {
      pageSummary.setAuthorName(xwikiApi.getUserName(doc.getAuthor(), false));
    }

    Document parent = Utils.getParentDocument(doc, xwikiApi);
    pageSummary.setParent(doc.getParent());
    // parentId must not be set if the parent document does not exist.
    if (parent != null && !parent.isNew()) {
      pageSummary.setParentId(parent.getPrefixedFullName());
    } else {
      pageSummary.setParentId("");
    }

    String spaceUri = uri(baseUri, SpaceResource.class, doc.getWiki(), doc.getSpace());
    Link spaceLink = objectFactory.createLink();
    spaceLink.setHref(spaceUri);
    spaceLink.setRel(Relations.SPACE);
    pageSummary.getLinks().add(spaceLink);

    if (parent != null) {
      String parentUri =
          uri(baseUri, PageResource.class, parent.getWiki(), parent.getSpace(), parent.getName());
      Link parentLink = objectFactory.createLink();
      parentLink.setHref(parentUri);
      parentLink.setRel(Relations.PARENT);
      pageSummary.getLinks().add(parentLink);
    }

    String historyUri =
        uri(baseUri, PageHistoryResource.class, doc.getWiki(), doc.getSpace(), doc.getName());
    Link historyLink = objectFactory.createLink();
    historyLink.setHref(historyUri);
    historyLink.setRel(Relations.HISTORY);
    pageSummary.getLinks().add(historyLink);

    if (!doc.getChildren().isEmpty()) {
      String pageChildrenUri =
          uri(baseUri, PageChildrenResource.class, doc.getWiki(), doc.getSpace(), doc.getName());
      Link pageChildrenLink = objectFactory.createLink();
      pageChildrenLink.setHref(pageChildrenUri);
      pageChildrenLink.setRel(Relations.CHILDREN);
      pageSummary.getLinks().add(pageChildrenLink);
    }

    if (!doc.getComments().isEmpty()) {
      String commentsUri;
      if (useVersion) {
        commentsUri =
            uri(
                baseUri,
                CommentsVersionResource.class,
                doc.getWiki(),
                doc.getSpace(),
                doc.getName(),
                doc.getVersion());
      } else {
        commentsUri =
            uri(baseUri, CommentsResource.class, doc.getWiki(), doc.getSpace(), doc.getName());
      }

      Link commentsLink = objectFactory.createLink();
      commentsLink.setHref(commentsUri);
      commentsLink.setRel(Relations.COMMENTS);
      pageSummary.getLinks().add(commentsLink);
    }

    if (!doc.getAttachmentList().isEmpty()) {
      String attachmentsUri;
      if (useVersion) {
        attachmentsUri =
            uri(
                baseUri,
                AttachmentsAtPageVersionResource.class,
                doc.getWiki(),
                doc.getSpace(),
                doc.getName(),
                doc.getVersion());
      } else {
        attachmentsUri =
            uri(baseUri, AttachmentsResource.class, doc.getWiki(), doc.getSpace(), doc.getName());
      }

      Link attachmentsLink = objectFactory.createLink();
      attachmentsLink.setHref(attachmentsUri);
      attachmentsLink.setRel(Relations.ATTACHMENTS);
      pageSummary.getLinks().add(attachmentsLink);
    }

    if (!doc.getxWikiObjects().keySet().isEmpty()) {
      String objectsUri;

      if (useVersion) {
        objectsUri =
            uri(
                baseUri,
                ObjectsAtPageVersionResource.class,
                doc.getWiki(),
                doc.getSpace(),
                doc.getName(),
                doc.getVersion());
      } else {
        objectsUri =
            uri(baseUri, ObjectsResource.class, doc.getWiki(), doc.getSpace(), doc.getName());
      }
      Link objectsLink = objectFactory.createLink();
      objectsLink.setHref(objectsUri);
      objectsLink.setRel(Relations.OBJECTS);
      pageSummary.getLinks().add(objectsLink);
    }

    com.xpn.xwiki.api.Object tagsObject = doc.getObject("XWiki.TagClass", 0);
    if (tagsObject != null) {
      if (tagsObject.getProperty("tags") != null) {
        String tagsUri =
            uri(baseUri, PageTagsResource.class, doc.getWiki(), doc.getSpace(), doc.getName());
        Link tagsLink = objectFactory.createLink();
        tagsLink.setHref(tagsUri);
        tagsLink.setRel(Relations.TAGS);
        pageSummary.getLinks().add(tagsLink);
      }
    }

    String syntaxesUri = uri(baseUri, SyntaxesResource.class);
    Link syntaxesLink = objectFactory.createLink();
    syntaxesLink.setHref(syntaxesUri);
    syntaxesLink.setRel(Relations.SYNTAXES);
    pageSummary.getLinks().add(syntaxesLink);
  }