Search in sources :

Example 31 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class TestHtmlTranslation method testMangleServerSideAndClientTagInJS.

public void testMangleServerSideAndClientTagInJS() {
    // get model
    String fileName = getName() + ".html";
    IStructuredModel structuredModel = getSharedModel(fileName, "<script> var a = <custom:tag/>5;\nif(a < <%= 4 %>) {} ; </script>");
    assertNotNull("missing test model", structuredModel);
    // do translation
    JsTranslationAdapterFactory.setupAdapterFactory(structuredModel);
    JsTranslationAdapter translationAdapter = (JsTranslationAdapter) ((IDOMModel) structuredModel).getDocument().getAdapterFor(IJsTranslation.class);
    IJsTranslation translation = translationAdapter.getJsTranslation(false);
    String translated = translation.getJsText();
    assertTrue("translation empty", translated.length() > 5);
    assertTrue("server-side script block included\n" + translated, translated.indexOf("<%") < 0);
    assertTrue("server-side script block included\n" + translated, translated.indexOf("%>") < 0);
    assertTrue("tag included\n" + translated, translated.indexOf("custom") < 0);
    assertTrue("tag included\n" + translated, translated.indexOf("/>") < 0);
    assertTrue("var dropped\n" + translated, translated.indexOf("var a = ") > -1);
    assertTrue("if dropped\n" + translated, translated.indexOf("5;\nif(a <") > -1);
    assertTrue("block dropped\n" + translated, translated.indexOf(") {} ; ") > -1);
    assertTrue("problems found in translation ", translation.getProblems().isEmpty());
    // release model
    structuredModel.releaseFromRead();
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)

Example 32 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class TestHtmlTranslation method testMangleTagAndServerSideInJS.

public void testMangleTagAndServerSideInJS() {
    // get model
    String fileName = getName() + ".html";
    IStructuredModel structuredModel = getSharedModel(fileName, "<script> var a = <%= 4 %>5;\nif(a < <custom:tag/>) {} ; </script>");
    assertNotNull("missing test model", structuredModel);
    // do translation
    JsTranslationAdapterFactory.setupAdapterFactory(structuredModel);
    JsTranslationAdapter translationAdapter = (JsTranslationAdapter) ((IDOMModel) structuredModel).getDocument().getAdapterFor(IJsTranslation.class);
    IJsTranslation translation = translationAdapter.getJsTranslation(false);
    String translated = translation.getJsText();
    assertTrue("translation empty", translated.length() > 5);
    assertTrue("server-side script block included\n" + translated, translated.indexOf("<%") < 0);
    assertTrue("server-side script block included\n" + translated, translated.indexOf("%>") < 0);
    assertTrue("tag included\n" + translated, translated.indexOf("custom") < 0);
    assertTrue("tag included\n" + translated, translated.indexOf("/>") < 0);
    assertTrue("var dropped\n" + translated, translated.indexOf("var a = ") > -1);
    assertTrue("if dropped\n" + translated, translated.indexOf("5;\nif(a < ") > -1);
    assertTrue("block dropped\n" + translated, translated.indexOf(") {} ; ") > -1);
    assertTrue("problems found in translation ", translation.getProblems().isEmpty());
    // release model
    structuredModel.releaseFromRead();
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)

Example 33 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class UpdaterTest3 method testModel.

public void testModel() {
    IDOMModel model = createXMLModel();
    try {
        Document document = model.getDocument();
        Element a = document.createElement("a");
        document.appendChild(a);
        Element b = document.createElement("b");
        a.appendChild(b);
        printSource(model);
        printTree(model);
        Text t1 = document.createTextNode("\n");
        a.insertBefore(t1, b);
        printSource(model);
        printTree(model);
        Text t2 = document.createTextNode("\n");
        a.appendChild(t2);
        printSource(model);
        printTree(model);
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 34 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class SplitTextTest7 method testModel.

public void testModel() {
    IDOMModel model = createHTMLModel();
    try {
        Document document = model.getDocument();
        Element p = document.createElement("P");
        document.appendChild(p);
        Text text = document.createTextNode("aaaa");
        Text text2 = document.createTextNode("bbbb");
        p.appendChild(text);
        p.appendChild(text2);
        printSource(model);
        printTree(model);
        // delete accross node boundry
        model.getStructuredDocument().replaceText(this, 6, 3, "");
        printSource(model);
        printTree(model);
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 35 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class TableTest method testModel.

public void testModel() {
    IDOMModel model = createHTMLModel();
    try {
        Document document = model.getDocument();
        Element html = document.createElement("HTML");
        document.appendChild(html);
        printSource(model);
        printTree(model);
        Element body = document.createElement("BODY");
        html.appendChild(body);
        printSource(model);
        printTree(model);
        Element table = document.createElement("TABLE");
        table.setAttribute("border", "1");
        Element td = null;
        for (int row = 0; row < 2; row++) {
            Element tr = document.createElement("TR");
            table.appendChild(tr);
            for (int col = 0; col < 2; col++) {
                td = document.createElement("TD");
                tr.appendChild(td);
            }
        }
        body.appendChild(table);
        printSource(model);
        printTree(model);
        Element font = document.createElement("FONT");
        font.setAttribute("color", "red");
        Text text = document.createTextNode("text");
        font.appendChild(text);
        td.appendChild(font);
        printSource(model);
        printTree(model);
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Aggregations

IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)433 Document (org.w3c.dom.Document)123 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)120 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)110 Element (org.w3c.dom.Element)109 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)103 Node (org.w3c.dom.Node)57 IFile (org.eclipse.core.resources.IFile)56 NodeList (org.w3c.dom.NodeList)47 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)45 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)44 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)41 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)41 Text (org.w3c.dom.Text)39 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)35 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)28 IOException (java.io.IOException)26 CoreException (org.eclipse.core.runtime.CoreException)26 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)26 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)25