List of usage examples for org.dom4j QName get
public static QName get(String qualifiedName, String uri)
From source file:com.xebialabs.overthere.winrm.WinRmClient.java
License:Open Source License
public void signal() { if (commandId == null) { logger.warn("Not sending WinRM Signal request in shell {} because there is no running command", shellId);//from w w w . ja va 2s . c o m return; } logger.debug("Sending WinRM Signal request for command {} in shell {}", commandId, shellId); final Element bodyContent = DocumentHelper.createElement(QName.get("Signal", Namespaces.NS_WIN_SHELL)) .addAttribute("CommandId", commandId); bodyContent.addElement(QName.get("Code", Namespaces.NS_WIN_SHELL)) .addText("http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate"); final Document requestDocument = getRequestDocument(Action.WS_SIGNAL, ResourceURI.RESOURCE_URI_CMD, null, bodyContent); sendRequest(requestDocument, SoapAction.SIGNAL); logger.debug("Sent WinRM Signal request for command {} in shell {}", commandId, shellId); }
From source file:com.zimbra.cs.dav.property.ResourceProperty.java
License:Open Source License
public ResourceProperty(String name) { this(QName.get(name, DavElements.WEBDAV_NS)); }
From source file:com.zimbra.cs.dav.resource.DavResource.java
License:Open Source License
public ResourceProperty getProperty(String propName) { return getProperty(QName.get(propName, DavElements.WEBDAV_NS)); }
From source file:com.zimbra.cs.dav.resource.DavResource.java
License:Open Source License
protected void setProperty(String key, String val) { setProperty(QName.get(key, DavElements.WEBDAV_NS), val); }
From source file:com.zimbra.soap.SoapCommandUtil.java
License:Open Source License
/** * Processes a path that's relative to the given root. The path * is in an XPath-like format:// w ww . j a v a 2 s .c o m * * <p><tt>element1/element2[/@attr][=value]</tt></p> * * If a value is specified, it sets the text of the last element * or attribute in the path. * * @param start <tt>Element</tt> that the path is relative to, or <tt>null</tt> * for the root * @param path an XPath-like path of elements and attributes */ private Element processPath(Element start, String path, ElementFactory factory) { String value = null; // Parse out value, if it's specified. Matcher m = PAT_PATH_AND_VALUE.matcher(path); if (m.matches()) { path = m.group(1); value = m.group(2); } // Find the first element. Element element = start; // Walk parts and implicitly create elements. String[] parts = path.split("/"); String part = null; for (int i = 0; i < parts.length; i++) { part = parts[i]; if (element == null) { QName name = QName.get(part, mNamespace); element = factory.createElement(name); } else if (part.equals("..")) { element = element.getParent(); } else if (!(part.startsWith("@"))) { element = element.addElement(part); } } // Set either element text or attribute value if (value != null && part != null) { if (part.startsWith("@")) { String attrName = part.substring(1); element.addAttribute(attrName, value); } else { element.setText(value); } } return element; }
From source file:com.zimbra.soap.util.WsdlGenerator.java
License:Open Source License
public static Document makeWsdlDoc(List<WsdlInfoForNamespace> nsInfos, String serviceName, String targetNamespace) { Namespace nsSvc = new Namespace(svcPrefix, targetNamespace); final QName svcTypes = QName.get("types", nsWsdl); Document document = DocumentHelper.createDocument(); Map<WsdlServiceInfo, Element> bindElems = Maps.newTreeMap(); Map<WsdlServiceInfo, Element> portTypeElems = Maps.newTreeMap(); Element root = document.addElement(QName.get("definitions", nsWsdl)); root.add(nsSvc);//from www . ja v a 2s. c o m for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) { root.add(wsdlNsInfo.getXsdNamespace()); } root.add(nsZimbra); root.add(nsSoap); root.add(nsXsd); root.add(nsWsdl); root.addAttribute("targetNamespace", targetNamespace); root.addAttribute("name", serviceName); addWsdlTypesElement(root, svcTypes, nsInfos); for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) { WsdlServiceInfo svcInfo = wsdlNsInfo.getSvcInfo(); if (!portTypeElems.containsKey(svcInfo)) { // wsdl:definitions/wsdl:portType Element portTypeElem = DocumentHelper.createElement(portType); portTypeElem.addAttribute("name", svcInfo.getPortTypeName()); portTypeElems.put(svcInfo, portTypeElem); } if (!bindElems.containsKey(svcInfo)) { // wsdl:definitions/wsdl:binding Element bindingElem = DocumentHelper.createElement(wsdlBinding); bindingElem.addAttribute("name", svcInfo.getBindingName()); bindingElem.addAttribute("type", svcPrefix + ":" + svcInfo.getPortTypeName()); // wsdl:definitions/wsdl:binding/soap:binding Element soapBindElem = bindingElem.addElement(soapBinding); soapBindElem.addAttribute("transport", "http://schemas.xmlsoap.org/soap/http"); soapBindElem.addAttribute("style", "document"); bindElems.put(svcInfo, bindingElem); } } for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) { WsdlServiceInfo svcInfo = wsdlNsInfo.getSvcInfo(); for (String requestName : wsdlNsInfo.getRequests()) { String rootName = requestName.substring(0, requestName.length() - 7); String responseName = rootName + "Response"; String reqOpName = requestName.substring(0, 1).toLowerCase() + requestName.substring(1); String reqMsgName = wsdlNsInfo.getTag() + requestName + "Message"; String respMsgName = wsdlNsInfo.getTag() + responseName + "Message"; addWsdlRequestAndResponseMessageElements(root, wsdlNsInfo, reqMsgName, respMsgName, requestName, responseName); addWsdlPortTypeOperationElements(portTypeElems.get(svcInfo), reqMsgName, respMsgName, reqOpName); addWsdlBindingOperationElements(bindElems.get(svcInfo), wsdlNsInfo, reqOpName, rootName); } } addWsdlSoapHdrContextMessageElement(root); for (Entry<WsdlServiceInfo, Element> entry : portTypeElems.entrySet()) { root.add(entry.getValue()); } for (Entry<WsdlServiceInfo, Element> entry : bindElems.entrySet()) { root.add(entry.getValue()); } Set<WsdlServiceInfo> svcSet = Sets.newHashSet(); for (WsdlInfoForNamespace wsdlNsInfo : nsInfos) { WsdlServiceInfo svcInfo = wsdlNsInfo.getSvcInfo(); if (!svcSet.contains(svcInfo)) { svcSet.add(svcInfo); addWsdlServiceElement(root, svcInfo); } } return document; }
From source file:com.zrsf.push.xmpp.push.NotificationManager.java
License:Open Source License
private IQ createNotificationIQ(String apikey, String json) { Random random = new Random(); String id = Integer.toHexString(random.nextInt()); Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE)); notification.addElement("id").setText(id); notification.addElement("apiKey").setText(apikey); notification.addElement("json").setText(json); IQ iq = new IQ(); iq.setType(IQ.Type.set);/*from w w w . j a v a2 s. c o m*/ iq.setChildElement(notification); return iq; }
From source file:de.fmaul.android.cmis.repo.CmisTypeDefinition.java
License:Apache License
public static CmisTypeDefinition createFromFeed(Document doc) { CmisTypeDefinition td = new CmisTypeDefinition(); final Namespace CMISRA = Namespace.get("http://docs.oasis-open.org/ns/cmis/restatom/200908/"); final QName CMISRA_TYPE = QName.get("type", CMISRA); Element type = doc.getRootElement().element(CMISRA_TYPE); td.id = type.elementTextTrim("id"); td.localName = type.elementTextTrim("localName"); td.localNamespace = type.elementTextTrim("localNamespace"); td.displayName = type.elementTextTrim("displayName"); td.queryName = type.elementTextTrim("queryName"); td.description = type.elementTextTrim("description"); td.baseId = type.elementTextTrim("baseId"); td.creatable = Boolean.valueOf(type.elementTextTrim("creatable")); td.fileable = Boolean.valueOf(type.elementTextTrim("fileable")); td.queryable = Boolean.valueOf(type.elementTextTrim("queryable")); td.fulltextIndexed = Boolean.valueOf(type.elementTextTrim("fulltextIndexed")); td.includedInSupertypeQuery = Boolean.valueOf(type.elementTextTrim("includedInSupertypeQuery")); td.controllablePolicy = Boolean.valueOf(type.elementTextTrim("controllablePolicy")); td.controllableACL = Boolean.valueOf(type.elementTextTrim("controllableACL")); td.versionable = Boolean.valueOf(type.elementTextTrim("versionable")); td.contentStreamAllowed = type.elementTextTrim("contentStreamAllowed"); List<Element> allElements = doc.getRootElement().element(CMISRA_TYPE).elements(); for (Element element : allElements) { if (element.getName().startsWith("property")) { CmisPropertyTypeDefinition propTypeDef = CmisPropertyTypeDefinition.createFromElement(element); td.propertyDefinition.put(propTypeDef.getId(), propTypeDef); }// w ww.j av a2 s . c o m } return td; }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.IQ.java
License:Open Source License
/** * Returns a {@link PacketExtension} on the first element found in this packet's * child element for the specified <tt>name</tt> and <tt>namespace</tt> or <tt>null</tt> if * none was found. If the IQ packet does not have a child element then <tt>null</tt> * will be returned.<p>//from w w w . j av a 2s . c o m * * Note: packet extensions on IQ packets are only for use in specialized situations. * In most cases, you should only need to set the child element of the IQ. * * @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 <tt>null</tt> if none was found. */ @SuppressWarnings("unchecked") public PacketExtension getExtension(String name, String namespace) { Element childElement = getChildElement(); if (childElement == null) { return null; } // Search for extensions in the child element List<Element> extensions = childElement.elements(QName.get(name, namespace)); if (!extensions.isEmpty()) { Class<? extends PacketExtension> extensionClass = PacketExtension.getExtensionClass(name, namespace); if (extensionClass != null) { try { Constructor<? extends PacketExtension> constructor = extensionClass .getDeclaredConstructor(new Class[] { Element.class }); return constructor.newInstance(new Object[] { extensions.get(0) }); } catch (Exception e) { Log.warn("Packet extension (name " + name + ", namespace " + namespace + ") cannot be found.", e); } } } return null; }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.IQ.java
License:Open Source License
/** * Deletes the first element whose element name and namespace matches the specified * element name and namespace in this packet's child element. If the * IQ packet does not have a child element then this method does nothing and returns * <tt>false</tt>.<p>/*from w ww. j av a 2 s . c o 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}.<p> * * Note: packet extensions on IQ packets are only for use in specialized situations. * In most cases, you should only need to set the child element of the IQ. * * @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) { Element childElement = getChildElement(); if (childElement == null) { return false; } // Delete extensions in the child element List<Element> extensions = childElement.elements(QName.get(name, namespace)); if (!extensions.isEmpty()) { childElement.remove(extensions.get(0)); return true; } return false; }