} else if (rl.item(i).getType() == org.w3c.dom.css.CSSRule.PAGE_RULE) { CSSPageRule cssPageRule = (CSSPageRule) rl.item(i); Ruleset pageRules = new Ruleset(new CSSPageRuleAdapter(cssPageRule), stylesheet.getOrigin()); stylesheet.addPageRuleset(pageRules);
    private void pullRulesets(CSSRuleList rl, Stylesheet stylesheet, StylesheetInfo sheetInfo) {        int nr = rl.getLength();        for (int i = 0; i < nr; i++) {            if (rl.item(i).getType() == org.w3c.dom.css.CSSRule.STYLE_RULE) {                stylesheet.addRuleset(new Ruleset((org.w3c.dom.css.CSSStyleRule) rl.item(i), stylesheet.getOrigin()));            } else if (rl.item(i).getType() == org.w3c.dom.css.CSSRule.IMPORT_RULE) {                //note: the steadystate parser does not fetch and load imported stylesheets                CSSImportRule cssir = (CSSImportRule) rl.item(i);                String href = cssir.getHref();                MediaList mediaList = cssir.getMedia();                String media = mediaList.getMediaText();                if (media.equals("")) {                    media = sheetInfo.getMedia();                }                String uri = null;                try {                    uri = new java.net.URL(new URL(stylesheet.getURI()), href).toString();                    StylesheetInfo info = new StylesheetInfo();                    info.setOrigin(stylesheet.getOrigin());                    info.setUri(uri);                    info.setMedia(media);                    info.setType("text/css");                    stylesheet.addStylesheet(info);                } catch (java.net.MalformedURLException e) {                    XRLog.exception("bad URL for imported stylesheet", e);                }            } else if (rl.item(i).getType() == org.w3c.dom.css.CSSRule.MEDIA_RULE) {                //create a "dummy" stylesheet                CSSMediaRule cssmr = (CSSMediaRule) rl.item(i);                StylesheetInfo info = new StylesheetInfo();                info.setMedia(cssmr.getMedia().getMediaText());                info.setOrigin(stylesheet.getOrigin());                info.setType("text/css");                Stylesheet mr = new Stylesheet(info.getUri(), info.getOrigin());                info.setStylesheet(mr);//there, the "dummy" connection is made                pullRulesets(cssmr.getCssRules(), mr, info);                stylesheet.addStylesheet(info);            }        }    }