public OMElement createOMElement(String localName, OMNamespace ns, OMContainer parent) throws OMDOMException { if (parent == null) { return new ElementImpl((DocumentImpl) this.createOMDocument(), localName, (NamespaceImpl) ns, this); } switch (((ParentNode) parent).getNodeType()) { case Node.ELEMENT_NODE: // We are adding a new child to an elem ElementImpl parentElem = (ElementImpl) parent; ElementImpl elem = new ElementImpl((DocumentImpl) parentElem .getOwnerDocument(), localName, (NamespaceImpl) ns, this); parentElem.appendChild(elem); return elem; case Node.DOCUMENT_NODE: DocumentImpl docImpl = (DocumentImpl) parent; return new ElementImpl(docImpl, localName, (NamespaceImpl) ns, this); case Node.DOCUMENT_FRAGMENT_NODE: DocumentFragmentImpl docFragImpl = (DocumentFragmentImpl) parent; return new ElementImpl((DocumentImpl) docFragImpl .getOwnerDocument(), localName, (NamespaceImpl) ns, this); default: throw new OMDOMException( "The parent container can only be an ELEMENT, DOCUMENT " + "or a DOCUMENT FRAGMENT"); } }
/** * 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 OMText createOMText(OMContainer parent, char[] charArary, int type) { ElementImpl parentElem = (ElementImpl) parent; TextImpl txt = new TextImpl((DocumentImpl) parentElem .getOwnerDocument(), charArary, this); parentElem.addChild(txt); return txt; }
/** @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; }
public void buildWithAttachments() { if (!done) { this.build(); } Iterator iterator = getChildren(); while (iterator.hasNext()) { OMNode node = (OMNode) iterator.next(); node.buildWithAttachments(); } } }
/** @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); } }
this.declareNamespace(attr.getName(), attr.getValue()); return attr; } else { if (!this.getOwnerDocument().equals(attr.getOwnerDocument())) { String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, if (this.isReadonly()) { String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, && findNamespace(attr.getNamespaceURI(), attr.getPrefix()) == null) { this.declareNamespace(new NamespaceImpl(attr.getNamespaceURI(), attr.getPrefix()));
if (!this.getOwnerDocument().equals(attr.getOwnerDocument())) { String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", if (this.isReadonly()) { String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, this.declareNamespace(attr.getNodeValue(), DOMUtil .getLocalName(attr.getName())); this.declareDefaultNamespace(attr.getValue());
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)); } }
/** * 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); } }
/** * Creates a text node with the given value and adds it to the element. * * @see org.apache.axiom.om.OMElement#setText(String) */ public void setText(String text) { if (this.isReadonly()) { String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); } // if we already have other text nodes remove them OMNode child = this.getFirstOMChild(); while (child != null) { if (child.getType() == OMNode.TEXT_NODE) { child.detach(); } child = child.getNextOMSibling(); } TextImpl textNode = (TextImpl) (this.ownerNode) .createTextNode(text); this.addChild(textNode); }
public Element createElement(String tagName) throws DOMException { return new ElementImpl(this, tagName, this.factory); }
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 void discard() throws OMException { if (done) { this.detach(); } else { builder.discard(this); } }
/** * Creates a clone which belongs to a new document. * * @see org.apache.axiom.om.OMElement#cloneOMElement() */ public OMElement cloneOMElement() { return (ElementImpl) this.cloneNode(true); }
/** * Allows overriding an existing declaration if the same prefix was used. * * @see org.apache.axiom.om.OMElement#declareNamespace (org.apache.axiom.om.OMNamespace) */ public OMNamespace declareNamespace(OMNamespace namespace) { if (namespaces == null) { this.namespaces = new HashMap(5); } if (namespace != null) { String prefix = namespace.getPrefix(); if ("".equals(prefix)) { namespace = declareDefaultNamespace(namespace.getNamespaceURI()); } else if (prefix == null) { prefix = OMSerializerUtil.getNextNSPrefix(); namespace = new NamespaceImpl(namespace.getNamespaceURI(), prefix); } if (!namespace.getPrefix().startsWith(OMConstants.XMLNS_NS_PREFIX)) { namespaces.put(namespace.getPrefix(), namespace); } } return namespace; }
public Document parse(InputSource inputSource) throws SAXException, IOException { try { OMDOMFactory factory = new OMDOMFactory(); // Not really sure whether this will work :-? XMLStreamReader reader = StAXUtils .createXMLStreamReader(inputSource.getCharacterStream()); StAXOMBuilder builder = new StAXOMBuilder(factory, reader); DocumentImpl doc = (DocumentImpl) builder.getDocument(); ((ElementImpl) doc.getDocumentElement()).build(); return (DocumentImpl) builder.getDocument(); } catch (XMLStreamException e) { throw new SAXException(e); } }
public OMElement createOMElement(String localName, OMNamespace ns) { return new ElementImpl((DocumentImpl) this.createOMDocument(), localName, (NamespaceImpl) ns, 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); }
/** * Returns an <code>Iterator</code> over all the <code>SOAPHeaderBlock</code> objects in this * <code>SOAPHeader </code> object and detaches them from this <code>SOAPHeader</code> object. * * @return an <code>Iterator</code> object over all the <code>SOAPHeaderBlock</code> objects * contained by this <code>SOAPHeader</code> */ public Iterator extractAllHeaderBlocks() { Collection result = new ArrayList(); for (Iterator iter = getChildrenWithName(null); iter.hasNext();) { result.add(((ElementImpl) iter.next()).detach()); } return result.iterator(); }