Example usage for org.jsoup.nodes DataNode setWholeData

List of usage examples for org.jsoup.nodes DataNode setWholeData

Introduction

In this page you can find the example usage for org.jsoup.nodes DataNode setWholeData.

Prototype

public DataNode setWholeData(String data) 

Source Link

Document

Set the data contents of this node.

Usage

From source file:psef.handler.HTMLFilter.java

/**
 * Revise all "style" statements with @import directives
 * @param doc the DOM document//from   w  w w  .ja v a  2  s.  c  om
 * @throws PsefException 
 */
private void filterStyles(Document doc) throws PsefException {
    try {
        Elements styles = doc.getElementsByTag("style");
        for (Element style : styles) {
            List<DataNode> data = style.dataNodes();
            String styleText = "";
            StringBuilder sb = new StringBuilder();
            for (DataNode node : data) {
                styleText = node.getWholeData();
                int pos = readAtImport(styleText);
                while (pos > 0) {
                    sb.append("@import ");
                    styleText = styleText.substring(pos);
                    CSSUrl cssu = new CSSUrl(styleText);
                    styleText = styleText.substring(cssu.getPos());
                    cssu.revise(host, base + relPath, "styles");
                    URL u = new URL(cssu.getUrl(host, base + relPath));
                    downloadResource(u, cssu.getLocalPath());
                    sb.append(cssu.toString());
                    sb.append("\n");
                    pos = readAtImport(styleText);
                }
                node.setWholeData(sb.toString());
            }
            sb.append(styleText);
            //style.( sb.toString() );
        }
    } catch (Exception e) {
        throw new PsefException(e);
    }
}