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();
}
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();
}
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();
}
}
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();
}
}
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();
}
}
Aggregations