Search in sources :

Example 11 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class JSPModelLoader method newStructuredDocument.

/**
 * This method must return a new instance of IStructuredDocument, that has
 * been initialized with appropriate parser. For many loaders, the
 * (default) parser used is known for any input. For others, the correct
 * parser (and its initialization) is normall dependent on the content of
 * the file. This no-argument method should assume "empty input" and would
 * therefore return the default parser for the default contentType.
 *
 * If the parser is to handle tag libraries, it must have a TaglibSupport
 * object with a valid URIResolver and this IStructuredDocument attached
 * to it before the contents are set on the IStructuredDocument.
 */
public IStructuredDocument newStructuredDocument() {
    IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser());
    ((BasicStructuredDocument) structuredDocument).setReParser(new JSPReParser());
    // structuredDocument.setDocumentPartitioner(new
    // JSPJavaDocumentPartioner());
    // even though this is an "empty model" ... we want it to have at
    // least the
    // default embeddeded content type handler
    EmbeddedTypeHandler embeddedType = getJSPDefaultEmbeddedType(null);
    embeddedType.initializeParser(structuredDocument.getParser());
    return structuredDocument;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) JSPReParser(org.eclipse.jst.jsp.core.internal.parser.JSPReParser)

Example 12 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class TestModelClone method getEmbeddedType.

private EmbeddedTypeHandler getEmbeddedType(IStructuredModel model) {
    Document doc = ((IDOMModel) model).getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getExistingAdapter(PageDirectiveAdapter.class);
    assertNotNull("model did not have embedded adapter", pageDirectiveAdapter);
    EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
    assertNotNull("model did not have embedded handler", embeddedHandler);
    return embeddedHandler;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) Document(org.w3c.dom.Document)

Example 13 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class TestModelClone method checkEmbeddedType.

private void checkEmbeddedType(IStructuredModel model, Class expectedType) {
    Document doc = ((IDOMModel) model).getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getExistingAdapter(PageDirectiveAdapter.class);
    assertNotNull("model did not have pageDirective", pageDirectiveAdapter);
    EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
    assertNotNull("model did not have embedded handler", embeddedHandler);
    assertEquals(expectedType, embeddedHandler.getClass());
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) Document(org.w3c.dom.Document)

Example 14 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class TestModelClone method checkForSameEmbeddedFactories.

/**
 * Method checkEmbeddedFactories.
 * @param model
 * @param clonedModel
 * @return boolean
 */
private boolean checkForSameEmbeddedFactories(IStructuredModel model, IStructuredModel clonedModel) {
    boolean result = true;
    EmbeddedTypeHandler oldEmbeddedType = getEmbeddedType(model);
    EmbeddedTypeHandler newEmbeddedType = getEmbeddedType(clonedModel);
    // expect to be the same type
    if (!oldEmbeddedType.getClass().equals(newEmbeddedType.getClass())) {
        result = false;
        assertTrue(result);
    }
    List oldFactories = oldEmbeddedType.getAdapterFactories();
    List newFactories = newEmbeddedType.getAdapterFactories();
    result = checkFactoriesListForEquivalence(oldFactories, newFactories);
    return result;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler in project webtools.sourceediting by eclipse.

the class TestModelHandlers method testDirtyStateForEmbeddedCharsetWithoutContentType.

public void testDirtyStateForEmbeddedCharsetWithoutContentType() 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=\"charset=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

EmbeddedTypeHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler)24 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)11 PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)9 Document (org.w3c.dom.Document)9 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)5 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)3 BasicStructuredDocument (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)2 JSPReParser (org.eclipse.jst.jsp.core.internal.parser.JSPReParser)2 EmbeddedTypeRegistry (org.eclipse.wst.sse.core.internal.modelhandler.EmbeddedTypeRegistry)2 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)2 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1