Exemplo n.º 1
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;
  }
Exemplo n.º 2
0
 /** 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;
  }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
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$
      }
    }
  }