List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. From source file:com.love320.templateparser.util.ConfigBeanXML.java
License:Apache License
private static Document merger(Document document, Document doc) { Iterator documentIter = selectNodes(document, "/beans");// if (documentIter.hasNext()) {// Element documentElement = (Element) documentIter.next();//?Element Iterator dociter = selectNodes(doc, "/beans/bean");// while (dociter.hasNext()) {//?? Element docElement = (Element) dociter.next();//?Element deleteElement(document, docElement.attributeValue("id"));// documentElement.add(docElement.createCopy());//?, }/*from ww w. j a v a2s.co m*/ } return document; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.MMXChannelManager.java
License:Apache License
private boolean sendLastPublishedItem(PublishedItem publishedItem, NodeSubscription subNode, JID to) { if (!subNode.canSendPublicationEvent(publishedItem.getNode(), publishedItem)) { return false; }//w ww. ja v a2 s . c o m Node node = subNode.getNode(); Message notification = new Message(); Element event = notification.getElement().addElement("event", "http://jabber.org/protocol/pubsub#event"); Element items = event.addElement("items"); items.addAttribute("node", node.getNodeID()); Element item = items.addElement("item"); if (publishedItem.getNode().isItemRequired()) { item.addAttribute("id", publishedItem.getID()); } if (node.isPayloadDelivered() && publishedItem.getPayload() != null) { item.add(publishedItem.getPayload().createCopy()); } // Add a message body (if required) if (subNode.isIncludingBody()) { notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body")); } // Include date when published item was created notification.getElement().addElement("delay", "urn:xmpp:delay").addAttribute("stamp", XMPPDateTimeFormat.format(publishedItem.getCreationDate())); // Send the event notification to the subscriber node.getService().sendNotification(node, notification, to); // node.getService().sendNotification(node, notification, subNode.getJID()); return true; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.MMXChannelManager.java
License:Apache License
private boolean sendLastPublishedItems(List<PublishedItem> publishedItems, NodeSubscription subNode, JID to) { PublishedItem pubItem = publishedItems.get(0); if (!subNode.canSendPublicationEvent(pubItem.getNode(), pubItem)) { return false; }//from w w w . j a v a 2 s . c om Node node = subNode.getNode(); Message notification = new Message(); Element event = notification.getElement().addElement("event", "http://jabber.org/protocol/pubsub#event"); Element items = event.addElement("items"); items.addAttribute("node", node.getNodeID()); for (PublishedItem publishedItem : publishedItems) { Element item = items.addElement("item"); if (publishedItem.getNode().isItemRequired()) { item.addAttribute("id", publishedItem.getID()); } if (node.isPayloadDelivered() && publishedItem.getPayload() != null) { item.add(publishedItem.getPayload().createCopy()); } } // Add a message body (if required) if (subNode.isIncludingBody()) { notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body")); } // Include date when published item was created notification.getElement().addElement("delay", "urn:xmpp:delay").addAttribute("stamp", XMPPDateTimeFormat.format(pubItem.getCreationDate())); // Send the event notification to the subscriber node.getService().sendNotification(node, notification, to); // node.getService().sendNotification(node, notification, subNode.getJID()); return true; }
From source file:com.mg.framework.support.ui.UIProducer.java
License:Open Source License
private static Element includeMacros(Element parentElement, Element element, RuntimeMacrosLoader runtimeMacrosLoader) { Document macros = null;/*from ww w. j a v a2 s . co m*/ String runtimeMacros = element.attributeValue(RUNTIME_MACROS_NAME_ATTR); if (runtimeMacros == null) macros = loadMacros(element.attributeValue(MACROS_NAME_ATTR)); else macros = loadRuntimeMacros(runtimeMacros, runtimeMacrosLoader); String macrosType = macros.getRootElement().getQualifiedName(); if (EMPTY_MACROS.equals(macrosType)) return null; //handle special case for empty macros else if (WRAP_MACROS.equals(macrosType)) { //copy macros contents exclude root element List<Element> macrosChildElements = MiscUtils.convertUncheckedList(Element.class, macros.getRootElement().elements()); for (Element macrosChild : macrosChildElements) { // if (INCLUDE_TAG_NAME.equals(macrosChild.getQualifiedName())) // includeMacros(parentElement, macrosChild, runtimeMacrosLoader); // else { Element macrosElement = copyElement(macrosChild, runtimeMacrosLoader); if (macrosElement != null) parentElement.add(macrosElement); // } } return null; } else { if (INCLUDE_TAG_NAME.equals(macros.getRootElement().getQualifiedName())) return includeMacros(parentElement, macros.getRootElement(), runtimeMacrosLoader); return copyElement(macros.getRootElement(), runtimeMacrosLoader); //copy root element } }
From source file:com.mg.framework.support.ui.UIProducer.java
License:Open Source License
private static Element copyElement(Element element, RuntimeMacrosLoader runtimeMacrosLoader) { //if (INCLUDE_TAG_NAME.equals(element.getQualifiedName())) //return includeMacros(); Element result = DocumentHelper.createElement(element.getQualifiedName()); result.setAttributes(element.attributes()); List<Element> childElements = MiscUtils.convertUncheckedList(Element.class, element.elements()); for (Element childElement : childElements) { Element copy;/*from w w w . j av a2 s. c o m*/ if (childElement.getQualifiedName().equals(INCLUDE_TAG_NAME)) { copy = includeMacros(result, childElement, runtimeMacrosLoader); /*Document macros = null; String runtimeMacros = childElement.attributeValue(RUNTIME_MACROS_NAME_ATTR); if (runtimeMacros == null) macros = loadMacros(childElement.attributeValue(MACROS_NAME_ATTR)); else macros = loadRuntimeMacros(runtimeMacros, runtimeMacrosLoader); String macrosType = macros.getRootElement().getQualifiedName(); if (macrosType.equals(EMPTY_MACROS)) copy = null; //handle special case for empty macros else if (macrosType.equals(WRAP_MACROS)) { //copy macros contents exclude root element List<Element> macrosChildElements = MiscUtils.convertUncheckedList(Element.class, macros.getRootElement().elements()); for (Element macrosChild : macrosChildElements) { Element macrosElement = copyElement(macrosChild, runtimeMacrosLoader); if (macrosElement != null) result.add(macrosElement); } copy = null; } else copy = copyElement(macros.getRootElement(), runtimeMacrosLoader); //copy root element */ } else { copy = copyElement(childElement, runtimeMacrosLoader); } if (copy != null) result.add(copy); } return result; }
From source file:com.nokia.ant.Database.java
License:Open Source License
private void insertDocumentation(Element outNode, String commentText) throws IOException, DocumentException { if (commentText != null) { WikiModel wikiModel = new WikiModel("", ""); if (!commentText.contains("</pre>") && (commentText.contains("**") || commentText.contains("==") || commentText.contains("- -"))) { commentText = commentText.replace("**", "").replace("==", "").replace("- -", "").trim(); log("Warning: Comment code has invalid syntax: " + commentText, Project.MSG_WARN); }//from w ww . ja v a 2 s . c o m if (commentText.startsWith("-")) commentText = commentText.replace("-", ""); commentText = commentText.trim(); String commentTextCheck = commentText.replace("deprecated>", "").replace("tt>", "").replace("todo>", ""); if (commentTextCheck.contains(">") && !commentTextCheck.contains("</pre>")) log("Warning: Comment code needs <pre> tags around it: " + commentText, Project.MSG_WARN); commentText = filterTextNewlines(commentText); commentText = wikiModel.render(commentText); // If <deprecated> tag exists in the comment, then parse the // deprecated message. if (commentText.indexOf("<deprecated>") != -1) { int deprecatedMsgStart = commentText.indexOf("<deprecated>") + 20; int deprecatedMsgEnd = commentText.indexOf("</deprecated>"); // Add deprecated element. String deprecatedMsg = commentText.substring(deprecatedMsgStart, deprecatedMsgEnd); addTextElement(outNode, "deprecated", deprecatedMsg); // remove <deprecated> part from description field. int commentTextLength = commentText.length(); String documentationMsgStart = commentText.substring(1, deprecatedMsgStart - 20); String documentationMsgEnd = commentText.substring(deprecatedMsgEnd + 21, commentTextLength); String documentationMsg = documentationMsgStart.concat(documentationMsgEnd); commentText = documentationMsg.trim(); } } else { commentText = ""; } // Get the documentation element as a document String documentationText = "<documentation>" + commentText + "</documentation>"; Document docDoc = DocumentHelper.parseText(documentationText); outNode.add(docDoc.getRootElement()); log("HTML comment: " + commentText, Project.MSG_DEBUG); }
From source file:com.nokia.helium.diamonds.XMLMerger.java
License:Open Source License
/** * Merging two XML elements. It only keeps difference. * // ww w. j a v a2 s .co m * @param dest * @param src */ @SuppressWarnings("unchecked") protected void mergeNode(Element dest, Element src) { for (Iterator<Element> node = src.elements().iterator(); node.hasNext();) { Element element = node.next(); List<Element> ses = dest.elements(element.getName()); boolean add = true; for (Element se : ses) { if (areSame(se, element)) { log.debug("Element " + element.getName() + " already found in dest."); add = false; } } if (add) { log.debug("Adding node " + element.getName() + " to " + dest.getName()); dest.add(element.detach()); } else if (ses.size() > 0) { log.debug("Merging " + ses.get(0).getName() + " to " + element.getName()); mergeNode(ses.get(0), element); } } }
From source file:com.nokia.helium.internaldata.ant.listener.XMLRenderer.java
License:Open Source License
protected void insertDatabase(Element statistics) { if (database != null) { Element databaseElt = statistics.addElement("database"); databaseElt.add(database.getRootElement().detach()); }/*from ww w. j av a 2 s. co m*/ }
From source file:com.noterik.bart.fs.fscommand.dynamic.config.flash.java
License:Open Source License
private void handleIncludeExcludeNodes(Document conf, Document tmpConf) { List<Node> includeNodes = tmpConf .selectNodes("/fsxml/filesystem[@id='1']/*[@id and not(ends-with(@id,'_exclude'))]"); List<Node> excludeNodes = tmpConf.selectNodes("/fsxml/filesystem[@id='1']/*[ends-with(@id,'_exclude')]"); logger.debug("number of includeNodes = " + includeNodes.size()); for (int j = 0; j < includeNodes.size(); j++) { logger.debug(j + " = " + includeNodes.get(j).toString()); }/* www . j a va 2 s.co m*/ logger.debug("number of excludeNodes = " + excludeNodes.size()); for (int j = 0; j < excludeNodes.size(); j++) { logger.debug(j + " = " + excludeNodes.get(j).toString()); } Element base = (Element) conf.selectSingleNode("/fsxml/filesystem[@id='1']"); if (includeNodes != null) { for (int i = 0; i < includeNodes.size(); i++) { String nodename = includeNodes.get(i).getName(); String nodeid = includeNodes.get(i).valueOf("@id"); logger.debug("check if node exists " + nodename + " id " + nodeid); Node existingNode = base.selectSingleNode(nodename + "[@id='" + nodeid + "']"); if (existingNode != null) { logger.debug("node exists, replace"); List contentOfBase = base.content(); int index = contentOfBase.indexOf(existingNode); contentOfBase.set(index, includeNodes.get(i).detach()); } else { base.add(includeNodes.get(i).detach()); } } } if (excludeNodes != null) { logger.debug("handling exclude nodes for user"); for (int i = 0; i < excludeNodes.size(); i++) { logger.debug("handling exclude node nr " + i); String nodename = excludeNodes.get(i).getName(); String nodeid = excludeNodes.get(i).valueOf("@id"); nodeid = nodeid.substring(0, nodeid.lastIndexOf("_exclude")); logger.debug("about to exclude " + nodename + " with id " + nodeid); Node remove = base.selectSingleNode(nodename + "[@id='" + nodeid + "']"); if (remove != null) { logger.debug("node to exclude found, detach"); remove.detach(); } } } }
From source file:com.noterik.bart.fs.fscommand.dynamic.presentation.playout.flash.java
License:Open Source License
public synchronized String run(String uri, String xml) { logger.debug("start dynamic/presentation/playout/flash"); logger.debug("qpr url=" + uri); long timer_start = new Date().getTime(); Document returnXml = DocumentHelper.createDocument(); Element fsxml = returnXml.addElement("fsxml"); fsxml.addElement("properties"); String domain = URIParser.getDomainIdFromUri(uri); String user = URIParser.getUserIdFromUri(uri); String selectedplaylist = ""; Element handlerparams = null; int pos = xml.indexOf("<virtualpath>"); if (pos != -1) { selectedplaylist = xml.substring(pos + 13 + 14); pos = selectedplaylist.indexOf("</virtualpath>"); if (pos != -1) { selectedplaylist = selectedplaylist.substring(0, pos); try { handlerparams = (Element) DocumentHelper.parseText(xml).getRootElement(); } catch (Exception docerror) { logger.error("invalid parameters in xml"); }//from w w w .j a v a 2 s. c o m } else { logger.error("invalid virtual path"); } } if (uri.indexOf("/collection/") == -1 || uri.indexOf("/presentation") == -1) { return FSXMLBuilder.getErrorMessage("403", "No collection presentation found", "You have to supply a valid collection presentation", "http://teamelements.noterik.nl/team"); } config conf = new config(domain, user, selectedplaylist, handlerparams); Document presentationProperties = cache.get(uri); if (presentationProperties == null) { presentationProperties = FSXMLRequestHandler.instance().getNodeProperties(uri, false); if (presentationProperties == null) { return FSXMLBuilder.getErrorMessage("404", "Presentation not found", "You have to supply an existing presentation", "http://teamelements.noterik.nl/team"); } cache.put(uri, presentationProperties); } String collection = uri.substring(uri.indexOf("/collection/") + 12, uri.indexOf("/presentation/")); conf.setCollection(collection); logger.debug("presentation " + uri + " domain " + domain + " user " + user + " collection " + collection); Node presentationXml = getPresentation(uri); if (presentationXml != null) { fsxml.add(presentationXml); logger.debug("past presentation xml"); List<Element> videos = addVideos(presentationXml); for (int i = 0; i < videos.size(); i++) { fsxml.add(videos.get(i)); } logger.debug("past adding video(s)"); } Node presentationConfig = getPresentationConfig(uri, presentationXml, conf); if (presentationConfig != null) { fsxml.add(presentationConfig); logger.debug("past presentation config"); List<Element> players = addPlayer(presentationConfig); for (int j = 0; j < players.size(); j++) { fsxml.add(players.get(j)); } } logger.debug("past adding player(s)"); // moved the remapping of the presentation so we already have the video nodes. // Warning: This relies on the corrected presentation config (sponsor/user/collection level // don't move before the presentationconfig it's added to the document (dom4j issue) !! presentationXml = dynamicTransform((Element) presentationXml, conf, fsxml); Node collectionConfig = getCollectionConfig(uri, conf); if (collectionConfig != null) { fsxml.add(collectionConfig); } logger.debug("past collection config"); logger.debug("end dynamic/presentation/playout/flash"); long timer_end = new Date().getTime(); System.out.println("GENTIME=" + (timer_end - timer_start) + " CACHE AT " + cache.getPerformance() + "% req=" + cache.getTotalRequest() + " size=" + cache.getCacheSize() + " URI=" + uri); return fsxml.asXML(); }