Example usage for org.w3c.dom.css CSSStyleDeclaration getCssText

List of usage examples for org.w3c.dom.css CSSStyleDeclaration getCssText

Introduction

In this page you can find the example usage for org.w3c.dom.css CSSStyleDeclaration getCssText.

Prototype

public String getCssText();

Source Link

Document

The parsable textual representation of the declaration block (excluding the surrounding curly braces).

Usage

From source file:com.xpn.xwiki.pdf.impl.PdfExportImpl.java

/**
 * Recursively inline the computed style that applies to a DOM Element into the {@code style} attribute of that
 * Element.// ww w  .j  av a 2  s.  c o m
 * 
 * @param element the Element whose style should be inlined
 */
private void applyInlineStyle(Element element) {
    for (int i = 0; i < element.nodeCount(); i++) {
        org.dom4j.Node node = element.node(i);
        if (node instanceof CSSStylableElement) {
            CSSStylableElement styleElement = (CSSStylableElement) node;
            CSSStyleDeclaration style = styleElement.getComputedStyle();
            if (style != null && StringUtils.isNotEmpty(style.getCssText())) {
                styleElement.addAttribute("style", styleElement.getComputedStyle().getCssText());
            }
        }
        if (node instanceof Element) {
            applyInlineStyle((Element) node);
        }
    }
}