use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method test_518987.
// http://bugs.eclipse.org/518987
public void test_518987() throws Exception {
String testName = "bug_518987";
// Create new project
IProject project = BundleResourceUtil.createJavaWebProject(testName);
assertTrue(project.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
// TEI class needs to already be compiled
// waitForBuildAndValidation(project);
// project.build(IncrementalProjectBuilder.FULL_BUILD, "org.eclipse.jdt.internal.core.builder.JavaBuilder", null, null);
project.getWorkspace().checkpoint(true);
IFile file1 = project.getFile("/WebContent/test1.jsp");
IDOMModel structuredModel1 = null;
try {
structuredModel1 = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file1);
ModelHandlerForJSP.ensureTranslationAdapterFactory(structuredModel1);
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) structuredModel1.getDocument().getAdapterFor(IJSPTranslation.class);
final String translation = translationAdapter.getJSPTranslation().getJavaText();
assertFalse("The unprocessed custom action's attribute value pair should not be in the translated source, was the custom tag not parsed?", translation.indexOf("insert=") > 0);
assertTrue("The 'insert' integer declared by a TEI class was not found, was the custom tag not parsed?\n\n" + translation, translation.indexOf("java.lang.Integer insert") > 0);
} finally {
if (structuredModel1 != null)
structuredModel1.releaseFromRead();
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method test_432978.
// http://bugs.eclipse.org/432978
public void test_432978() throws Exception {
String testName = "bug_432978";
// Create new project
IProject project = BundleResourceUtil.createJavaWebProject(testName);
assertTrue(project.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
// TEI class needs to already be compiled
// waitForBuildAndValidation(project);
// project.build(IncrementalProjectBuilder.FULL_BUILD, "org.eclipse.jdt.internal.core.builder.JavaBuilder", null, null);
project.getWorkspace().checkpoint(true);
IFile file1 = project.getFile("/WebContent/test.jsp");
IFile file2 = project.getFile("/WebContent/test2.jsp");
IDOMModel structuredModel1 = null;
IDOMModel structuredModel2 = null;
try {
ITaglibRecord tld = TaglibIndex.resolve(file1.getFullPath().toString(), "http://eclipse.org/testbug_432978", false);
structuredModel1 = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file1);
ModelHandlerForJSP.ensureTranslationAdapterFactory(structuredModel1);
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) structuredModel1.getDocument().getAdapterFor(IJSPTranslation.class);
final String translation = translationAdapter.getJSPTranslation().getJavaText();
assertTrue("The 'extra' integer declared by a TEI class was not found, taglib was: " + tld, translation.indexOf("java.lang.Integer extra") > 0);
/*
* the extra variable should only be declared once in the
* translated text
*/
assertEquals(2, translation.split("java.lang.Integer extra").length);
structuredModel2 = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file2);
ModelHandlerForJSP.ensureTranslationAdapterFactory(structuredModel2);
JSPTranslationAdapter translationAdapter2 = (JSPTranslationAdapter) structuredModel2.getDocument().getAdapterFor(IJSPTranslation.class);
final String translation2 = translationAdapter2.getJSPTranslation().getJavaText();
assertTrue(translation2.indexOf("extra") != -1);
// the extra variable should be declared twice because of the nested atbegin tags
assertEquals(3, translation2.split("java.lang.Integer extra").length);
} finally {
if (structuredModel1 != null)
structuredModel1.releaseFromRead();
if (structuredModel2 != null)
structuredModel2.releaseFromRead();
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testLoadCustomTagsThroughJSPSyntax.
public void testLoadCustomTagsThroughJSPSyntax() throws IOException, CoreException {
IFile jspFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.ROOT.append(PROJECT_NAME).append("web stuff/test1.jsp"));
assertTrue("test file " + jspFile.getFullPath() + " does not exist", jspFile.exists());
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(jspFile);
NodeList presents = model.getDocument().getElementsByTagName(TAG_NAME);
assertNotNull(TAG_NAME + " was missing from document", presents.item(0));
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) presents.item(0)).getAdapterFor(ModelQueryAdapter.class);
CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration((Element) presents.item(0));
assertNotNull("no CMElementDelcaration for " + TAG_NAME, declaration);
assertEquals("qualified name from element declaration was different", TAG_NAME, declaration.getNodeName());
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testTagFileHasTagContentModel.
public void testTagFileHasTagContentModel() throws IOException, CoreException {
String DPROJECT_NAME = getName();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(DPROJECT_NAME);
if (!project.exists()) {
// Create new project
project = BundleResourceUtil.createSimpleProject(DPROJECT_NAME, null, null);
}
project.refreshLocal(IResource.DEPTH_INFINITE, null);
IFile tagFile = project.getFile("test1.tag");
tagFile.create(new ByteArrayInputStream(new byte[0]), IResource.FORCE, null);
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tagFile);
model.getStructuredDocument().set("<" + JSP20Namespace.ElementName.DOBODY + "/>");
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) model.getDocument().getDocumentElement()).getAdapterFor(ModelQueryAdapter.class);
CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration(model.getDocument().getDocumentElement());
assertNotNull("no CMElementDeclaration for '" + JSP20Namespace.ElementName.DOBODY + "'", declaration);
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
project.delete(true, null);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class TestOrphan method getHTMLDoc.
private Document getHTMLDoc() {
IDOMModel structuredModel = (IDOMModel) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForHTML.ContentTypeID_HTML);
Document doc = structuredModel.getDocument();
return doc;
}
Aggregations