/** * Reload informations of code completion. * * @param source HTML */ public void reload(IFile file, String source) { this.file = file; rules.clear(); source = HTMLUtil.scriptlet2space(source, false); FuzzyXMLDocument doc = new FuzzyXMLParser().parse(source); if (doc != null) { processElement(doc.getDocumentElement()); } }
private void processElement(FuzzyXMLElement element) { if (element.getName().equalsIgnoreCase("link")) { // external CSS cpecified by link tag String rel = ""; String type = ""; String href = ""; FuzzyXMLAttribute[] attrs = element.getAttributes(); for (int i = 0; i < attrs.length; i++) { if (attrs[i].getName().equalsIgnoreCase("rel")) { rel = attrs[i].getValue(); } else if (attrs[i].getName().equalsIgnoreCase("type")) { type = attrs[i].getValue(); } else if (attrs[i].getName().equalsIgnoreCase("href")) { href = attrs[i].getValue(); } } if (rel.equalsIgnoreCase("stylesheet") && type.equalsIgnoreCase("text/css")) { try { IFile css = getFile(href); if (css != null && css.exists()) { String text = new String(IOUtil.readStream(css.getContents())); processStylesheet(text); } } catch (Exception ex) { } } } else if (element.getName().equalsIgnoreCase("style")) { // inline CSS defined in style tag String type = ""; FuzzyXMLAttribute[] attrs = element.getAttributes(); for (int i = 0; i < attrs.length; i++) { if (attrs[i].getName().equalsIgnoreCase("type")) { type = attrs[i].getValue(); } } if (type.equalsIgnoreCase("text/css")) { String text = HTMLUtil.getXPathValue(element, "/"); processStylesheet(text); } } FuzzyXMLNode[] children = element.getChildren(); for (int i = 0; i < children.length; i++) { if (children[i] instanceof FuzzyXMLElement) { processElement((FuzzyXMLElement) children[i]); } } }