public ElementImpl(DocumentImpl ownerDocument, String tagName, NamespaceImpl ns, OMXMLParserWrapper builder, OMFactory factory) { super(ownerDocument, factory); this.localName = tagName; this.namespace = ns; this.builder = builder; this.declareNamespace(ns); this.attributes = new AttributeMap(this); }
public ElementImpl(String tagName, NamespaceImpl ns, OMXMLParserWrapper builder, OMFactory factory) { this(factory); this.localName = tagName; this.namespace = ns; this.builder = builder; if (ns != null) { this.declareNamespace(ns); } this.attributes = new AttributeMap(this); }
/** * Creates a new element with the namespace. * * @param ownerDocument * @param tagName * @param ns */ public ElementImpl(DocumentImpl ownerDocument, String tagName, NamespaceImpl ns, OMFactory factory) { super(ownerDocument, factory); this.localName = tagName; this.namespace = ns; this.declareNamespace(ns); this.attributes = new AttributeMap(this); this.done = true; }
/** * Allows overriding an existing declaration if the same prefix was used. * * @see org.apache.axiom.om.OMElement#declareNamespace(String, String) */ public OMNamespace declareNamespace(String uri, String prefix) { if (prefix == null) { prefix = OMSerializerUtil.getNextNSPrefix(); } NamespaceImpl ns = new NamespaceImpl(uri, prefix); return declareNamespace(ns); }
/** @see org.apache.axiom.om.OMElement#findNamespace(String, String) */ public OMNamespace findNamespace(String uri, String prefix) { // check in the current element OMNamespace namespace = findDeclaredNamespace(uri, prefix); if (namespace != null) { return namespace; } // go up to check with ancestors if (this.parentNode != null) { // For the OMDocumentImpl there won't be any explicit namespace // declarations, so going up the parent chain till the document // element should be enough. if (parentNode instanceof OMElement) { namespace = ((ElementImpl) parentNode).findNamespace(uri, prefix); } } if (namespace == null && uri != null && prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX) && uri.equals(OMConstants.XMLNS_URI)) { declareNamespace(OMConstants.XMLNS_URI, OMConstants.XMLNS_PREFIX); namespace = findNamespace(uri, prefix); } return namespace; }
/** @see org.apache.axiom.om.OMElement#addAttribute (org.apache.axiom.om.OMAttribute) */ public OMAttribute addAttribute(OMAttribute attr) { OMNamespace namespace = attr.getNamespace(); if (namespace != null && namespace.getNamespaceURI() != null && !"".equals(namespace.getNamespaceURI()) && this.findNamespace(namespace.getNamespaceURI(), namespace .getPrefix()) == null) { this.declareNamespace(namespace.getNamespaceURI(), namespace.getPrefix()); } if (attr.getNamespace() != null) { // If the attr has a namespace return (AttrImpl) this.setAttributeNode((Attr) attr); } else { return (AttrImpl) this.setAttributeNodeNS((Attr) attr); } }
/** * The behaviour of this is the same as org.w3c.dom.Element#setAttributeNS * * @see org.apache.axiom.om.OMElement#addAttribute(String, String, org.apache.axiom.om.OMNamespace) */ public OMAttribute addAttribute(String attributeName, String value, OMNamespace ns) { if (ns != null && findNamespace(ns.getNamespaceURI(), ns.getPrefix()) != null) { declareNamespace(ns); } if (ns != null) { return this.addAttribute(ns.getNamespaceURI(), ns.getPrefix() + ":" + attributeName, value); } else { return this.addAttribute(null, attributeName, value); } }
public void setAttribute(String name, String value) throws DOMException { // Check for invalid charaters if (!DOMUtil.isQualifiedName(name)) { String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null); throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg); } if (name.startsWith(OMConstants.XMLNS_NS_PREFIX + ":")) { // This is a ns declaration this.declareNamespace(value, DOMUtil.getLocalName(name)); } else if (name.equals(OMConstants.XMLNS_NS_PREFIX)) { this.declareDefaultNamespace(value); } else { this.setAttributeNode(new AttrImpl(this.ownerNode, name, value, this.factory)); } }
this.declareNamespace(attr.getName(), attr.getValue()); return attr; } else { this.declareNamespace(new NamespaceImpl(attr.getNamespaceURI(), attr.getPrefix()));
/** * Adds a new attribute. * * @see org.w3c.dom.Element#setAttributeNS(String, String, String) */ public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException { if (namespaceURI != null && !"".equals(namespaceURI)) { if (namespaceURI.equals(OMConstants.XMLNS_NS_URI)) { this.declareNamespace(value, DOMUtil .getLocalName(qualifiedName)); } else { AttrImpl attr = new AttrImpl(this.ownerNode, DOMUtil .getLocalName(qualifiedName), value, this.factory); attr.setOMNamespace(new NamespaceImpl(namespaceURI, DOMUtil .getPrefix(qualifiedName))); this.setAttributeNodeNS(attr); } } else { // When the namespace is null, the attr name given better not be // a qualified name // But anyway check and set it this.setAttribute(DOMUtil.getLocalName(qualifiedName), value); } }
this.declareNamespace(attr.getNodeValue(), DOMUtil .getLocalName(attr.getName()));