List of usage examples for org.dom4j QName get
public static QName get(String qualifiedName, String uri)
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.Packet.java
License:Open Source License
/** * Returns a {@link PacketExtension} on the first element found in this packet * for the specified <tt>name</tt> and <tt>namespace</tt> or <tt>null</tt> if * none was found.//from w w w . j ava 2 s . c o m * * @param name the child element name. * @param namespace the child element namespace. * @return a PacketExtension on the first element found in this packet for the specified * name and namespace or null if none was found. */ @SuppressWarnings("unchecked") public PacketExtension getExtension(String name, String namespace) { List<Element> extensions = element.elements(QName.get(name, namespace)); if (!extensions.isEmpty()) { Class<? extends PacketExtension> extensionClass = PacketExtension.getExtensionClass(name, namespace); // If a specific PacketExtension implementation has been registered, use that. if (extensionClass != null) { try { Constructor<? extends PacketExtension> constructor = extensionClass .getDeclaredConstructor(Element.class); return constructor.newInstance(extensions.get(0)); } catch (Exception e) { Log.warn("Packet extension (name " + name + ", namespace " + namespace + ") cannot be found.", e); } } // Otherwise, use a normal PacketExtension. else { return new PacketExtension(extensions.get(0)); } } return null; }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.Packet.java
License:Open Source License
/** * Deletes the first element whose element name and namespace matches the specified * element name and namespace.<p>//from www .j av a 2 s.co m * * Notice that this method may remove any child element that matches the specified * element name and namespace even if that element was not added to the Packet using a * {@link PacketExtension}. * * * @param name the child element name. * @param namespace the child element namespace. * @return true if a child element was removed. */ @SuppressWarnings("unchecked") public boolean deleteExtension(String name, String namespace) { List<Element> extensions = element.elements(QName.get(name, namespace)); if (!extensions.isEmpty()) { element.remove(extensions.get(0)); return true; } return false; }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.PacketExtension.java
License:Open Source License
/** * Returns the extension class to use for the specified element name and namespace. For * instance, the DataForm class should be used for the element "x" and * namespace "jabber:x:data".//w w w.j a va 2 s. c om * * @param name the child element name. * @param namespace the child element namespace. * @return the extension class to use for the specified element name and namespace. */ public static Class<? extends PacketExtension> getExtensionClass(String name, String namespace) { return registeredExtensions.get(QName.get(name, namespace)); }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.resultsetmanagement.ResultSet.java
License:Open Source License
/** * Generates a Result Set Management 'set' element that describes the parto * of the result set that was generated. You typically would use the List * that was returned by {@link #applyRSMDirectives(Element)} as an argument * to this method.//from w w w. j a v a 2 s . c o m * * @param returnedResults * The subset of Results that is returned by the current query. * @return An Element named 'set' that can be included in the result IQ * stanza, which returns the subset of results. */ public Element generateSetElementFromResults(List<E> returnedResults) { if (returnedResults == null) { throw new IllegalArgumentException("Argument 'returnedResults' cannot be null."); } final Element setElement = DocumentHelper .createElement(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)); // the size element contains the size of this entire result set. setElement.addElement("count").setText(String.valueOf(size())); // if the query wasn't a 'count only' query, add two more elements if (returnedResults.size() > 0) { final Element firstElement = setElement.addElement("first"); firstElement.addText(returnedResults.get(0).getUID()); firstElement.addAttribute("index", String.valueOf(indexOf(returnedResults.get(0)))); setElement.addElement("last").addText(returnedResults.get(returnedResults.size() - 1).getUID()); } return setElement; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.XsdElement.java
License:BSD License
public Element create() { QName qNode = QName.get(xmlName(), AbstractStudyCalendarXmlSerializer.PSC_NS); return DocumentHelper.createElement(qNode); }
From source file:eml.studio.server.oozie.workflow.ActionNodeDef.java
License:Open Source License
/** * the detail xml configurations goes here, this will be called in append2XML * @param action// w w w . j a va 2 s . c o m */ public void generateActionXML(Element action) { Namespace xmlns = new Namespace("", "uri:oozie:shell-action:0.2"); // root namespace uri QName qName = QName.get("shell", xmlns); // your root element's name Element shell = action.addElement(qName); // action.appendChild( shell ); generateElement(shell, "job-tracker", "${jobTracker}"); generateElement(shell, "name-node", "${nameNode}"); Element configuration = shell.addElement("configuration"); createProperty(configuration, "mapred.job.queue.name", "${queueName}"); createProperty(configuration, "mapreduce.map.memeory.mb", "10240"); if (program.isScriptProgram()) { //?? generateElement(shell, "exec", "./" + widgetId + ".startup"); } else { generateElement(shell, "exec", "./run.sh"); } command2XMLforShell(shell); if (program.isScriptProgram()) { generateElement(shell, "file", "${appPath}/" + widgetId + ".startup"); generateElement(shell, "file", "${appPath}/" + widgetId + ".script"); } else generateElement(shell, "file", "${nameNode}/" + program.getPath() + "/run.sh"); shell.addElement("capture-output"); }
From source file:eml.studio.server.oozie.workflow.WFGraph.java
License:Open Source License
/** * Transform the Graph into an workflow xml definition * @param jobname the job name of Oozie job, can't be null * @return workflow xml//from w w w. j ava 2s.c o m */ public String toWorkflow(String jobname) { Namespace xmlns = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri QName qName = QName.get("workflow-app", xmlns); // your root element's name Element workflow = DocumentHelper.createElement(qName); Document xmldoc = DocumentHelper.createDocument(workflow); // Create workflow root workflow.addAttribute("xmlns", "uri:oozie:workflow:0.4"); // <workflow-app name='xxx'></workflow-app> if (jobname == null || "".equals(jobname)) workflow.addAttribute("name", "Not specified"); else workflow.addAttribute("name", jobname); Queue<NodeDef> que = new LinkedList<NodeDef>(); que.add(start); while (!que.isEmpty()) { NodeDef cur = que.remove(); cur.append2XML(workflow); for (NodeDef toNode : cur.getOutNodes()) { toNode.delInNode(cur); if (toNode.getInDegree() == 0) que.add(toNode); } } // Set XML document format OutputFormat outputFormat = OutputFormat.createPrettyPrint(); // Set XML encoding, use the specified encoding to save the XML document to the string, it can be specified GBK or ISO8859-1 outputFormat.setEncoding("UTF-8"); outputFormat.setSuppressDeclaration(true); // Whether generate xml header outputFormat.setIndent(true); // Whether set indentation outputFormat.setIndent(" "); // Implement indentation with four spaces outputFormat.setNewlines(true); // Set whether to wrap try { // stringWriter is used to save xml document StringWriter stringWriter = new StringWriter(); // xmlWriter is used to write XML document to string(tool) XMLWriter xmlWriter = new XMLWriter(stringWriter, outputFormat); // Write the created XML document into the string xmlWriter.write(xmldoc); xmlWriter.close(); System.out.println(stringWriter.toString().trim()); // Print the string, that is, the XML document return stringWriter.toString().trim(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:eml.studio.server.oozie.workflow.WFGraph.java
License:Open Source License
public static void main(String args[]) { Namespace rootNs = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri QName rootQName = QName.get("workflow-app", rootNs); // your root element's name Element workflow = DocumentHelper.createElement(rootQName); Document doc = DocumentHelper.createDocument(workflow); workflow.addAttribute("name", "test"); Element test = workflow.addElement("test"); test.addText("hello"); OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true);/* w w w .ja v a2s. co m*/ outputFormat.setIndent(" "); outputFormat.setNewlines(true); try { StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter); xmlWriter.write(doc); xmlWriter.close(); System.out.println(doc.asXML()); System.out.println(stringWriter.toString().trim()); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:net.emiva.crossfire.plugin.muc.spi.IQMUCRegisterHandler.java
License:Open Source License
public void initialize() { if (probeResult == null) { // Create the registration form of the room which contains information // such as: first name, last name and nickname. final DataForm registrationForm = new DataForm(DataForm.Type.form); registrationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.reg.title")); registrationForm.addInstruction(LocaleUtils.getLocalizedString("muc.form.reg.instruction")); final FormField fieldForm = registrationForm.addField(); fieldForm.setVariable("FORM_TYPE"); fieldForm.setType(FormField.Type.hidden); fieldForm.addValue("http://jabber.org/protocol/muc#register"); final FormField fieldReg = registrationForm.addField(); fieldReg.setVariable("muc#register_first"); fieldReg.setType(FormField.Type.text_single); fieldReg.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name")); fieldReg.setRequired(true);/*from w w w . j a va 2s .co m*/ final FormField fieldLast = registrationForm.addField(); fieldLast.setVariable("muc#register_last"); fieldLast.setType(FormField.Type.text_single); fieldLast.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name")); fieldLast.setRequired(true); final FormField fieldNick = registrationForm.addField(); fieldNick.setVariable("muc#register_roomnick"); fieldNick.setType(FormField.Type.text_single); fieldNick.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname")); fieldNick.setRequired(true); final FormField fieldUrl = registrationForm.addField(); fieldUrl.setVariable("muc#register_url"); fieldUrl.setType(FormField.Type.text_single); fieldUrl.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url")); final FormField fieldMail = registrationForm.addField(); fieldMail.setVariable("muc#register_email"); fieldMail.setType(FormField.Type.text_single); fieldMail.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email")); final FormField fieldFaq = registrationForm.addField(); fieldFaq.setVariable("muc#register_faqentry"); fieldFaq.setType(FormField.Type.text_single); fieldFaq.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry")); // Create the probeResult and add the registration form probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register")); probeResult.add(registrationForm.getElement()); } }
From source file:net.emiva.crossfire.plugin.muc.spi.IQMUCRegisterHandler.java
License:Open Source License
public IQ handleIQ(IQ packet) { IQ reply = null;/*from w w w . j ava2 s. c om*/ // Get the target room MUCRoom room = null; String name = packet.getTo().getNode(); if (name != null) { room = mucService.getChatRoom(name); } if (room == null) { // The room doesn't exist so answer a NOT_FOUND error reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.item_not_found); return reply; } else if (!room.isRegistrationEnabled()) { // The room does not accept users to register reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.not_allowed); return reply; } if (IQ.Type.get == packet.getType()) { reply = IQ.createResultIQ(packet); String nickname = room.getReservedNickname(packet.getFrom().toBareJID()); Element currentRegistration = probeResult.createCopy(); if (nickname != null) { // The user is already registered with the room so answer a completed form ElementUtil.setProperty(currentRegistration, "query.registered", null); Element form = currentRegistration.element(QName.get("x", "jabber:x:data")); Iterator fields = form.elementIterator("field"); Element field; while (fields.hasNext()) { field = (Element) fields.next(); if ("muc#register_roomnick".equals(field.attributeValue("var"))) { field.addElement("value").addText(nickname); } } reply.setChildElement(currentRegistration); } else { // The user is not registered with the room so answer an empty form reply.setChildElement(currentRegistration); } } else if (IQ.Type.set == packet.getType()) { try { // Keep a registry of the updated presences List<Presence> presences = new ArrayList<Presence>(); reply = IQ.createResultIQ(packet); Element iq = packet.getChildElement(); if (ElementUtil.includesProperty(iq, "query.remove")) { // The user is deleting his registration presences.addAll(room.addNone(packet.getFrom(), room.getRole())); } else { // The user is trying to register with a room Element formElement = iq.element("x"); // Check if a form was used to provide the registration info if (formElement != null) { // Get the sent form final DataForm registrationForm = new DataForm(formElement); // Get the desired nickname sent in the form List<String> values = registrationForm.getField("muc#register_roomnick").getValues(); String nickname = (!values.isEmpty() ? values.get(0) : null); // TODO The rest of the fields of the form are ignored. If we have a // requirement in the future where we need those fields we'll have to change // MUCRoom.addMember in order to receive a RegistrationInfo (new class) // Add the new member to the members list presences.addAll(room.addMember(packet.getFrom(), nickname, room.getRole())); } else { reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.bad_request); } } // Send the updated presences to the room occupants for (Presence presence : presences) { room.send(presence); } } catch (ForbiddenException e) { reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.forbidden); } catch (ConflictException e) { reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.conflict); } catch (Exception e) { Log.error(e.getMessage(), e); } } return reply; }