return;
}
}
//Create buffer and estimate the new size
HtmlStringBuffer buffer = new HtmlStringBuffer(
oldStyles.length() + 10);
//Parse the current styles into a map
Map stylesMap = parseStyles(oldStyles);
//Check if the new style is already present
if (stylesMap.containsKey(name)) {
//If the style is present and the value is null, remove the style,
//otherwise replace it with the new value
if (value == null) {
stylesMap.remove(name);
} else {
stylesMap.put(name, value);
}
} else {
stylesMap.put(name, value);
}
//The styles map might be empty if the last style was removed
if (stylesMap.isEmpty()) {
getAttributes().remove("style");
return;
}
//Iterate over the stylesMap appending each entry to buffer
Iterator it = stylesMap.entrySet().iterator();
while (it.hasNext()) {
Entry entry = (Entry) it.next();
String styleName = String.valueOf(entry.getKey());
String styleValue = String.valueOf(entry.getValue());
buffer.append(styleName);
buffer.append(":");
buffer.append(styleValue);
buffer.append(";");
}
getAttributes().put("style", buffer.toString());
}