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();
    }
  }
 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);
   }
 }
 /**
  * retrieve email address fo user
  *
  * @param userName
  * @return the email of the user as stored in the repository, if not found returns the parameter
  *     userName
  */
 public String getUserMail(String userName) {
   try {
     HierarchyManager hm = ContentRepository.getHierarchyManager(ContentRepository.USERS);
     Content user = hm.getContent(userName);
     if (user != null) {
       return user.getNodeData(EMAIL).getValue().getString();
     }
   } catch (Exception e) {
     log.error("can not get user email info.");
   }
   return userName;
 }
  /**
   * 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;
  }
 public void deleteNode(String parentPath, String label)
     throws ExchangeException, RepositoryException {
   Content parentNode = getHierarchyManager().getContent(parentPath);
   String path;
   if (!parentPath.equals("/")) { // $NON-NLS-1$
     path = parentPath + "/" + label; // $NON-NLS-1$
   } else {
     path = "/" + label; // $NON-NLS-1$
   }
   this.deActivateNode(path);
   parentNode.delete(label);
   parentNode.save();
 }
  /**
   * 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;
  }
 /** Method to init a stmp parameter */
 protected void initParam(Content configNode, String paramName, String defaultValue) {
   String value = configNode.getNodeData(paramName).getString();
   if (!StringUtils.isEmpty(value)) {
     log.info("Init param[{}] with value:[{}]", paramName, value);
     initParam(paramName, value);
   } else {
     log.info("Init param[{}] with value:[{}] (default)", paramName, defaultValue);
     initParam(paramName, defaultValue);
   }
 }
  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;
  }
Example #9
0
  /**
   * Reads listener config from the config repository and caches its content in to the hash table.
   */
  public static void load() {

    log.info("Config : loading Listener info"); // $NON-NLS-1$

    Collection children = Collections.EMPTY_LIST;

    try {

      Content startPage =
          ContentRepository.getHierarchyManager(ContentRepository.CONFIG).getContent(CONFIG_PAGE);
      Content configNode = startPage.getContent("IPConfig");
      children = configNode.getChildren(ItemType.CONTENTNODE); // $NON-NLS-1$
    } catch (RepositoryException re) {
      log.error("Config : Failed to load Listener info"); // $NON-NLS-1$
      log.error(re.getMessage(), re);
    }

    Listener.cachedContent.clear();
    Listener.cacheContent(children);
    log.info("Config : Listener info loaded"); // $NON-NLS-1$
  }
Example #10
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;
  }
Example #11
0
  /** Cache listener content from the config repository. */
  private static void cacheContent(Collection listeners) {

    Iterator ipList = listeners.iterator();
    while (ipList.hasNext()) {
      Content c = (Content) ipList.next();
      try {
        Map types = new Hashtable();
        Listener.cachedContent.put(c.getNodeData("IP").getString(), types); // $NON-NLS-1$
        Iterator it = c.getContent("Access").getChildren().iterator(); // $NON-NLS-1$
        while (it.hasNext()) {
          Content type = (Content) it.next();
          types.put(
              type.getNodeData("Method").getString().toLowerCase(),
              StringUtils.EMPTY); // $NON-NLS-1$
        }
      } catch (RepositoryException re) {
        log.error(
            "RepositoryException caught while loading listener configuration: " + re.getMessage(),
            re); //$NON-NLS-1$
      }
    }
  }
 public Content copyMoveNode(String source, String destination, boolean move)
     throws ExchangeException, RepositoryException {
   // todo: ??? generic -> RequestInterceptor.java
   if (getHierarchyManager().isExist(destination)) {
     String parentPath = StringUtils.substringBeforeLast(destination, "/"); // $NON-NLS-1$
     String label = StringUtils.substringAfterLast(destination, "/"); // $NON-NLS-1$
     label = Path.getUniqueLabel(getHierarchyManager(), parentPath, label);
     destination = parentPath + "/" + label; // $NON-NLS-1$
   }
   if (move) {
     if (destination.indexOf(source + "/") == 0) { // $NON-NLS-1$
       // todo: disable this possibility in javascript
       // move source into destinatin not possible
       return null;
     }
     this.deActivateNode(source);
     try {
       getHierarchyManager().moveTo(source, destination);
     } catch (Exception e) {
       // try to move below node data
       return null;
     }
   } else {
     // copy
     getHierarchyManager().copyTo(source, destination);
   }
   // SessionAccessControl.invalidateUser(this.getRequest());
   Content newContent = getHierarchyManager().getContent(destination);
   try {
     newContent.updateMetaData();
     newContent.getMetaData().setUnActivated();
   } catch (Exception e) {
     if (log.isDebugEnabled()) log.debug("Exception caught: " + e.getMessage(), e); // $NON-NLS-1$
   }
   newContent.save();
   return newContent;
 }
 @Override
 protected void execute(ForumManager forumManager, Content node) throws RepositoryException {
   forumManager.deleteMessage(node.getUUID());
 }
  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();
  }
  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;
      }
    }
  }
  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;
  }