private void deleteComment(HttpServletRequest request, Content websiteNode)
      throws RepositoryException {

    if (websiteNode.hasContent("comments")) {
      Content commentsNode = websiteNode.getContent("comments");
      commentsNode.delete(request.getParameter("id"));
      websiteNode.save();
    }
  }
  private List<Comment> readComments(Content websiteNode) throws RepositoryException {

    List<Comment> list = new ArrayList<Comment>();

    if (websiteNode.hasContent("comments")) {
      Content commentsNode = websiteNode.getContent("comments");
      Collection<Content> children = commentsNode.getChildren();
      for (Content commentNode : children) {
        Comment comment = new Comment();
        comment.setName(commentNode.getNodeData("name").getString());
        comment.setEmail(commentNode.getNodeData("email").getString());
        comment.setText(commentNode.getNodeData("text").getString());
        comment.setCreated(commentNode.getNodeData("created").getDate().getTime());
        comment.setId(commentNode.getName());
        list.add(comment);
      }
    }

    return list;
  }
  private void writeComment(HttpServletRequest request, Content websiteNode)
      throws RepositoryException {

    Content commentsNode;
    if (websiteNode.hasContent("comments")) {
      commentsNode = websiteNode.getContent("comments");
    } else {
      commentsNode = websiteNode.createContent("comments");
    }

    HierarchyManager hierarchyManager = MgnlContext.getHierarchyManager(ContentRepository.WEBSITE);
    String label = Path.getUniqueLabel(hierarchyManager, commentsNode.getHandle(), "comment");

    Content commentNode = commentsNode.createContent(label);
    commentNode.setNodeData("name", request.getParameter("name"));
    commentNode.setNodeData("email", request.getParameter("email"));
    commentNode.setNodeData("text", request.getParameter("text"));
    commentNode.setNodeData("created", Calendar.getInstance());

    websiteNode.save();
  }
Ejemplo n.º 4
0
  /**
   * Get an array of image URIs, one URI for each text string.
   *
   * @param The array of text strings.
   * @return An array of URIs pointing to the images.
   */
  private String[] getImageURIs(
      String[] subStrings, HttpServletRequest req, Content imageContentNode)
      throws PathNotFoundException, AccessDeniedException, RepositoryException,
          FileNotFoundException, IOException, FontFormatException {

    String[] imageURIs = new String[subStrings.length];
    for (int i = 0; i < subStrings.length; i++) {
      // Create a unique image node name
      String tmpImgNodeName =
          subStrings[i]
              + this.textBackColor
              + this.textFontColor
              + this.textFontFace
              + this.textFontSize;
      String imageNodeName = this.convertToSimpleString(tmpImgNodeName);
      // If the image node with this name does not exist, then create it.
      if (!imageContentNode.hasContent(imageNodeName)) {
        File image = createImage(subStrings[i]);

        // Create the node that will contain the image
        Content imageNode = imageContentNode.createContent(imageNodeName, ItemType.CONTENTNODE);

        this.createImageNode(image, imageNode);
      }
      // Save the URI for this image in the array
      String contextPath = req.getContextPath();
      String handle = imageContentNode.getHandle();
      String imageURI =
          contextPath
              + handle
              + "/"
              + imageNodeName
              + "/"
              + getFilename()
              + "."
              + PROPERTIES_EXTENSION_VALUE;
      imageURIs[i] = imageURI;
    }
    return imageURIs;
  }