Search in sources :

Example 86 with IDOMModel

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();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter) IProject(org.eclipse.core.resources.IProject)

Example 87 with IDOMModel

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();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter) IProject(org.eclipse.core.resources.IProject)

Example 88 with IDOMModel

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();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList)

Example 89 with IDOMModel

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IProject(org.eclipse.core.resources.IProject)

Example 90 with IDOMModel

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;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) 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