/** * Returns whether the attribute specified by name has a value. * * @param attributeName the name of the attribute * @return true if an attribute with the given name is specified on this element or has a * default value, false otherwise. */ @Override public boolean hasAttribute(final String attributeName) { return attributes_.containsKey(attributeName); }
/** * {@inheritDoc} */ @Override public DomNode cloneNode(final boolean deep) { final DomElement clone = (DomElement) super.cloneNode(deep); clone.attributes_ = new NamedAttrNodeMapImpl(clone, isAttributeCaseSensitive()); clone.attributes_.putAll(attributes_); return clone; }
/** * Creates an instance of a DOM element that can have a namespace. * * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name of the element type to instantiate * @param page the page that contains this element * @param attributes a map ready initialized with the attributes for this element, or * <code>null</code>. The map will be stored as is, not copied. */ public DomElement(final String namespaceURI, final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { super(namespaceURI, qualifiedName, page); if (attributes != null && !attributes.isEmpty()) { attributes_ = new NamedAttrNodeMapImpl(this, isAttributeCaseSensitive(), attributes); for (final DomAttr entry : attributes_.values()) { entry.setParentNode(this); final String attrNamespaceURI = entry.getNamespaceURI(); if (attrNamespaceURI != null) { namespaces_.put(attrNamespaceURI, entry.getPrefix()); } } } }
/** * {@inheritDoc} */ @Override public DomAttr getAttributeNode(final String name) { return attributes_.get(name); }
/** * {@inheritDoc} */ @Override public DomAttr put(String key, final DomAttr value) { key = fixName(key); if (!containsKey(key)) { attrPositions_.add(key); } return super.put(key, value); }
/** * Sets the value of the attribute specified by namespace and qualified name. * * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name (prefix:local) of the attribute * @param attributeValue the value of the attribute */ public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { final String value = attributeValue; if (attributes_ == NamedAttrNodeMapImpl.EMPTY_MAP) { attributes_ = new NamedAttrNodeMapImpl(this, isAttributeCaseSensitive()); } final DomAttr newAttr = new DomAttr(getPage(), namespaceURI, qualifiedName, value); newAttr.setParentNode(this); attributes_.put(qualifiedName, newAttr); if (namespaceURI != null) { namespaces().put(namespaceURI, newAttr.getPrefix()); } }
/** * {@inheritDoc} */ @Override public DomAttr setNamedItem(final Node node) { return put(node.getLocalName(), (DomAttr) node); }
/** * Prints the content between "<" and ">" (or "/>") in the output of the tag name * and its attributes in XML format. * @param printWriter the writer to print in */ protected void printOpeningTagContentAsXml(final PrintWriter printWriter) { printWriter.print(getTagName()); for (final String name : attributes_.keySet()) { printWriter.print(" "); printWriter.print(name); printWriter.print("=\""); printWriter.print(StringEscapeUtils.escapeXml(attributes_.get(name).getNodeValue())); printWriter.print("\""); } }
/** * {@inheritDoc} */ @Override public boolean containsKey(final Object key) { if (key instanceof String) { final String name = fixName((String) key); return map_.containsKey(name); } return false; }
/** * Removes an attribute specified by name from this element. * @param attributeName the attribute attributeName */ @Override public void removeAttribute(final String attributeName) { attributes_.remove(attributeName); }
/** * {@inheritDoc} */ @Override public int getLength() { return size(); }
/** * {@inheritDoc} */ @Override public final boolean hasAttributes() { return !attributes_.isEmpty(); }
NamedAttrNodeMapImpl(final DomElement domNode, final boolean caseSensitive, final Map<String, DomAttr> attributes) { this(domNode, caseSensitive); putAll(attributes); }
/** * {@inheritDoc} */ @Override public DomNode cloneNode(final boolean deep) { final DomElement clone = (DomElement) super.cloneNode(deep); clone.attributes_ = new NamedAttrNodeMapImpl(clone, isAttributeCaseSensitive()); clone.attributes_.putAll(attributes_); return clone; } }
/** * Creates an instance of a DOM element that can have a namespace. * * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name of the element type to instantiate * @param page the page that contains this element * @param attributes a map ready initialized with the attributes for this element, or * <code>null</code>. The map will be stored as is, not copied. */ public DomElement(final String namespaceURI, final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { super(namespaceURI, qualifiedName, page); if (attributes != null && !attributes.isEmpty()) { attributes_ = new NamedAttrNodeMapImpl(this, isAttributeCaseSensitive(), attributes); for (final DomAttr entry : attributes_.values()) { entry.setParentNode(this); final String attrNamespaceURI = entry.getNamespaceURI(); if (attrNamespaceURI != null) { namespaces_.put(attrNamespaceURI, entry.getPrefix()); } } } }
/** * {@inheritDoc} */ @Override public DomAttr getNamedItem(final String name) { return get(name); }