/** * Returns attribute value. Returns <code>null</code> when * attribute doesn't exist or when attribute exist but doesn't * specify a value. */ public String getAttribute(final String name) { Attribute attribute = getAttributeInstance(name); if (attribute == null) { return null; } return attribute.getValue(); }
/** * Sets attribute value. Value may be <code>null</code>. */ public void setAttribute(String name, final String value) { initAttributes(); String rawAttributeName = name; if (!ownerDocument.config.isCaseSensitive()) { name = name.toLowerCase(); } // search if attribute with the same name exist for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) { Attribute attr = attributes.get(i); if (attr.getName().equals(name)) { attr.setValue(value); return; } } attributes.add(new Attribute(rawAttributeName, name, value)); }
/** * Copies all non-final values to the empty cloned object. * Cache-related values are not copied. */ protected <T extends Node> T cloneTo(final T dest) { // dest.nodeValue = nodeValue; // already in clone implementations! dest.parentNode = parentNode; if (attributes != null) { dest.attributes = new ArrayList<>(attributes.size()); for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) { Attribute attr = attributes.get(i); dest.attributes.add(attr.clone()); } } if (childNodes != null) { dest.childNodes = new ArrayList<>(childNodes.size()); for (int i = 0, childNodesSize = childNodes.size(); i < childNodesSize; i++) { Node child = childNodes.get(i); Node childClone = child.clone(); childClone.parentNode = dest; // fix parent! dest.childNodes.add(childClone); } } return dest; }
/** * Renders attribute name. */ protected String resolveAttributeName(final Node node, final Attribute attribute) { switch (attributeCase) { case DEFAULT: return attribute.getName(); case RAW: return attribute.getRawName(); case LOWERCASE: return attribute.getRawName().toLowerCase(); case UPPERCASE: return attribute.getRawName().toUpperCase(); } return null; }
protected int indexOfAttributeInstance(String name) { if (attributes == null) { return -1; } if (!ownerDocument.config.isCaseSensitive()) { name = name.toLowerCase(); } for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) { Attribute attr = attributes.get(i); if (attr.getName().equals(name)) { return i; } } return -1; }
/** * Sets attribute value. Value may be <code>null</code>. */ public void setAttribute(String name, String value) { initAttributes(); if (!caseSensitive) { name = name.toLowerCase(); } // search if attribute with the same name exist int nameHash = name.hashCode(); for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) { Attribute attr = attributes.get(i); if (attr.equalsName(name, nameHash)) { attr.setValue(value); return; } } attributes.add(new Attribute(name, value, true)); }
@Override public Attribute clone() { return new Attribute(rawName, name, value); }
@Override protected String resolveAttributeName(Node node, Attribute attribute) { String attributeName = attribute.getRawName(); if (attributeName.contains("_") || attributeName.contains("-")) { return attributeName; } return super.resolveAttributeName(node, attribute); }
/** * Returns <code>true</code> if attribute containing some word. */ public boolean isAttributeContaining(final String name, final String word) { Attribute attr = getAttributeInstance(name); if (attr == null) { return false; } return attr.isContaining(word); }
/** * Renders attribute name. */ protected String resolveAttributeName(final Node node, final Attribute attribute) { switch (attributeCase) { case DEFAULT: return attribute.getName(); case RAW: return attribute.getRawName(); case LOWERCASE: return attribute.getRawName().toLowerCase(); case UPPERCASE: return attribute.getRawName().toUpperCase(); } return null; }
protected Attribute getAttributeInstance(String name) { if (attributes == null) { return null; } if (!ownerDocument.config.isCaseSensitive()) { name = name.toLowerCase(); } for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) { Attribute attr = attributes.get(i); if (attr.getName().equals(name)) { return attr; } } return null; }
@Override public Attribute clone() { return new Attribute(rawName, name, value); }
/** * Returns <code>true</code> if attribute containing some word. */ public boolean isAttributeContaining(final String name, final String word) { Attribute attr = getAttributeInstance(name); if (attr == null) { return false; } return attr.isContaining(word); }
/** * Sets attribute value. Value may be <code>null</code>. */ public void setAttribute(String name, final String value) { initAttributes(); String rawAttributeName = name; if (!ownerDocument.config.isCaseSensitive()) { name = name.toLowerCase(); } // search if attribute with the same name exist for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) { Attribute attr = attributes.get(i); if (attr.getName().equals(name)) { attr.setValue(value); return; } } attributes.add(new Attribute(rawAttributeName, name, value)); }
/** * Renders attribute. */ protected void renderAttribute(final Node node, final Attribute attribute, final Appendable appendable) throws IOException { String name = resolveAttributeName(node, attribute); String value = attribute.getValue(); appendable.append(name); if (value != null) { appendable.append('='); appendable.append('\"'); appendable.append(HtmlEncoder.attributeDoubleQuoted(value)); appendable.append('\"'); } }
/** * Renders attribute name. */ protected String resolveAttributeName(Node node, Attribute attribute) { switch (attributeCase) { case DEFAULT: return attribute.getName(); case RAW: return attribute.getRawName(); case LOWERCASE: return attribute.getRawName().toLowerCase(); case UPPERCASE: return attribute.getRawName().toUpperCase(); } return null; }
/** * Returns <code>true</code> if node contains an attribute. */ public boolean hasAttribute(String name) { if (attributes == null) { return false; } if (!ownerDocument.config.isCaseSensitive()) { name = name.toLowerCase(); } for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) { Attribute attr = attributes.get(i); if (attr.getName().equals(name)) { return true; } } return false; }
@Override public Attribute clone() { return new Attribute(name, value, false); }
/** * Copies all non-final values to the empty cloned object. * Cache-related values are not copied. */ protected <T extends Node> T cloneTo(final T dest) { // dest.nodeValue = nodeValue; // already in clone implementations! dest.parentNode = parentNode; if (attributes != null) { dest.attributes = new ArrayList<>(attributes.size()); for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) { Attribute attr = attributes.get(i); dest.attributes.add(attr.clone()); } } if (childNodes != null) { dest.childNodes = new ArrayList<>(childNodes.size()); for (int i = 0, childNodesSize = childNodes.size(); i < childNodesSize; i++) { Node child = childNodes.get(i); Node childClone = child.clone(); childClone.parentNode = dest; // fix parent! dest.childNodes.add(childClone); } } return dest; }