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