List of usage examples for org.w3c.dom Attr getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * Output a DOM representation to a SerializationContext * @param el is a DOM Element/*from w w w . ja va 2s.c o m*/ */ public void writeDOMElement(Element el) throws IOException { AttributesImpl attributes = null; NamedNodeMap attrMap = el.getAttributes(); if (attrMap.getLength() > 0) { attributes = new AttributesImpl(); for (int i = 0; i < attrMap.getLength(); i++) { Attr attr = (Attr)attrMap.item(i); String tmp = attr.getNamespaceURI(); if ( tmp != null && tmp.equals(Constants.NS_URI_XMLNS) ) { String prefix = attr.getLocalName(); if (prefix != null) { if (prefix.equals("xmlns")) prefix = ""; String nsURI = attr.getValue(); registerPrefixForURI(prefix, nsURI); } continue; } attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA", attr.getValue()); } } String namespaceURI = el.getNamespaceURI(); String localPart = el.getLocalName(); if(namespaceURI == null || namespaceURI.length()==0) localPart = el.getNodeName(); QName qName = new QName(namespaceURI, localPart); startElement(qName, attributes); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { writeDOMElement((Element)child); } else if (child instanceof CDATASection) { writeString("<![CDATA["); writeString(((Text)child).getData()); writeString("]]>"); } else if (child instanceof Comment) { writeString("<!--"); writeString(((CharacterData)child).getData()); writeString("-->"); } else if (child instanceof Text) { writeSafeString(((Text)child).getData()); } } endElement(); }
From source file:org.apache.axis.message.MessageElement.java
/** * remove a an attribue//from ww w . j av a2 s. c om * @param oldAttr * @return oldAttr * @throws DOMException */ public Attr removeAttributeNode(Attr oldAttr) throws DOMException { makeAttributesEditable(); Name name = new PrefixedQName(oldAttr.getNamespaceURI(), oldAttr.getLocalName(), oldAttr.getPrefix()); removeAttribute(name); return oldAttr; }
From source file:org.apache.axis.message.MessageElement.java
/** * set an attribute as a node/*ww w .j a va 2s. c o m*/ * @see org.w3c.dom.Element#setAttributeNodeNS(org.w3c.dom.Attr) * @todo implement properly. * @param newAttr * @return null * @throws DOMException */ public Attr setAttributeNodeNS(Attr newAttr) throws DOMException { //attributes. AttributesImpl attributes = makeAttributesEditable(); // how to convert to DOM ATTR attributes.addAttribute(newAttr.getNamespaceURI(), newAttr.getLocalName(), newAttr.getLocalName(), "CDATA", newAttr.getValue()); return null; }
From source file:org.apache.axis2.jaxws.message.util.impl.XMLStreamReaderFromDOM.java
public QName getAttributeName(int index) { Attr attr = (Attr) getAttributes().get(index); return new QName(attr.getNamespaceURI(), attr.getLocalName()); }
From source file:org.apache.axis2.jaxws.message.util.impl.XMLStreamReaderFromDOM.java
public String getAttributeNamespace(int index) { Attr attr = (Attr) getAttributes().get(index); return attr.getNamespaceURI(); }
From source file:org.apache.cocoon.forms.util.DomHelper.java
private static Map addLocalNSDeclarations(Element elm, Map nsDeclarations) { NamedNodeMap atts = elm.getAttributes(); int attsSize = atts.getLength(); for (int i = 0; i < attsSize; i++) { Attr attr = (Attr) atts.item(i); if (XMLNS_URI.equals(attr.getNamespaceURI())) { String nsUri = attr.getValue(); String pfx = attr.getLocalName(); if (nsDeclarations == null) nsDeclarations = new HashMap(); nsDeclarations.put(nsUri, pfx); }/*from w w w . ja v a2s. com*/ } return nsDeclarations; }
From source file:org.apache.ode.il.OMUtils.java
public static OMElement toOM(Element src, OMFactory omf, OMContainer parent) { OMElement omElement = parent == null ? omf.createOMElement(src.getLocalName(), null) : omf.createOMElement(src.getLocalName(), null, parent); if (src.getNamespaceURI() != null) { if (src.getPrefix() != null) omElement.setNamespace(omf.createOMNamespace(src.getNamespaceURI(), src.getPrefix())); else//from w w w. jav a 2 s . c o m omElement.declareDefaultNamespace(src.getNamespaceURI()); } if (parent == null) { NSContext nscontext = DOMUtils.getMyNSContext(src); injectNamespaces(omElement, nscontext.toMap()); } else { Map<String, String> nss = DOMUtils.getMyNamespaces(src); injectNamespaces(omElement, nss); } NamedNodeMap attrs = src.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (attr.getLocalName().equals("xmlns") || (attr.getNamespaceURI() != null && attr.getNamespaceURI().equals(DOMUtils.NS_URI_XMLNS))) continue; OMNamespace attrOmNs = null; String attrNs = attr.getNamespaceURI(); String attrPrefix = attr.getPrefix(); if (attrNs != null) attrOmNs = omElement.findNamespace(attrNs, null); if (attrOmNs == null && attrPrefix != null) attrOmNs = omElement.findNamespace(null, attrPrefix); omElement.addAttribute(attr.getLocalName(), attr.getValue(), attrOmNs); } NodeList children = src.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); switch (n.getNodeType()) { case Node.CDATA_SECTION_NODE: omElement.addChild(omf.createOMText(((CDATASection) n).getTextContent(), XMLStreamConstants.CDATA)); break; case Node.TEXT_NODE: omElement.addChild(omf.createOMText(((Text) n).getTextContent(), XMLStreamConstants.CHARACTERS)); break; case Node.ELEMENT_NODE: toOM((Element) n, omf, omElement); break; } } return omElement; }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Test whether an attribute contains a namespace declaration. * @param a an {@link Attr} to test.// w ww . j a v a 2 s . c o m * @return <code>true</code> if the {@link Attr} is a namespace declaration */ public static boolean isNSAttribute(Attr a) { assert a != null; String s = a.getNamespaceURI(); return (s != null && s.equals(NS_URI_XMLNS)); }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Deep clone, but don't fry, the given node in the context of the given document. * For all intents and purposes, the clone is the exact same copy of the node, * except that it might have a different owner document. * * This method is fool-proof, unlike the <code>adoptNode</code> or <code>adoptNode</code> methods, * in that it doesn't assume that the given node has a parent or a owner document. * * @param document/* ww w .j a v a 2s.com*/ * @param sourceNode * @return a clone of node */ public static Node cloneNode(Document document, Node sourceNode) { Node clonedNode = null; // what is my name? QName sourceQName = getNodeQName(sourceNode); String nodeName = sourceQName.getLocalPart(); String namespaceURI = sourceQName.getNamespaceURI(); // if the node is unqualified, don't assume that it inherits the WS-BPEL target namespace if (Namespaces.WSBPEL2_0_FINAL_EXEC.equals(namespaceURI)) { namespaceURI = null; } switch (sourceNode.getNodeType()) { case Node.ATTRIBUTE_NODE: if (namespaceURI == null) { clonedNode = document.createAttribute(nodeName); } else { String prefix = ((Attr) sourceNode).lookupPrefix(namespaceURI); // the prefix for the XML namespace can't be looked up, hence this... if (prefix == null && namespaceURI.equals(NS_URI_XMLNS)) { prefix = "xmlns"; } // if a prefix exists, qualify the name with it if (prefix != null && !"".equals(prefix)) { nodeName = prefix + ":" + nodeName; } // create the appropriate type of attribute if (prefix != null) { clonedNode = document.createAttributeNS(namespaceURI, nodeName); } else { clonedNode = document.createAttribute(nodeName); } } break; case Node.CDATA_SECTION_NODE: clonedNode = document.createCDATASection(((CDATASection) sourceNode).getData()); break; case Node.COMMENT_NODE: clonedNode = document.createComment(((Comment) sourceNode).getData()); break; case Node.DOCUMENT_FRAGMENT_NODE: clonedNode = document.createDocumentFragment(); break; case Node.DOCUMENT_NODE: clonedNode = document; break; case Node.ELEMENT_NODE: // create the appropriate type of element if (namespaceURI == null) { clonedNode = document.createElement(nodeName); } else { String prefix = namespaceURI.equals(Namespaces.XMLNS_URI) ? "xmlns" : ((Element) sourceNode).lookupPrefix(namespaceURI); if (prefix != null && !"".equals(prefix)) { nodeName = prefix + ":" + nodeName; clonedNode = document.createElementNS(namespaceURI, nodeName); } else { clonedNode = document.createElement(nodeName); } } // attributes are not treated as child nodes, so copy them explicitly NamedNodeMap attributes = ((Element) sourceNode).getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attributeClone = (Attr) cloneNode(document, attributes.item(i)); if (attributeClone.getNamespaceURI() == null) { ((Element) clonedNode).setAttributeNode(attributeClone); } else { ((Element) clonedNode).setAttributeNodeNS(attributeClone); } } break; case Node.ENTITY_NODE: // TODO break; case Node.ENTITY_REFERENCE_NODE: clonedNode = document.createEntityReference(nodeName); // TODO break; case Node.NOTATION_NODE: // TODO break; case Node.PROCESSING_INSTRUCTION_NODE: clonedNode = document.createProcessingInstruction(((ProcessingInstruction) sourceNode).getData(), nodeName); break; case Node.TEXT_NODE: clonedNode = document.createTextNode(((Text) sourceNode).getData()); break; default: break; } // clone children of element and attribute nodes NodeList sourceChildren = sourceNode.getChildNodes(); if (sourceChildren != null) { for (int i = 0; i < sourceChildren.getLength(); i++) { Node sourceChild = sourceChildren.item(i); Node clonedChild = cloneNode(document, sourceChild); clonedNode.appendChild(clonedChild); // if the child has a textual value, parse it for any embedded prefixes if (clonedChild.getNodeType() == Node.TEXT_NODE || clonedChild.getNodeType() == Node.CDATA_SECTION_NODE) { parseEmbeddedPrefixes(sourceNode, clonedNode, clonedChild); } } } return clonedNode; }
From source file:org.apache.openejb.server.axis.assembler.CommonsSchemaInfoBuilder.java
/** * Extract the nested component type of an Array from the XML Schema Type. * * @return the QName of the nested component type or null if the schema type can not be determined * @throws org.apache.openejb.OpenEJBException if the XML Schema Type can not represent an Array @param complexType *///from ww w . jav a 2s . c o m private static QName extractSoapArrayComponentType(XmlSchemaComplexType complexType) { // Soap arrays are based on complex content restriction if (!isSoapArray(complexType)) { return null; } XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) complexType .getContentModel().getContent(); //First, handle case that looks like this: // <complexType name="ArrayOfstring"> // <complexContent> // <restriction base="soapenc:Array"> // <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/> // </restriction> // </complexContent> // </complexType> XmlSchemaObjectCollection attributes = restriction.getAttributes(); for (Iterator iterator = attributes.getIterator(); iterator.hasNext();) { Object item = iterator.next(); if (item instanceof XmlSchemaAttribute) { XmlSchemaAttribute attribute = (XmlSchemaAttribute) item; if (attribute.getRefName().equals(SOAP_ARRAY_TYPE)) { for (Attr attr : attribute.getUnhandledAttributes()) { QName attQName = new QName(attr.getNamespaceURI(), attr.getLocalName()); if (WSDL_ARRAY_TYPE.equals(attQName)) { // value is a namespace prefixed xsd type String value = attr.getValue(); // extract local part int pos = value.lastIndexOf(":"); QName componentType; if (pos < 0) { componentType = new QName("", value); } else { String localPart = value.substring(pos + 1); // resolve the namespace prefix String prefix = value.substring(0, pos); String namespace = getNamespaceForPrefix(prefix, attr.getOwnerElement()); componentType = new QName(namespace, localPart); } log.debug("determined component type from element type"); return componentType; } } } } } // If that didn't work, try to handle case like this: // <complexType name="ArrayOfstring1"> // <complexContent> // <restriction base="soapenc:Array"> // <sequence> // <element name="string1" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/> // </sequence> // </restriction> // </complexContent> // </complexType> XmlSchemaParticle particle = restriction.getParticle(); if (particle instanceof XmlSchemaSequence) { XmlSchemaSequence sequence = (XmlSchemaSequence) particle; if (sequence.getItems().getCount() != 1) { throw new IllegalArgumentException("more than one element inside array definition: " + complexType); } XmlSchemaObject item = sequence.getItems().getItem(0); if (item instanceof XmlSchemaElement) { XmlSchemaElement element = (XmlSchemaElement) item; QName componentType = element.getSchemaTypeName(); log.debug("determined component type from element type"); return componentType; } } return null; }