Search in sources :

Example 81 with IDOMModel

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

the class HTMLDocumentLoader method preLoadAdapt.

protected void preLoadAdapt(IStructuredModel structuredModel) {
    // DMW: just added this preload on 8/16/2002
    // I noticed the ProagatingAdapterFactory was being added,
    // that that the ProagatingAdapterAdapter was not being
    // preload adapted -- I'm assuing it ALWAYS has to be.
    IDOMModel domModel = (IDOMModel) structuredModel;
    // if there is a model in the adapter, this will adapt it to
    // first node. After that the PropagatingAdater spreads over the
    // children being
    // created. Each time that happends, a side effect is to
    // also "spread" sprecific registered adapters,
    // they two can propigate is needed.
    ((INodeNotifier) domModel.getDocument()).getAdapterFor(PropagatingAdapter.class);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 82 with IDOMModel

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

the class HTMLModelLoader method preLoadAdapt.

protected void preLoadAdapt(IStructuredModel structuredModel) {
    super.preLoadAdapt(structuredModel);
    // DMW: just added this preload on 8/16/2002
    // I noticed the ProagatingAdapterFactory was being added,
    // that that the ProagatingAdapterAdapter was not being
    // preload adapted -- I'm assuing it ALWAYS has to be.
    IDOMModel domModel = (IDOMModel) structuredModel;
    // if there is a model in the adapter, this will adapt it to
    // first node. After that the PropagatingAdater spreads over the
    // children being
    // created. Each time that happends, a side effect is to
    // also "spread" sprecific registered adapters,
    // they two can propigate is needed.
    ((INodeNotifier) domModel.getDocument()).getAdapterFor(PropagatingAdapter.class);
    if (Debug.debugNotificationAndEvents) {
        PropagatingAdapter propagatingAdapter = (PropagatingAdapter) ((INodeNotifier) domModel.getDocument()).getAdapterFor(PropagatingAdapter.class);
        propagatingAdapter.addAdaptOnCreateFactory(new DebugAdapterFactory());
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) DebugAdapterFactory(org.eclipse.wst.xml.core.internal.DebugAdapterFactory) PropagatingAdapter(org.eclipse.wst.sse.core.internal.PropagatingAdapter) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 83 with IDOMModel

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

the class TEIValidation method testCustomTagInAttribute.

public void testCustomTagInAttribute() throws Exception {
    // $NON-NLS-1$
    final String path = "/" + PROJECT_NAME + "/WebContent/test.jsp";
    final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
    IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead(file);
    try {
        assertTrue("Not an IDOMModel", model instanceof IDOMModel);
        NodeList divs = ((IDOMModel) model).getDocument().getElementsByTagName("div");
        assertTrue("Missing a div", divs.getLength() > 0);
        IDOMNode node = (IDOMNode) divs.item(0);
        IStructuredDocumentRegion region = node.getStartStructuredDocumentRegion();
        ITextRegionList regions = region.getRegions();
        assertTrue(regions.size() > 2);
        /* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
        /* JSPJavaTranslatorCoreTest.waitForBuildAndValidation(getProject()); */
        final TaglibHelper helper = new TaglibHelper(getProject());
        final List problems = new ArrayList();
        final IStructuredDocument document = model.getStructuredDocument();
        ITextRegion embedded = regions.get(2);
        assertTrue("Not a container region", embedded instanceof ITextRegionContainer);
        helper.getCustomTag("test:foo", document, (ITextRegionContainer) embedded, problems);
    /* assertEquals("No problems should be generated", 0, problems.size()); */
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IFile(org.eclipse.core.resources.IFile) TaglibHelper(org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 84 with IDOMModel

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

the class JSPJavaTranslatorCoreTest method testIterationTagsIncomplete.

/**
 * Tests that an iteration tag will generate
 * @throws Exception
 */
public void testIterationTagsIncomplete() throws Exception {
    String testName = "testIterationTags";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
    if (!project.isAccessible()) {
        // Create new project
        project = BundleResourceUtil.createSimpleProject(testName, null, null);
        assertTrue(project.exists());
        BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
    }
    /* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
    /* waitForBuildAndValidation(project); */
    IFile testFile = project.getFile("/WebContent/test_missing_end_tag.jsp");
    assertTrue("test_missing_end_tag.jsp is not accessible", testFile.isAccessible());
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(testFile);
        ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
        JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
        JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
        String javaText = translation.getJavaText();
        int startOffset = javaText.indexOf("} // [</plain:loop>]");
        assertTrue("Missing end tag was not accounted for.", startOffset != -1);
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) JSPTranslationExtension(org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension) 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 85 with IDOMModel

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

the class JSPJavaTranslatorCoreTest method testIterationTags.

public void testIterationTags() throws Exception {
    String testName = "testIterationTags";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
    if (!project.isAccessible()) {
        // Create new project
        project = BundleResourceUtil.createSimpleProject(testName, null, null);
        assertTrue(project.exists());
        BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
    }
    /* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
    /* waitForBuildAndValidation(project); */
    IFile testFile = project.getFile("/WebContent/test.jsp");
    assertTrue("test.jsp is not accessible", testFile.isAccessible());
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(testFile);
        ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
        JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
        JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
        translation.setProblemCollectingActive(true);
        assertNotNull("No Java translation found", translation);
        translation.reconcileCompilationUnit();
        translation.setProblemCollectingActive(false);
        List<IProblem> problems = translation.getProblems();
        assertNotNull("Translation had a null problems list.", problems);
        Iterator<IProblem> it = problems.iterator();
        String javaText = translation.getJavaText();
        int startOffset = javaText.indexOf("<plain:simple>");
        assertTrue("<plan:simple> scope not found.", startOffset > 0);
        int endOffset = javaText.indexOf("</plain:simple>", startOffset);
        assertTrue("</plan:simple> scope not found.", endOffset > 0);
        // Finds all errors caused by "continue cannot be used outside of a loop" - should only occur between <plain:simple></plain:simple>
        while (it.hasNext()) {
            IProblem problem = it.next();
            if (problem.isError()) {
                if ("continue cannot be used outside of a loop".equals(problem.getMessage())) {
                    assertTrue("'continue cannot be used outside of a loop' outside of iteration tag: ", problem.getSourceStart() > startOffset && problem.getSourceEnd() < endOffset);
                }
            }
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) JSPTranslationExtension(org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension) 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) IProblem(org.eclipse.jdt.core.compiler.IProblem) IProject(org.eclipse.core.resources.IProject)

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