Search in sources :

Example 21 with PageDirectiveAdapter

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

the class JSPModelLoader method setLanguageInPageDirective.

protected void setLanguageInPageDirective(IStructuredModel newModel) {
    if (newModel instanceof IDOMModel) {
        IDOMDocument document = ((IDOMModel) newModel).getDocument();
        PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getAdapterFor(PageDirectiveAdapter.class);
        String language = getLanguage(newModel);
        pageDirectiveAdapter.setLanguage(language);
    }
}
Also used : 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)

Example 22 with PageDirectiveAdapter

use of org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter 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 23 with PageDirectiveAdapter

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

the class JSPModelLoader method reInitializeEmbeddedType.

/**
 * This is "reinitialize" since there should always be at least the
 * default one assigned, before we start checking the stream
 */
private void reInitializeEmbeddedType(IStructuredModel model, EmbeddedTypeHandler oldEmbeddedContentType, EmbeddedTypeHandler newEmbeddedContentType) {
    // check program logic
    // $NON-NLS-1$
    Assert.isNotNull(oldEmbeddedContentType, "Program error: invalid call during model initialization");
    // once we know the embedded content type, we need to set it in the
    // PageDirectiveAdapter ... the order of initialization is
    // critical here, the doc must have been created, but its contents not
    // set yet,
    // and all factories must have been set up also.
    IDOMModel domModel = (IDOMModel) model;
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    IDOMDocument document = domModel.getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getExistingAdapter(PageDirectiveAdapter.class);
    // ==> // PropagatingAdapter propagatingAdapter = (PropagatingAdapter)
    // ((INodeNotifier)
    // document).getExistingAdapter(PropagatingAdapter.class);
    // ==> // ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter)
    // ((INodeNotifier)
    // document).getExistingAdapter(ModelQueryAdapter.class);
    oldEmbeddedContentType.uninitializeFactoryRegistry(model.getFactoryRegistry());
    oldEmbeddedContentType.uninitializeParser(structuredDocument.getParser());
    // since 'document' is not recreated in this
    // reinit path, we need to remove all adapters,
    // except for the propagated adapters (including page
    // directive adapter, and model query adapter).
    // to accomplish this, we'll just remove all, then
    // add back with a call to pre-load adapt.
    // let clients decide to unload adapters from document
    // Collection oldAdapters = document.getAdapters();
    // Iterator oldAdaptersIterator = oldAdapters.iterator();
    // while (oldAdaptersIterator.hasNext()) {
    // INodeAdapter oldAdapter = (INodeAdapter)
    // oldAdaptersIterator.next();
    // if (oldAdapter != pageDirectiveAdapter && oldAdapter !=
    // propagatingAdapter && oldAdapter != modelQueryAdapter) {
    // // DO NOT remove directly!
    // // can change contents while in notifity loop!
    // //oldAdaptersIterator.remove();
    // document.removeAdapter(oldAdapter);
    // }
    // }
    // DMW: I believe something like the following is needed,
    // since releases cached adapters
    // if (document instanceof DocumentImpl) {
    // ((DocumentImpl) document).releaseDocumentType();
    // ((DocumentImpl) document).releaseStyleSheets();
    // }
    // remember, embedded type factories are automatically cleared when
    // embededType changed
    pageDirectiveAdapter.setEmbeddedType(newEmbeddedContentType);
    // pageDirectiveAdapter.clearPageWatchers();
    if (newEmbeddedContentType != null) {
        // need to null out or else ModelParserAdapter
        // won't get reinitialized
        ((DOMModelImpl) model).setModelParser(null);
        newEmbeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry());
        newEmbeddedContentType.initializeParser(structuredDocument.getParser());
        // partitioner setup is the responsibility of this loader
        IDocumentPartitioner documentPartitioner = structuredDocument.getDocumentPartitioner();
        // added null/type checks for safety.
        if (documentPartitioner != null && documentPartitioner instanceof StructuredTextPartitionerForJSP) {
            if (newEmbeddedContentType.getFamilyId().equals(ContentTypeIdForXML.ContentTypeID_XML)) {
                ((StructuredTextPartitionerForJSP) documentPartitioner).setEmbeddedPartitioner(new StructuredTextPartitionerForXML());
            } else if (newEmbeddedContentType.getFamilyId().equals(ContentTypeIdForHTML.ContentTypeID_HTML)) {
                ((StructuredTextPartitionerForJSP) documentPartitioner).setEmbeddedPartitioner(new StructuredTextPartitionerForHTML());
            }
        }
    }
    // adding language here, in this convienent central
    // location, but some obvious renaming or refactoring
    // wouldn't hurt, in future.
    // I needed to add this language setting for JSP Fragment support
    // Note: this is the one that counts, since at this point,
    // the model has an ID, so we can look up IFile, etc.
    String language = getLanguage(model);
    if (language != null && language.length() > 0) {
        pageDirectiveAdapter.setLanguage(language);
    }
}
Also used : StructuredTextPartitionerForJSP(org.eclipse.jst.jsp.core.internal.text.StructuredTextPartitionerForJSP) StructuredTextPartitionerForXML(org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) StructuredTextPartitionerForHTML(org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)

Example 24 with PageDirectiveAdapter

use of org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter 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 25 with PageDirectiveAdapter

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

the class JSPModelLoader method initCloneOfEmbeddedType.

/**
 * This is "reinitialize" since there should always be at least the
 * default one assigned, before we start checking the stream
 */
private void initCloneOfEmbeddedType(IStructuredModel model, EmbeddedTypeHandler oldEmbeddedContentType, EmbeddedTypeHandler newEmbeddedContentType) {
    // check program logic
    // $NON-NLS-1$
    Assert.isNotNull(oldEmbeddedContentType, "Program error: invalid call during model initialization");
    // once we know the embedded content type, we need to set it in the
    // PageDirectiveAdapter ... the order of initialization is
    // critical here, the doc must have been created, but its contents not
    // set yet,
    // and all factories must have been set up also.
    IDOMModel domModel = (IDOMModel) model;
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    IDOMDocument document = domModel.getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getAdapterFor(PageDirectiveAdapter.class);
    // ==> // PropagatingAdapter propagatingAdapter = (PropagatingAdapter)
    // ((INodeNotifier) document).getAdapterFor(PropagatingAdapter.class);
    // ==> // ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter)
    // ((INodeNotifier) document).getAdapterFor(ModelQueryAdapter.class);
    // because, even in the clone case, the model has been paritally
    // intialized with
    // the old embedded type (during createModel), we need to unitialize
    // parts of it, based on the old (or default) ones
    oldEmbeddedContentType.uninitializeFactoryRegistry(model.getFactoryRegistry());
    oldEmbeddedContentType.uninitializeParser(structuredDocument.getParser());
    // remember, embedded type factories are automatically cleared when
    // embededType changed
    pageDirectiveAdapter.setEmbeddedType(newEmbeddedContentType);
    if (newEmbeddedContentType != null) {
        newEmbeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry());
        newEmbeddedContentType.initializeParser(structuredDocument.getParser());
    }
    // adding language here, in this convienent central
    // location, but some obvious renaming or refactoring
    // wouldn't hurt, in future.
    // I needed to add this language setting for JSP Fragment support
    // Note: this is the one that counts, since at this point,
    // the model has an ID, so we can look up IFile, etc.
    String language = getLanguage(model);
    if (language != null && language.length() > 0) {
        pageDirectiveAdapter.setLanguage(language);
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)

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