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; }
/** * 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; }
/** * 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 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; }
/** * 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$ }