use of com.gargoylesoftware.htmlunit.css.StyleElement in project htmlunit by HtmlUnit.
the class NamedAttrNodeMapImpl method replaceStyleAttribute.
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
*
* Replaces the value of the named style attribute. If there is no style attribute with the
* specified name, a new one is added. If the specified value is an empty (or all whitespace)
* string, this method actually removes the named style attribute.
* @param name the attribute name (delimiter-separated, not camel-cased)
* @param value the attribute value
* @param priority the new priority of the property; <code>"important"</code>or the empty string if none.
*/
public void replaceStyleAttribute(final String name, final String value, final String priority) {
if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
removeStyleAttribute(name);
return;
}
final Map<String, StyleElement> styleMap = getStyleMap();
final StyleElement old = styleMap.get(name);
final StyleElement element;
if (old == null) {
element = new StyleElement(name, value, priority, SelectorSpecificity.FROM_STYLE_ATTRIBUTE);
} else {
element = new StyleElement(name, value, priority, SelectorSpecificity.FROM_STYLE_ATTRIBUTE, old.getIndex());
}
styleMap.put(name, element);
writeStyleToElement(styleMap);
}
use of com.gargoylesoftware.htmlunit.css.StyleElement in project htmlunit by HtmlUnit.
the class NamedAttrNodeMapImpl method writeStyleToElement.
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
*
* @param styleMap the styles
*/
public void writeStyleToElement(final Map<String, StyleElement> styleMap) {
final StringBuilder builder = new StringBuilder();
final SortedSet<StyleElement> sortedValues = new TreeSet<>(styleMap.values());
for (final StyleElement e : sortedValues) {
if (builder.length() != 0) {
builder.append(' ');
}
builder.append(e.getName());
builder.append(": ");
builder.append(e.getValue());
final String prio = e.getPriority();
if (org.apache.commons.lang3.StringUtils.isNotBlank(prio)) {
builder.append(" !");
builder.append(prio);
}
builder.append(';');
}
final String value = builder.toString();
setAttribute("style", value);
}
Aggregations