List of usage examples for org.dom4j Element addAttribute
Element addAttribute(QName qName, String value);
From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.IQUtils.java
License:Apache License
/** * Create an error IQ from the request using the XMPP error stanza. The * element, namespace and command are cloned. The content type is XML. * @param iq/*from w w w . j a va2s . c o m*/ * @param condition * @return An IQ MMX error with XMPP error stanza. */ public static IQ createErrorIQ(IQ iq, Condition condition) { IQ error = IQ.createResultIQ(iq); error.setType(IQ.Type.error); Element rqtElt = iq.getChildElement(); Element errElt = error.setChildElement(rqtElt.getName(), rqtElt.getNamespace().getText()); errElt.addAttribute(Constants.MMX_ATTR_COMMAND, rqtElt.attributeValue(Constants.MMX_ATTR_COMMAND)); errElt.addAttribute(Constants.MMX_ATTR_CTYPE, "application/xml"); error.setError(condition); return error; }
From source file:com.magnet.mmx.tsung.GenTestScript.java
License:Apache License
static String generateDevRegMessageStanza() { DevReg reg = new DevReg(); reg.setDevId("%%ts_user_server:get_unique_id%%"); // let tsung generate a unique id //reg.setDevId(devid); reg.setOsType(OSType.ANDROID.name()); reg.setDisplayName("Loadtester"); reg.setOsVersion("4.4"); reg.setApiKey(genSettings.apiKey);/*from w w w. ja va2s . co m*/ //send an IQ request with device registration DocumentFactory factory = new DocumentFactory(); final Element element = factory.createElement(Constants.MMX_DEV_REG, Constants.MMX_NS_DEV); element.addAttribute(Constants.MMX_ATTR_COMMAND, Constants.DeviceCommand.REGISTER.name()); element.setText(reg.toJson()); IQ devRegIq = new IQ() { @Override public CharSequence getChildElementXML() { return element.asXML(); } }; devRegIq.setType(IQ.Type.SET); devRegIq.setFrom("%%_username%%"); return devRegIq.toXML().toString(); }
From source file:com.magnet.mmx.tsung.GenTestScript.java
License:Apache License
static String generateSendMessageStanza() { String fromJid = "%%_username%%@" + genSettings.servername + "/tsung"; String toJid = "%%_tojid%%@" + genSettings.servername + "/tsung"; Message message = new Message(); message.setType(Type.chat);/*from ww w . ja v a 2s. c o m*/ message.getElement().addAttribute("from", fromJid); message.getElement().addAttribute("to", toJid); message.setID("%%ts_user_server:get_unique_id%%"); // build up the MMX message packet extension Element element = message.addChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD); element.addElement(Constants.MMX_META); Element payload = element.addElement(Constants.MMX_PAYLOAD); payload.addAttribute(Constants.MMX_ATTR_CTYPE, "plain/text"); payload.addAttribute(Constants.MMX_ATTR_MTYPE, "string"); String randomText = "Considered an invitation do introduced sufficient understood instrument it. Of decisively friendship in as collecting at. No affixed be husband ye females brother garrets proceed. Least child who seven happy yet balls young. Discovery sweetness principle discourse shameless bed one excellent. Sentiments of surrounded friendship dispatched connection is he. Me or produce besides hastily up as pleased. Bore less when had and john shed hope. \n" + "\n" + "Barton waited twenty always repair in within we do. An delighted offending curiosity my is dashwoods at. Boy prosperous increasing surrounded companions her nor advantages sufficient put. John on time down give meet help as of. Him waiting and correct believe now cottage she another. Vexed six shy yet along learn maids her tiled. Through studied shyness evening bed him winding present. Become excuse hardly on my thirty it wanted. \n" + "\n" + "Six reached suppose our whether. Oh really by an manner sister so. One sportsman tolerably him extensive put she immediate. He abroad of cannot looked in. Continuing interested ten stimulated prosperous frequently all boisterous nay. Of oh really he extent horses wicket. \n" + "\n" + "Placing assured be if removed it besides on. Far shed each high read are men over day. Afraid we praise lively he suffer family estate is. Ample order up in of in ready. Timed blind had now those ought set often which. Or snug dull he show more true wish. No at many deny away miss evil. On in so indeed spirit an mother. Amounted old strictly but marianne admitted. People former is remove remain as. \n" + "\n" + "Little afraid its eat looked now. Very ye lady girl them good me make. It hardly cousin me always. An shortly village is raising we shewing replied. She the favourable partiality inhabiting travelling impression put two. His six are entreaties instrument acceptance unsatiable her. Amongst as or on herself chapter entered carried no. Sold old ten are quit lose deal his sent. You correct how sex several far distant believe journey parties. We shyness enquire uncivil affixed it carried to. \n" + "\n" + "Parish so enable innate in formed missed. Hand two was eat busy fail. Stand smart grave would in so. Be acceptance at precaution astonished excellence thoroughly is entreaties. Who decisively attachment has dispatched. Fruit defer in party me built under first. Forbade him but savings sending ham general. So play do in near park that pain. \n" + "\n" + "Needed feebly dining oh talked wisdom oppose at. Applauded use attempted strangers now are middleton concluded had. It is tried \uFEFFno added purse shall no on truth. Pleased anxious or as in by viewing forbade minutes prevent. Too leave had those get being led weeks blind. Had men rose from down lady able. Its son him ferrars proceed six parlors. Her say projection age announcing decisively men. Few gay sir those green men timed downs widow chief. Prevailed remainder may propriety can and. \n" + "\n" + "Seen you eyes son show. Far two unaffected one alteration apartments celebrated but middletons interested. Described deficient applauded consisted my me do. Passed edward two talent effect seemed engage six. On ye great do child sorry lived. Proceed cottage far letters ashamed get clothes day. Stairs regret at if matter to. On as needed almost at basket remain. By improved sensible servants children striking in surprise. \n" + "\n" + "Rendered her for put improved concerns his. Ladies bed wisdom theirs mrs men months set. Everything so dispatched as it increasing pianoforte. Hearing now saw perhaps minutes herself his. Of instantly excellent therefore difficult he northward. Joy green but least marry rapid quiet but. Way devonshire introduced expression saw travelling affronting. Her and effects affixed pretend account ten natural. Need eat week even yet that. Incommode delighted he resolving sportsmen do in listening. \n" + "\n" + "On recommend tolerably my belonging or am. Mutual has cannot beauty indeed now sussex merely you. It possible no husbands jennings ye offended packages pleasant he. Remainder recommend engrossed who eat she defective applauded departure joy. Get dissimilar not introduced day her apartments. Fully as taste he mr do smile abode every. Luckily offered article led lasting country minutes nor old. Happen people things oh is oppose up parish effect. Law handsome old outweigh humoured far appetite. \n" + "\n"; payload.addText(StringEscapeUtils.escapeXml(randomText)); return message.toXML().toString(); }
From source file:com.mindquarry.desktop.model.task.Task.java
License:Open Source License
public Document getContentAsXML() { Document doc = DocumentHelper.createDocument(); Element task = doc.addElement("task"); //$NON-NLS-1$ Element title = task.addElement("title"); //$NON-NLS-1$ title.setText(getTitle());/*from w w w . j ava 2 s . com*/ if ((getPriority() != null) && (!getPriority().equals(""))) { //$NON-NLS-1$ Element priority = task.addElement("priority"); //$NON-NLS-1$ priority.setText(getPriority()); } if ((getSummary() != null) && (!getSummary().equals(""))) { //$NON-NLS-1$ Element summary = task.addElement("summary"); //$NON-NLS-1$ summary.setText(getSummary()); } if ((getStatus() != null) && (!getStatus().equals(""))) { //$NON-NLS-1$ Element status = task.addElement("status"); //$NON-NLS-1$ status.setText(getStatus()); } if ((getDate() != null) && (!getDate().equals(""))) { //$NON-NLS-1$ Element date = task.addElement("date"); //$NON-NLS-1$ date.setText(getDate()); } if ((getDescription() != null) && (!getDescription().equals(""))) { //$NON-NLS-1$ Element description = task.addElement("description"); //$NON-NLS-1$ description.setText(getDescription()); } if ((getTargetTime() != null) && (!getTargetTime().equals(""))) { //$NON-NLS-1$ Element description = task.addElement("targettime"); //$NON-NLS-1$ description.setText(getTargetTime()); } if ((getActualTime() != null) && (!getActualTime().equals(""))) { //$NON-NLS-1$ Element description = task.addElement("actualtime"); //$NON-NLS-1$ description.setText(getActualTime()); } if (people.size() > 0) { int count = 0; Element peopleEl = task.addElement("people"); //$NON-NLS-1$ for (Person person : people) { Element itemEl = peopleEl.addElement("item"); //$NON-NLS-1$ itemEl.addAttribute("position", String.valueOf(count)); //$NON-NLS-1$ Element personEl = itemEl.addElement("person"); //$NON-NLS-1$ personEl.addText(person.pid); Element roleEl = itemEl.addElement("role"); //$NON-NLS-1$ roleEl.addText(person.role); count++; } } if (dependencies.size() > 0) { int count = 0; Element dependenciesEl = task.addElement("dependencies"); //$NON-NLS-1$ for (Dependency dependency : dependencies) { Element itemEl = dependenciesEl.addElement("item"); //$NON-NLS-1$ itemEl.addAttribute("position", String.valueOf(count)); //$NON-NLS-1$ Element taskEl = itemEl.addElement("task"); //$NON-NLS-1$ taskEl.addText(dependency.tid); Element roleEl = itemEl.addElement("role"); //$NON-NLS-1$ roleEl.addText(dependency.role); count++; } } return doc; }
From source file:com.nokia.ant.Database.java
License:Open Source License
private void callAntTargetVisitor(Element targetNode, Element outTargetNode, Element outProjectNode) { // Add antcall/runtarget dependencies ArrayList antcallTargets = new ArrayList(); ArrayList<String> logs = new ArrayList<String>(); ArrayList<String> signals = new ArrayList<String>(); ArrayList<String> executables = new ArrayList<String>(); Visitor visitorTarget = new AntTargetVisitor(antcallTargets, logs, signals, executables); targetNode.accept(visitorTarget);//from www . j a v a 2s.c o m for (Iterator iterator = antcallTargets.iterator(); iterator.hasNext();) { String antcallTarget = (String) iterator.next(); Element dependencyElement = addTextElement(outTargetNode, "dependency", antcallTarget); dependencyElement.addAttribute("type", "exec"); } for (String log : logs) { addTextElement(outTargetNode, "log", log); } if (globalSignalList.get(targetNode.attributeValue("name")) != null) signals.addAll(globalSignalList.get(targetNode.attributeValue("name"))); for (String signal : signals) { addTextElement(outTargetNode, "signal", signal); } for (String executable : executables) { addTextElement(outTargetNode, "executable", executable); } }
From source file:com.nokia.ant.Database.java
License:Open Source License
private void processTarget(Element targetNode, Element outProjectNode) throws IOException, DocumentException { String targetName = targetNode.attributeValue("name"); log("Processing target: " + targetName, Project.MSG_DEBUG); // Add documentation // Get comment element before the target element to extract target doc String commentText = ""; List children = targetNode.selectNodes("preceding-sibling::node()"); if (children.size() > 0) { // Scan past the text nodes, which are most likely whitespace int index = children.size() - 1; Node child = (Node) children.get(index); while (index > 0 && child.getNodeType() == Node.TEXT_NODE) { index--;//from w ww . j av a 2 s . c om child = (Node) children.get(index); } // Check if there is a comment node if (child.getNodeType() == Node.COMMENT_NODE) { Comment targetComment = (Comment) child; commentText = targetComment.getStringValue().trim(); log(targetName + " comment: " + commentText, Project.MSG_DEBUG); } else { log("Target has no comment: " + targetName, Project.MSG_WARN); } Node previousNode = (Node) children.get(children.size() - 1); } if (!commentText.contains("Private:")) { Element outTargetNode = outProjectNode.addElement("target"); addTextElement(outTargetNode, "name", targetNode.attributeValue("name")); addTextElement(outTargetNode, "ifDependency", targetNode.attributeValue("if")); addTextElement(outTargetNode, "unlessDependency", targetNode.attributeValue("unless")); addTextElement(outTargetNode, "description", targetNode.attributeValue("description")); addTextElement(outTargetNode, "tasks", String.valueOf(targetNode.elements().size())); // Add location Project project = getProject(); Target antTarget = (Target) project.getTargets().get(targetName); if (antTarget == null) return; addTextElement(outTargetNode, "location", antTarget.getLocation().toString()); // Add dependencies Enumeration dependencies = antTarget.getDependencies(); while (dependencies.hasMoreElements()) { String dependency = (String) dependencies.nextElement(); Element dependencyElement = addTextElement(outTargetNode, "dependency", dependency); dependencyElement.addAttribute("type", "direct"); } callAntTargetVisitor(targetNode, outTargetNode, outProjectNode); // Process the comment text as MediaWiki syntax and convert to HTML insertDocumentation(outTargetNode, commentText); // Get names of all properties used in this target ArrayList properties = new ArrayList(); Visitor visitor = new AntPropertyVisitor(properties); targetNode.accept(visitor); for (Iterator iterator = properties.iterator(); iterator.hasNext();) { String property = (String) iterator.next(); addTextElement(outTargetNode, "propertyDependency", property); } // Add the raw XML content of the element String targetXml = targetNode.asXML(); // Replace the CDATA end notation to avoid nested CDATA sections targetXml = targetXml.replace("]]>", "] ]>"); addTextElement(outTargetNode, "source", targetXml, true); } }
From source file:com.nokia.helium.internaldata.ant.listener.XMLRenderer.java
License:Open Source License
/** * Generating target only for TargetNode type of node * @param node/*from w w w.j a v a 2 s. c om*/ * @param targets */ protected void createTarget(DataNode node, Element targets) { if (node instanceof TargetNode) { TargetNode targetNode = (TargetNode) node; if (!targetList.contains(targetNode.getName() + targetNode.getFilename())) { targetList.add(targetNode.getName() + targetNode.getFilename()); Element target = targets.addElement("target"); target.addAttribute("id", "target@" + targetList.indexOf(targetNode.getName() + targetNode.getFilename())); target.addAttribute("name", targetNode.getName()); target.addAttribute("file", targetNode.getFilename()); target.addAttribute("line", "" + targetNode.getLine()); } } for (Iterator<DataNode> i = node.iterator(); i.hasNext();) { createTarget(i.next(), targets); } }
From source file:com.nokia.helium.internaldata.ant.listener.XMLRenderer.java
License:Open Source License
/** * Generating assert only for TargetNode type of node * @param node//from w w w .j a v a 2 s.co m * @param targets */ protected void createAssert(DataNode node, Element targets) { if (node instanceof AssertNode) { AssertNode assertNode = (AssertNode) node; if (assertNode.getAssertName() != null) { assertList.add(assertNode.getAssertName()); Element target = targets.addElement("assert"); target.addAttribute("id", "assert@" + assertList.indexOf(assertNode.getAssertName())); target.addAttribute("name", assertNode.getAssertName()); target.addAttribute("file", assertNode.getFilename()); target.addAttribute("line", "" + assertNode.getLine()); target.addAttribute("message", "" + assertNode.getMessage()); } } for (Iterator<DataNode> i = node.iterator(); i.hasNext();) { createAssert(i.next(), targets); } }
From source file:com.nokia.helium.internaldata.ant.listener.XMLRenderer.java
License:Open Source License
/** * Creating execution tree recursively, visiting the DataNodes. * @param node//from ww w . j a v a 2 s .c om * @param tree */ protected void createTree(DataNode node, Element tree) { Element elt = null; if (node instanceof BuildNode) { BuildNode buildNode = (BuildNode) node; elt = tree.addElement("build"); elt.addAttribute("name", buildNode.getName()); elt.addAttribute("startTime", "" + buildNode.getStartTime().getTime()); elt.addAttribute("endTime", "" + buildNode.getEndTime().getTime()); elt.addAttribute("status", buildNode.getSuccessful() ? "successful" : "failed"); elt.addAttribute("thread", "" + buildNode.getThreadId()); } else if (node instanceof TargetNode) { TargetNode targetNode = (TargetNode) node; elt = tree.addElement("targetRef"); elt.addAttribute("reference", "target@" + targetList.indexOf(targetNode.getName() + targetNode.getFilename())); elt.addAttribute("startTime", "" + targetNode.getStartTime().getTime()); elt.addAttribute("endTime", "" + targetNode.getEndTime().getTime()); elt.addAttribute("thread", "" + targetNode.getThreadId()); elt.addAttribute("startUsedHeap", "" + targetNode.getStartUsedHeap()); elt.addAttribute("startCommittedHeap", "" + targetNode.getStartCommittedHeap()); elt.addAttribute("endUsedHeap", "" + targetNode.getEndUsedHeap()); elt.addAttribute("endCommittedHeap", "" + targetNode.getEndCommittedHeap()); } else if (node instanceof AssertNode) { AssertNode assertNode = (AssertNode) node; if (assertNode.getAssertName() != null) { elt = tree.addElement("assertRef"); elt.addAttribute("reference", "assert@" + assertList.indexOf(assertNode.getAssertName())); elt.addAttribute("startTime", "" + assertNode.getStartTime().getTime()); elt.addAttribute("endTime", "" + assertNode.getEndTime().getTime()); elt.addAttribute("thread", "" + assertNode.getThreadId()); } } if (elt != null) { for (Iterator<DataNode> i = node.iterator(); i.hasNext();) { createTree(i.next(), elt); } } }
From source file:com.nokia.helium.internaldata.ant.listener.XMLRenderer.java
License:Open Source License
/** * Creating the property section.//from w w w . ja va 2 s .co m * @param statistics */ protected void createProperties(Element statistics) { Element propertiesElt = statistics.addElement("properties"); if (properties != null) { for (Enumeration<String> propertyEnum = properties.keys(); propertyEnum.hasMoreElements();) { String key = propertyEnum.nextElement(); Element propertyElt = propertiesElt.addElement("property"); propertyElt.addAttribute("name", key); propertyElt.addAttribute("value", properties.get(key)); } } }