List of usage examples for org.w3c.dom Element getPrefix
public String getPrefix();
null
if it is unspecified. From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyChildNodes_domSoap() throws Exception { String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body xmlns:fish='urn:example:fish'>" + " <meal:lunch xmlns:produce='urn:example:produce'" + " xmlns:meal='urn:example:meal'>" + " <time>1200</time>" + " <produce:lettuce>0.1lb</produce:lettuce>" + " <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + " </meal:lunch>" + " </soap:Body>" + "</soap:Envelope>"; SOAPMessage soapMessage = parseSoap(xml); SOAPElement source = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch"); Element target = XmlUtil.createElement("detail"); // perform the copy SoapUtil.copyChildNodes(target, source); // local element Element time = XmlUtil.getElement(target, "time"); assertNull(time.getPrefix()); // qualified, prefixed element Element lettuce = XmlUtil.getElement(target, "urn:example:produce", "lettuce"); assertEquals("produce", lettuce.getPrefix()); // parent qualified, prefixed element Element fillet = XmlUtil.getElement(target, "urn:example:fish", "fillet"); assertEquals("fish", fillet.getPrefix()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyChildElement_domSoap() throws Exception { // <soap:Envelope xmlns:soap='${SOAPConstants.URI_NS_SOAP_ENVELOPE}'> // <soap:Body xmlns:fish='urn:example:fish'> // <meal:lunch xmlns:produce='urn:example:produce' // xmlns:meal='urn:example:meal'> // <padding /> // </meal:lunch> // </soap:Body> // </soap:Envelope> SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); body.addNamespaceDeclaration("fish", "urn:example:fish"); Name lunchName = envelope.createName("lunch", "meal", "urn:example:meal"); SOAPElement lunch = body.addBodyElement(lunchName); lunch.addNamespaceDeclaration("produce", "urn:example:produce"); lunch.addNamespaceDeclaration("meal", "urn:example:meal"); SOAPElement source = SoapUtil.addChildElement(lunch, "padding"); Element parent = XmlUtil.createElement("urn:example:meal", "lunch"); // perform the copy SoapUtil.copyChildElement(parent, source); Element padding = XmlUtil.getElement(parent, "padding"); // unqualified element assertNull(padding.getPrefix()); // reload/*www. ja v a 2 s . c o m*/ // parent = writeAndRead(parent); padding = XmlUtil.getElement(parent, "padding"); // unqualified element assertNull(padding.getPrefix()); }
From source file:org.jbpm.bpel.xml.util.XmlUtil.java
public static String toTraceString(Element elem) { String namespace = elem.getNamespaceURI(); String localName = elem.getLocalName(); // easy way out: no namespace if (namespace == null || namespace.length() == 0) return localName; StringBuffer traceBuffer = new StringBuffer(namespace.length() + localName.length()); traceBuffer.append('{').append(namespace).append('}'); String prefix = elem.getPrefix(); if (prefix != null && prefix.length() > 0) traceBuffer.append(prefix).append(':'); return traceBuffer.append(localName).toString(); }
From source file:org.jbpm.bpel.xml.util.XmlUtil.java
public static void ensureOwnNamespaceDeclared(Element elem) { ensureNamespaceDeclared(elem, elem.getNamespaceURI(), elem.getPrefix()); }
From source file:org.jbpm.bpel.xml.util.XmlUtil.java
/** * Creates an element with the given namespace URI and prefixed name. The returned element will be * set as the document element of its owner document. * @param namespaceURI the namespace URI of the element to create * @param prefixedName the prefixed name of the element to instantiate * @return a new element with the specified <code>namespaceURI</code> and * <code>prefixedName</code>. *///from w w w .ja va 2 s . com public static Element createElement(String namespaceURI, String prefixedName) { Document doc = createDocument(); Element elem = doc.createElementNS(namespaceURI, prefixedName); doc.appendChild(elem); // some TrAX implementations do not fix up namespaces, declare namespace String prefix = elem.getPrefix(); if (prefix != null) addNamespaceDeclaration(elem, namespaceURI, prefix); else addNamespaceDeclaration(elem, namespaceURI); return elem; }
From source file:org.openestate.io.core.XmlUtils.java
private static void printNode(Element node, int indent) { String prefix = (indent > 0) ? StringUtils.repeat(">", indent) + " " : ""; LOGGER.debug(prefix + "<" + node.getTagName() + "> / " + node.getNamespaceURI() + " / " + node.getPrefix()); prefix = StringUtils.repeat(">", indent + 1) + " "; NamedNodeMap attribs = node.getAttributes(); for (int i = 0; i < attribs.getLength(); i++) { Attr attrib = (Attr) attribs.item(i); LOGGER.debug(prefix + "@" + attrib.getName() + " / " + attrib.getNamespaceURI() + " / " + attrib.getPrefix());/* w w w . j av a 2 s.c o m*/ } NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { XmlUtils.printNode((Element) child, indent + 1); } } }
From source file:org.osaf.cosmo.xml.DomWriter.java
private static void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException { //if (log.isDebugEnabled()) //log.debug("Writing element " + e.getNodeName()); String local = e.getLocalName(); if (local == null) local = e.getNodeName();/* w ww. j av a 2 s. co m*/ String ns = e.getNamespaceURI(); if (ns != null) { String prefix = e.getPrefix(); if (prefix != null) { writer.writeStartElement(prefix, local, ns); writer.writeNamespace(prefix, ns); } else { writer.setDefaultNamespace(ns); writer.writeStartElement(ns, local); writer.writeDefaultNamespace(ns); } } else { writer.writeStartElement(local); } NamedNodeMap attributes = e.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) writeAttribute((Attr) attributes.item(i), writer); NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) writeNode(children.item(i), writer); writer.writeEndElement(); }
From source file:org.unitedinternet.cosmo.util.DomWriter.java
private static void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException { //if (log.isDebugEnabled()) //log.debug("Writing element " + e.getNodeName()); String local = e.getLocalName(); if (local == null) { local = e.getNodeName();// w w w . jav a 2 s. co m } String ns = e.getNamespaceURI(); if (ns != null) { String prefix = e.getPrefix(); if (prefix != null) { writer.writeStartElement(prefix, local, ns); writer.writeNamespace(prefix, ns); } else { writer.setDefaultNamespace(ns); writer.writeStartElement(ns, local); writer.writeDefaultNamespace(ns); } } else { writer.writeStartElement(local); } NamedNodeMap attributes = e.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { writeAttribute((Attr) attributes.item(i), writer); } NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { writeNode(children.item(i), writer); } writer.writeEndElement(); }
From source file:org.wso2.developerstudio.eclipse.esb.impl.ModelObjectImpl.java
/** * {@inheritDoc}/*from w w w . j a va 2 s .c om*/ */ public void load(Element self) throws Exception { // Extract additional namespaces. Map<String, String> extractedNamespaceEntries = extractNamespaces(self); // Load default namespace info. if (!StringUtils.isBlank(self.getNamespaceURI())) { Namespace defaultNs = getEsbFactory().createNamespace(); defaultNs.setUri(self.getNamespaceURI()); if (!StringUtils.isBlank(self.getPrefix())) { defaultNs.setPrefix(self.getPrefix()); // Additional namespaces should not contain the namespace // corresponding to current element itself. extractedNamespaceEntries.remove(self.getPrefix()); } setDefaultNamespace(defaultNs); } // Store extracted namespaces as additional namespaces. for (Entry<String, String> namespaceEntry : extractedNamespaceEntries.entrySet()) { Namespace extractedNs = getEsbFactory().createNamespace(); extractedNs.setPrefix(namespaceEntry.getKey()); extractedNs.setUri(namespaceEntry.getValue()); getAdditionalNamespaces().add(extractedNs); } doLoad(self); }
From source file:org.wso2.developerstudio.eclipse.esb.impl.NamespacedPropertyImpl.java
/** * {@inheritDoc}/* www. j a v a 2 s . c o m*/ */ public void doLoad(Element self) throws Exception { if (self.hasAttribute(getPropertyName())) { setPropertyValue(self.getAttribute(getPropertyName())); } // Clear namespace declarations. getNamespaces().clear(); // Load all declared additional namespaces on this element. Map<String, String> additionalNamespaces = extractNamespaces(self); if (!StringUtils.isBlank(self.getPrefix())) { // Do not include the namespace corresponding to current element itself. additionalNamespaces.remove(self.getPrefix()); } getNamespaces().putAll(additionalNamespaces); super.doLoad(self); }