try {   org.apache.xpath.objects.XObject xo = XPathAPI.eval(doc.getDocumentElement(), " org.w3c.dom.NodeList nl = xo.nodelist(); for (int i = 0, len = nl.getLength(); i < len; i++) { StylesheetInfo info = new StylesheetInfo(); info.setOrigin(StylesheetInfo.AUTHOR); org.w3c.dom.Element link = (org.w3c.dom.Element) nl.item(i); String a = link.getAttribute("rel"); if (a.indexOf("alternate") != -1) continue; a = link.getAttribute("type"); if ("".equals(a)) a = "text/css"; info.setType(a); a = link.getAttribute("href"); info.setUri(a); a = link.getAttribute("media"); if ("".equals(a)) a = "screen"; info.setMedia(a); a = link.getAttribute("title"); info.setTitle(a); if (info.getType().equals("text/css")) list.add(info); } } catch (Exception ex) { ex.printStackTrace();
org.w3c.dom.NodeList nl = null; for (int i = 0; i < 1; i++) { Element html = doc.getDocumentElement(); nl = html.getElementsByTagName("head"); if (nl.getLength() == 0) break; nl = ((Element) nl.item(0)).getElementsByTagName("link"); } for (int i = 0, len = nl.getLength(); i < len; i++) { Element link = (Element) nl.item(i); if (!link.getAttribute("rel").equals("stylesheet")) continue; StylesheetInfo info = new StylesheetInfo(); info.setOrigin(StylesheetInfo.AUTHOR); String a = link.getAttribute("rel"); if (a.indexOf("alternate") != -1) continue; a = link.getAttribute("type"); if ("".equals(a)) a = "text/css"; info.setType(a); a = link.getAttribute("href"); info.setUri(a); a = link.getAttribute("media"); if ("".equals(a)) a = "screen"; info.setMedia(a); a = link.getAttribute("title"); info.setTitle(a); if (info.getType().equals("text/css")) list.add(info);
    public StylesheetInfo[] getStylesheetLinks(org.w3c.dom.Document doc) {        List list = new ArrayList();        //get the processing-instructions (actually for XmlDocuments)        StylesheetInfo[] refs = super.getStylesheetLinks(doc);        list.addAll(java.util.Arrays.asList(refs));        //get the link elements        try {            //this namespace handling is horrible!            //org.apache.xpath.objects.XObject xo = XPathAPI.eval(doc.getDocumentElement(), "//xh:link[@type='text/css']/@xh:href", pres);            org.apache.xpath.objects.XObject xo = XPathAPI.eval(doc.getDocumentElement(), "//link[contains(@rel,'stylesheet')]");            org.w3c.dom.NodeList nl = xo.nodelist();            for (int i = 0, len = nl.getLength(); i < len; i++) {                StylesheetInfo info = new StylesheetInfo();                info.setOrigin(StylesheetInfo.AUTHOR);                org.w3c.dom.Element link = (org.w3c.dom.Element) nl.item(i);                String a = link.getAttribute("rel");                if (a.indexOf("alternate") != -1) continue;//DON'T get alternate stylesheets                a = link.getAttribute("type");                if ("".equals(a)) a = "text/css";//HACK: is not entirely correct because default may be set by META tag or HTTP headers                info.setType(a);                a = link.getAttribute("href");                info.setUri(a);                a = link.getAttribute("media");                if ("".equals(a)) a = "screen";//the default in HTML                info.setMedia(a);                a = link.getAttribute("title");                info.setTitle(a);                if (info.getType().equals("text/css")) list.add(info);            }        } catch (Exception ex) {            ex.printStackTrace();        }        refs = new StylesheetInfo[list.size()];        for (int i = 0; i < refs.length; i++) {            refs[i] = (StylesheetInfo) list.get(i);        }        return refs;    }