MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / getStyleMap

Method getStyleMap

src/main/java/org/htmlunit/html/DomElement.java:290–328  ·  view source on GitHub ↗

INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. Returns a sorted map containing style elements, keyed on style element name. We use a LinkedHashMap map so that results are deterministic and are thus testable. @return a sorted map cont

()

Source from the content-addressed store, hash-verified

288 * @return a sorted map containing style elements, keyed on style element name
289 */
290 public LinkedHashMap<String, StyleElement> getStyleMap() {
291 final String styleAttribute = getAttributeDirect("style");
292 if (styleString_ == styleAttribute) {
293 return styleMap_;
294 }
295
296 final LinkedHashMap<String, StyleElement> styleMap = new LinkedHashMap<>();
297 if (ATTRIBUTE_NOT_DEFINED == styleAttribute || ATTRIBUTE_VALUE_EMPTY == styleAttribute) {
298 styleMap_ = styleMap;
299 styleString_ = styleAttribute;
300 return styleMap_;
301 }
302
303 final CSSStyleDeclarationImpl cssStyle = new CSSStyleDeclarationImpl(null);
304 try {
305 // use the configured cssErrorHandler here to do the same error handling during
306 // parsing of inline styles like for external css
307 cssStyle.setCssText(styleAttribute, getPage().getWebClient().getCssErrorHandler());
308 }
309 catch (final Exception e) {
310 if (LOG.isErrorEnabled()) {
311 LOG.error("Error while parsing style value '" + styleAttribute + "'", e);
312 }
313 }
314
315 for (final Property prop : cssStyle.getProperties()) {
316 final String key = prop.getName().toLowerCase(Locale.ROOT);
317 final StyleElement element = new StyleElement(key,
318 prop.getValue().getCssText(),
319 prop.isImportant() ? StyleElement.PRIORITY_IMPORTANT : "",
320 SelectorSpecificity.FROM_STYLE_ATTRIBUTE);
321 styleMap.put(key, element);
322 }
323
324 styleMap_ = styleMap;
325 styleString_ = styleAttribute;
326 // styleString_ = cssStyle.getCssText();
327 return styleMap_;
328 }
329
330 /**
331 * Prints the content between "&lt;" and "&gt;" (or "/&gt;") in the output of the tag name

Callers 4

replaceStyleAttributeMethod · 0.95
removeStyleAttributeMethod · 0.95
getStyleElementMethod · 0.95

Calls 12

getAttributeDirectMethod · 0.95
getCssErrorHandlerMethod · 0.80
isImportantMethod · 0.80
getWebClientMethod · 0.65
getPageMethod · 0.65
isErrorEnabledMethod · 0.65
errorMethod · 0.65
getNameMethod · 0.65
setCssTextMethod · 0.45
getCssTextMethod · 0.45
getValueMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected