Search in sources :

Example 26 with PageDirectiveAdapter

use of org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter in project webtools.sourceediting by eclipse.

the class TestModelHandlers method testDirtyStateForMisspelledEmbeddedCharset.

public void testDirtyStateForMisspelledEmbeddedCharset() throws Exception {
    String projectName = "TestModelHandlers." + getName();
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (!project.isAccessible()) {
        project = BundleResourceUtil.createSimpleProject(projectName, null, null);
    }
    IFile testFile = project.getFile("charaset.jsp");
    String contents = "<%@ page language=\"java\" contentType=\"text/xml; charaset=UTF-8\" pageEncoding=\"UTF-8\"%>\n" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Contents>\n" + "<Error state=\"fatal\" code=\"\">\n" + "</Error>\n" + "</Contents>";
    if (!testFile.exists()) {
        testFile.create(new ByteArrayInputStream(contents.getBytes("utf8")), IResource.FORCE, null);
    } else {
        testFile.setContents(new ByteArrayInputStream(contents.getBytes("utf8")), IResource.FORCE, null);
    }
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead(testFile);
        Document doc = ((IDOMModel) model).getDocument();
        PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getAdapterFor(PageDirectiveAdapter.class);
        EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
        assertFalse("newly opened model was dirty, embedded handler changed? current family:" + embeddedHandler.getFamilyId(), model.isDirty());
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
    project.delete(true, null);
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Document(org.w3c.dom.Document) IProject(org.eclipse.core.resources.IProject)

Aggregations

PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)26 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)23 Document (org.w3c.dom.Document)10 EmbeddedTypeHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler)9 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)9 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)6 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)6 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)5 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)4 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)3 ModelQueryAdapter (org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter)3 Node (org.w3c.dom.Node)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IDocument (org.eclipse.jface.text.IDocument)2 PageDirectiveAdapterFactory (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapterFactory)2 NodeList (org.w3c.dom.NodeList)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1