public String pasteNode(String pathOrigin, String pathSelected, int pasteType, int action)
      throws ExchangeException, RepositoryException {
    boolean move = false;
    if (action == Tree.ACTION_MOVE) {
      move = true;
    }
    String label = StringUtils.substringAfterLast(pathOrigin, "/"); // $NON-NLS-1$
    String slash = "/"; // $NON-NLS-1$
    if (pathSelected.equals("/")) { // $NON-NLS-1$
      slash = StringUtils.EMPTY;
    }
    String destination = pathSelected + slash + label;
    if (pasteType == Tree.PASTETYPE_SUB
        && action != Tree.ACTION_COPY
        && destination.equals(pathOrigin)) {
      // drag node to parent node: move to last position
      pasteType = Tree.PASTETYPE_LAST;
    }
    if (pasteType == Tree.PASTETYPE_SUB) {
      destination = pathSelected + slash + label;
      Content touchedContent = this.copyMoveNode(pathOrigin, destination, move);
      if (touchedContent == null) {
        return StringUtils.EMPTY;
      }
      return touchedContent.getHandle();

    } else if (pasteType == Tree.PASTETYPE_LAST) {
      // LAST only available for sorting inside the same directory
      try {
        Content touchedContent = getHierarchyManager().getContent(pathOrigin);
        return touchedContent.getHandle();
      } catch (RepositoryException re) {
        return StringUtils.EMPTY;
      }
    } else {
      try {
        // PASTETYPE_ABOVE | PASTETYPE_BELOW
        String nameSelected = StringUtils.substringAfterLast(pathSelected, "/"); // $NON-NLS-1$
        String nameOrigin = StringUtils.substringAfterLast(pathOrigin, "/"); // $NON-NLS-1$
        Content tomove = getHierarchyManager().getContent(pathOrigin);
        Content selected = getHierarchyManager().getContent(pathSelected);
        if (tomove.getParent().getUUID().equals(selected.getParent().getUUID())) {
          tomove.getParent().orderBefore(nameOrigin, nameSelected);
          tomove.getParent().save();
        } else {
          String newOrigin = selected.getParent().getHandle() + "/" + nameOrigin;
          getHierarchyManager().moveTo(pathOrigin, newOrigin);
          Content newNode = getHierarchyManager().getContent(newOrigin);
          if (pasteType == Tree.PASTETYPE_ABOVE) {
            newNode.getParent().orderBefore(nameOrigin, nameSelected);
          }
        }
        return tomove.getHandle();
      } catch (RepositoryException re) {
        re.printStackTrace();
        log.error("Problem when pasting node", re);
        return StringUtils.EMPTY;
      }
    }
  }
Пример #2
0
 protected void onRegister(Content node) {
   if (node.getHandle().endsWith("templates")) {
     log.info("Loading mail templates from node:" + node.getHandle());
     templates = listTemplatesFromRepository(node);
   } else if (node.getHandle().endsWith("smtp")) {
     log.info("Loading mail smptp settings from node:" + node.getHandle());
     initMailParameter(node);
   }
 }
  public String renameNode(String newLabel)
      throws AccessDeniedException, ExchangeException, PathNotFoundException, RepositoryException {
    String returnValue;
    String parentPath = StringUtils.substringBeforeLast(this.getPath(), "/"); // $NON-NLS-1$
    newLabel = Path.getValidatedLabel(newLabel);

    // don't rename if it uses the same name as the current
    if (this.getPath().endsWith("/" + newLabel)) {
      return newLabel;
    }

    String dest = parentPath + "/" + newLabel; // $NON-NLS-1$
    if (getHierarchyManager().isExist(dest)) {
      newLabel = Path.getUniqueLabel(getHierarchyManager(), parentPath, newLabel);
      dest = parentPath + "/" + newLabel; // $NON-NLS-1$
    }
    this.deActivateNode(this.getPath());

    if (log.isInfoEnabled()) {
      log.info("Moving node from " + this.getPath() + " to " + dest); // $NON-NLS-1$ //$NON-NLS-2$
    }
    if (getHierarchyManager().isNodeData(this.getPath())) {
      Content parentPage = getHierarchyManager().getContent(parentPath);
      NodeData newNodeData = parentPage.createNodeData(newLabel);
      NodeData existingNodeData = getHierarchyManager().getNodeData(this.getPath());
      newNodeData.setValue(existingNodeData.getString());
      existingNodeData.delete();
      dest = parentPath;
    } else {
      // we can't rename a node. we must move
      // we must place the node at the same position
      Content current = getHierarchyManager().getContent(this.getPath());
      Content parent = current.getParent();
      String placedBefore = null;
      for (Iterator iter = parent.getChildren(current.getNodeTypeName()).iterator();
          iter.hasNext(); ) {
        Content child = (Content) iter.next();
        if (child.getHandle().equals(this.getPath())) {
          if (iter.hasNext()) {
            child = (Content) iter.next();
            placedBefore = child.getName();
          }
        }
      }

      getHierarchyManager().moveTo(this.getPath(), dest);

      // now set at the same place as before
      if (placedBefore != null) {
        parent.orderBefore(newLabel, placedBefore);
      }
    }

    Content newPage = getHierarchyManager().getContent(dest);
    returnValue = newLabel;
    newPage.updateMetaData();
    newPage.save();

    return returnValue;
  }
Пример #4
0
  /**
   * Data is fetch into the repository to get the different parameters of the email
   *
   * @param id the id to find under the template section of the repository
   * @return a new <code>MgnlMail</code> instance, with the template set
   * @throws Exception if fails
   */
  public MgnlEmail getEmailFromTemplate(String id, Map map) throws Exception {
    if (id == null) {
      return new SimpleEmail(getSession());
    }
    HierarchyManager hm = ContentRepository.getHierarchyManager(ContentRepository.CONFIG);
    String nodeTemplatePath = templatePath + "/" + id;
    if (!hm.isExist(nodeTemplatePath)) {
      throw new MailException("Template:[" + id + "] configuration was not found in repository");
    }

    Content node = hm.getContent(nodeTemplatePath);

    // type
    NodeData typeNode = node.getNodeData(MAIL_TYPE);
    String type = typeNode.getValue().getString();

    MgnlEmail mail = getEmailFromType(type);

    // body
    NodeData bodyNode = node.getNodeData(MAIL_BODY);
    String body = bodyNode.getValue().getString();
    mail.setBodyFromResourceFile(body, map);

    // from
    NodeData fromNode = node.getNodeData(MAIL_FROM);
    String from = fromNode.getValue().getString();
    mail.setFrom(from);

    // subject
    NodeData subjectNode = node.getNodeData(MAIL_SUBJECT);
    String subject = subjectNode.getValue().getString();
    mail.setSubject(subject);

    String attachNodePath = node.getHandle() + "/" + MAIL_ATTACHMENT;
    if (hm.isExist(attachNodePath)) {
      Content attachments = hm.getContent(attachNodePath);
      Collection atts = attachments.getChildren();
      Iterator iter = atts.iterator();
      while (iter.hasNext()) {
        Content att = (Content) iter.next();
        String cid = att.getNodeData("cid").getString();
        String url = att.getNodeData("url").getString();
        MailAttachment a = new MailAttachment(new URL(url), cid);
        mail.addAttachment(a);
      }
    }

    // parameters
    mail.setParameters(map);

    return mail;
  }
Пример #5
0
  /**
   * List the templates stored in the repository
   *
   * @return <code>ArrayList</code> of <code>String</code> containing the template name
   */
  private ArrayList listTemplatesFromRepository(Content templatesNode) {
    ArrayList list = new ArrayList();
    this.templatePath = templatesNode.getHandle();
    try {
      Iterator iter = templatesNode.getChildren().iterator();
      while (iter.hasNext()) {
        Content temp = (Content) iter.next();
        String templateName = temp.getName();
        log.info("Loading template:" + templateName);
        list.add(templateName);
      }
    } catch (Exception e) {
      log.error("Error while listing templates", e);
    }

    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();
  }
Пример #7
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;
  }