Search in sources :

Example 21 with EmbeddedTypeHandler

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

the class JSPModelLoader method initEmbeddedTypePre.

protected void initEmbeddedTypePre(IStructuredModel model, IStructuredDocument structuredDocument) {
    // note: this will currently only work for models backed by files
    EmbeddedTypeHandler embeddedContentType = null;
    IDOMModel domModel = (IDOMModel) model;
    if (embeddedContentType == null) {
        IContentDescription desc = getContentDescription(structuredDocument);
        if (desc != null) {
            Object prop = null;
            prop = desc.getProperty(IContentDescriptionForJSP.CONTENT_FAMILY_ATTRIBUTE);
            if (prop != null) {
                if (ContentTypeFamilyForHTML.HTML_FAMILY.equals(prop)) {
                    embeddedContentType = EmbeddedTypeRegistryImpl.getInstance().getTypeFor("text/html");
                }
            }
            if (embeddedContentType == null) {
                prop = desc.getProperty(IContentDescriptionForJSP.CONTENT_TYPE_ATTRIBUTE);
                if (prop != null) {
                    embeddedContentType = EmbeddedTypeRegistryImpl.getInstance().getTypeFor((String) prop);
                }
            }
        }
    }
    IDOMDocument document = domModel.getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getAdapterFor(PageDirectiveAdapter.class);
    if (embeddedContentType != null) {
        pageDirectiveAdapter.setEmbeddedType(embeddedContentType);
        embeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry());
    } else {
        // use default embeddedType if it couldn't determine one
        embeddedContentType = getJSPDefaultEmbeddedType(model);
        pageDirectiveAdapter.setEmbeddedType(embeddedContentType);
        embeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry());
    }
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 22 with EmbeddedTypeHandler

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

the class JSPModelLoader method getEmbeddedType.

private EmbeddedTypeHandler getEmbeddedType(IStructuredModel model) {
    Document doc = ((IDOMModel) model).getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getAdapterFor(PageDirectiveAdapter.class);
    EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
    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) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDocument(org.eclipse.jface.text.IDocument) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 23 with EmbeddedTypeHandler

use of org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler 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)

Example 24 with EmbeddedTypeHandler

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

the class JSPDocumentLoader method getEmbeddedType.

/**
 * Determine the MIME content type specified in a page directive. This
 * should appear "as early as possible in the JSP page" according to the
 * JSP v1.2 specification.
 */
private EmbeddedTypeHandler getEmbeddedType(IFile file) throws UnsupportedEncodingException, CoreException, IOException {
    EmbeddedTypeHandler handler = null;
    if (fFullPreparedReader == null) {
        handler = getJSPDefaultEmbeddedType();
    } else {
        String mimeType = null;
        IDocumentCharsetDetector jspProvider = getDocumentEncodingDetector();
        Reader fullPreparedReader = getFullPreparedReader();
        BufferedLimitedReader limitedReader = new BufferedLimitedReader(fullPreparedReader, CodedIO.MAX_BUF_SIZE);
        jspProvider.set(limitedReader);
        if (jspProvider instanceof IJSPHeadContentDetector) {
            mimeType = ((IJSPHeadContentDetector) jspProvider).getContentType();
            fullPreparedReader.reset();
        }
        EmbeddedTypeRegistry reg = getEmbeddedContentTypeRegistry();
        if (mimeType == null || mimeType.length() == 0) {
            handler = getJSPDefaultEmbeddedType();
        } else {
            handler = reg.getTypeFor(mimeType);
        }
    }
    return handler;
}
Also used : EmbeddedTypeRegistry(org.eclipse.wst.sse.core.internal.modelhandler.EmbeddedTypeRegistry) EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IDocumentCharsetDetector(org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector) BufferedLimitedReader(org.eclipse.wst.sse.core.internal.encoding.util.BufferedLimitedReader) BufferedLimitedReader(org.eclipse.wst.sse.core.internal.encoding.util.BufferedLimitedReader) Reader(java.io.Reader)

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