Java Code Examples for org.dom4j.Element#createCopy()
The following examples show how to use
org.dom4j.Element#createCopy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JFrameEditableParameters.java From mts with GNU General Public License v3.0 | 6 votes |
/** * Returns the elements concerned by the key (node selected in the tree) * * @param key - TreePath in string format * @return */ private List<Element> getEltsForTable(String key) { if (key == null) return this.elements; if (key.contains("[root,")) key = key.substring(7, key.length()-1); // 7 => '[root, ' else key = key.substring(1, key.length()-1); key = key.replaceAll(", ", "."); List<Element> dispElts = new LinkedList<Element>(); for (Element e:this.elements) { if (e.attributeValue("name").contains(".")) { if (e.attributeValue("name").startsWith("["+key+".")) { Element elt = e.createCopy(); elt.attribute("name").setValue(e.attributeValue("name").substring(key.length()+2, e.attributeValue("name").length()-1)); dispElts.add(elt); } } else dispElts.add(e.createCopy()); } return dispElts; }
Example 2
Source File: TraceEvent.java From pega-tracerviewer with Apache License 2.0 | 6 votes |
protected Element createElement(String newName, Element element, String elementName) { Element newElement = null; String targetName = newName; if (element != null) { if ((newName == null) || ("".equals(newName))) { targetName = element.getName(); } newElement = element.createCopy(); newElement.addAttribute("name", targetName); } else { if ((elementName != null) && (!"".equals(elementName))) { DocumentFactory factory = DocumentFactory.getInstance(); newElement = factory.createElement(elementName); newElement.addAttribute("name", targetName); } } return newElement; }
Example 3
Source File: PubSubEngine.java From Openfire with Apache License 2.0 | 6 votes |
private void getNodeConfiguration(PubSubService service, IQ iq, Element childElement, String nodeID) { Node node = service.getNode(nodeID); if (node == null) { // Node does not exist. Return item-not-found error sendErrorPacket(iq, PacketError.Condition.item_not_found, null); return; } if (!node.isAdmin(iq.getFrom())) { // Requesting entity is prohibited from configuring this node. Return forbidden error sendErrorPacket(iq, PacketError.Condition.forbidden, null); return; } // Return data form containing node configuration to the owner IQ reply = IQ.createResultIQ(iq); Element replyChildElement = childElement.createCopy(); reply.setChildElement(replyChildElement); replyChildElement.element("configure").add(node.getConfigurationForm().getElement()); router.route(reply); }
Example 4
Source File: PubSubEngine.java From Openfire with Apache License 2.0 | 6 votes |
private void getDefaultNodeConfiguration(PubSubService service, IQ iq, Element childElement, Element defaultElement) { String type = defaultElement.attributeValue("type"); type = type == null ? "leaf" : type; boolean isLeafType = "leaf".equals(type); DefaultNodeConfiguration config = service.getDefaultNodeConfiguration(isLeafType); if (config == null) { // Service does not support the requested node type so return an error Element pubsubError = DocumentHelper.createElement( QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors")); pubsubError.addAttribute("feature", isLeafType ? "leaf" : "collections"); sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError); return; } // Return data form containing default node configuration IQ reply = IQ.createResultIQ(iq); Element replyChildElement = childElement.createCopy(); reply.setChildElement(replyChildElement); replyChildElement.element("default").add(config.getConfigurationForm().getElement()); router.route(reply); }
Example 5
Source File: DefaultXmlCodecWalker.java From onos with Apache License 2.0 | 6 votes |
@Override public void walk(XmlListener listener, Element element, Element rootElement) { try { Element newElement = element.createCopy(); newElement.remove(element.getNamespace()); listener.enterXmlElement(element, getElementType(newElement), rootElement); if (element.hasContent() && !element.isTextOnly()) { for (Iterator i = element.elementIterator(); i.hasNext();) { Element childElement = (Element) i.next(); walk(listener, childElement, rootElement); } } listener.exitXmlElement(element, getElementType(element), rootElement); } catch (Exception e) { log.error("Exception occurred when walk xml element: {}", element); } }
Example 6
Source File: JUnitReportGenerator.java From gocd with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Document doc = new SAXReader().read(new FileInputStream(new File("/home/cruise/sample_junit.xml"))); Element suite = (Element) doc.selectSingleNode("//testsuite"); Element rootElement = doc.getRootElement(); for (int i = 0; i < 50000; i++) { Element copy = suite.createCopy(); setAttr(i, copy, "name"); setAttr(i, copy, "hostname"); List<Element> elements = copy.selectNodes(".//testcase"); for (Element element : elements) { setAttr(i, element, "classname"); setAttr(i, element, "name"); } rootElement.add(copy); } FileUtils.writeStringToFile(new File("/tmp/repo/imagine.xml"), doc.asXML(), UTF_8); }
Example 7
Source File: XMLElementRTPFLOWParser.java From mts with GNU General Public License v3.0 | 5 votes |
public List<Element> replace(Element element, ParameterPool parameterPool) throws Exception { List<Element> result = new LinkedList(); //do classic replacement of attribute and save it in result Element newElement = element.createCopy(); result.add(newElement); List<Attribute> attributes = newElement.attributes(); for (Attribute attribute : attributes) { if (!attribute.getName().equalsIgnoreCase("timestamp") && !attribute.getName().equalsIgnoreCase("seqnum") && !attribute.getName().equalsIgnoreCase("deltaTime") && !attribute.getName().equalsIgnoreCase("mark")) { String value = attribute.getValue(); LinkedList<String> parsedValue = parameterPool.parse(value); if (parsedValue.size() != 1) { throw new ExecutionException("Invalid size of variables in attribute " + value); } attribute.setValue(parsedValue.getFirst()); } } return result; }
Example 8
Source File: XMLTree.java From mts with GNU General Public License v3.0 | 5 votes |
public XMLTree(Element root, boolean duplicate) { elementsOrder = new LinkedList<Element>(); elementsMap = new HashMap<Element, List<Element>>(); lock = new ReentrantLock(); if (duplicate) { this.root = root.createCopy(); } else { this.root = root; } }
Example 9
Source File: XMLElementDefaultParser.java From mts with GNU General Public License v3.0 | 5 votes |
public List<Element> replace(Element element, ParameterPool parameterPool) throws Exception { List<Element> list = new LinkedList<Element>(); Element newElement = element.createCopy(); list.add(newElement); List<Attribute> attributes = newElement.attributes(); for (Attribute attribute : attributes) { String value = attribute.getValue(); LinkedList<String> parsedValue = parameterPool.parse(value); if (parsedValue.size() > 1) { throw new ExecutionException("Invalid size of variables in attribute " + value); } if (parsedValue.size() == 1) { attribute.setValue(parsedValue.getFirst()); } else { attribute.setValue(null); } } return list; }
Example 10
Source File: PubSubEngine.java From Openfire with Apache License 2.0 | 5 votes |
private void getAffiliations(PubSubService service, IQ iq, Element childElement) { // TODO Assuming that owner is the bare JID (as defined in the JEP). This can be replaced with an explicit owner specified in the packet JID owner = iq.getFrom().asBareJID(); // Collect affiliations of owner for all nodes at the service Collection<NodeAffiliate> affiliations = new ArrayList<>(); for (Node node : service.getNodes()) { NodeAffiliate nodeAffiliate = node.getAffiliate(owner); if (nodeAffiliate != null) { affiliations.add(nodeAffiliate); } } // Create reply to send IQ reply = IQ.createResultIQ(iq); Element replyChildElement = childElement.createCopy(); reply.setChildElement(replyChildElement); if (affiliations.isEmpty()) { // User does not have any affiliation or subscription with the pubsub service reply.setError(PacketError.Condition.item_not_found); } else { Element affiliationsElement = replyChildElement.element("affiliations"); // Add information about affiliations without subscriptions for (NodeAffiliate affiliate : affiliations) { Element affiliateElement = affiliationsElement.addElement("affiliation"); // Do not include the node id when node is the root collection node if (!affiliate.getNode().isRootCollectionNode()) { affiliateElement.addAttribute("node", affiliate.getNode().getUniqueIdentifier().getNodeId()); } affiliateElement.addAttribute("jid", affiliate.getJID().toString()); affiliateElement.addAttribute("affiliation", affiliate.getAffiliation().name()); } } // Send reply router.route(reply); }
Example 11
Source File: XmppWebSocket.java From Openfire with Apache License 2.0 | 5 votes |
private void sendPacketError(Element stanza, PacketError.Condition condition) { Element reply = stanza.createCopy(); reply.addAttribute("type", "error"); reply.addAttribute("to", stanza.attributeValue("from")); reply.addAttribute("from", stanza.attributeValue("to")); reply.add(new PacketError(condition).getElement()); deliver(reply.asXML()); }
Example 12
Source File: IQPEPHandler.java From Openfire with Apache License 2.0 | 5 votes |
/** * Implements UserItemsProvider, adding PEP related items to a disco#items * result. */ @Override public Iterator<Element> getUserItems(String name, JID senderJID) { ArrayList<Element> items = new ArrayList<>(); JID recipientJID = XMPPServer.getInstance().createJID(name, null, true).asBareJID(); PEPService pepService = pepServiceManager.getPEPService(recipientJID, false); if (pepService != null) { CollectionNode rootNode = pepService.getRootCollectionNode(); Element defaultItem = DocumentHelper.createElement("item"); defaultItem.addAttribute("jid", recipientJID.toString()); for (Node node : pepService.getNodes()) { // Do not include the root node as an item element. if (node == rootNode) { continue; } AccessModel accessModel = node.getAccessModel(); if (accessModel.canAccessItems(node, senderJID, recipientJID)) { Element item = defaultItem.createCopy(); item.addAttribute("node", node.getUniqueIdentifier().getNodeId()); items.add(item); } } } return items.iterator(); }
Example 13
Source File: PrivacyItem.java From Openfire with Apache License 2.0 | 4 votes |
PrivacyItem(Element itemElement) { this.allow = "allow".equals(itemElement.attributeValue("action")); this.order = Integer.parseInt(itemElement.attributeValue("order")); String typeAttribute = itemElement.attributeValue("type"); if (typeAttribute != null) { this.type = Type.valueOf(typeAttribute); // Decode the proper value based on the rule type String value = itemElement.attributeValue("value"); if (type == Type.jid) { // Decode the specified JID this.jidValue = new JID(value); } else if (type == Type.subscription) { // Decode the specified subscription type if ("both".equals(value)) { this.subscriptionValue = RosterItem.SUB_BOTH; } else if ("to".equals(value)) { this.subscriptionValue = RosterItem.SUB_TO; } else if ("from".equals(value)) { this.subscriptionValue = RosterItem.SUB_FROM; } else { this.subscriptionValue = RosterItem.SUB_NONE; } } else { // Decode the specified group name this.groupValue = value; } } // Set what type of stanzas should be filters (i.e. blocked or allowed) this.filterIQ = itemElement.element("iq") != null; this.filterMessage = itemElement.element("message") != null; this.filterPresence_in = itemElement.element("presence-in") != null; this.filterPresence_out = itemElement.element("presence-out") != null; if (!filterIQ && !filterMessage && !filterPresence_in && !filterPresence_out) { // If none was defined then block all stanzas filterEverything = true; } // Keep a copy of the item element that defines this item this.itemElement = itemElement.createCopy(); }
Example 14
Source File: XmlText.java From ats-framework with Apache License 2.0 | 3 votes |
private XmlText( Element root ) throws XMLException { this.root = DocumentHelper.createElement("root"); DocumentHelper.createDocument(this.root); this.root = root.createCopy(); DocumentHelper.createDocument(this.root); }
Example 15
Source File: VCardManager.java From Openfire with Apache License 2.0 | 2 votes |
/** * Returns the vCard of a given user or null if none was defined before. Changes to the * returned vCard will not be stored in the database. Use the returned vCard as a * read-only vCard. * * @param username Username (not full JID) whose vCard to retrieve. * @return the vCard of a given user. */ public Element getVCard(String username) { Element vCardElement = getOrLoadVCard(username); return vCardElement == null ? null : vCardElement.createCopy(); }