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
()
| 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 "<" and ">" (or "/>") in the output of the tag name |
no test coverage detected