Search in sources :

Example 1 with LinkStyle

use of org.w3c.dom.stylesheets.LinkStyle in project webtools.sourceediting by eclipse.

the class StyleAdapterPerfTest method testPerformance.

public void testPerformance() {
    try {
        String filename = "testfiles/html/example04.html";
        IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit(filename, getClass().getResourceAsStream(filename), null);
        if (model instanceof IDOMModel) {
            IDOMDocument doc = ((IDOMModel) model).getDocument();
            NodeList nodes = doc.getElementsByTagName(HTML40Namespace.ElementName.STYLE);
            if (nodes != null && nodes.getLength() > 0) {
                Node node = nodes.item(0);
                if (node instanceof LinkStyle) {
                    long start = System.currentTimeMillis();
                    ((LinkStyle) node).getSheet();
                    // System.out.println("elapsed time = " + (System.currentTimeMillis() - start));
                    // TODO: we should probably use something likse o.e.core.runtime.PerformanceStats
                    // I picked the following fail criteria simple since before fix, the printlin reports about 7000
                    // on my computer, but with fix, reported about 1000.
                    // The appropriate time may vary greatly depending on the build/test machine.
                    // This is just to catch some large change in behavior
                    long elapsedTime = System.currentTimeMillis() - start;
                    if (elapsedTime > MAX_EXPECTED_TIME) {
                        fail("getSheet took longer than expected the expected " + MAX_EXPECTED_TIME + "ms");
                    }
                }
            }
        }
        if (model != null)
            model.releaseFromRead();
    } catch (Exception e) {
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) LinkStyle(org.w3c.dom.stylesheets.LinkStyle)

Example 2 with LinkStyle

use of org.w3c.dom.stylesheets.LinkStyle in project webtools.sourceediting by eclipse.

the class StyleTest method testModel.

public void testModel() {
    // new HTMLModelImpl();
    IDOMModel model = createHTMLModel();
    Document document = model.getDocument();
    Element style = document.createElement("STYLE");
    Text text = document.createTextNode("BODY { color : red; } P { color : green; } B { color : blue; }");
    style.appendChild(text);
    document.appendChild(style);
    printSource(model);
    printTree(model);
    DocumentStyle ds = (DocumentStyle) document;
    StyleSheetList ssl = ds.getStyleSheets();
    if (ssl.getLength() > 0) {
        CSSStyleSheet ss = (CSSStyleSheet) ssl.item(0);
        ss.deleteRule(1);
    }
    printSource(model);
    printTree(model);
    LinkStyle ls = (LinkStyle) style;
    CSSStyleSheet ss2 = (CSSStyleSheet) ls.getSheet();
    if (ss2 != null) {
        ss2.deleteRule(0);
    }
    printSource(model);
    printTree(model);
    saveAndCompareTestResults();
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) DocumentStyle(org.w3c.dom.stylesheets.DocumentStyle) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList) LinkStyle(org.w3c.dom.stylesheets.LinkStyle)

Aggregations

IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)2 LinkStyle (org.w3c.dom.stylesheets.LinkStyle)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 Text (org.w3c.dom.Text)1 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)1 DocumentStyle (org.w3c.dom.stylesheets.DocumentStyle)1 StyleSheetList (org.w3c.dom.stylesheets.StyleSheetList)1