Search in sources :

Example 16 with PageDirectiveAdapter

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

the class TestPageDirective method testAddEmbeddedFactory.

public void testAddEmbeddedFactory() {
    IDOMModel model = createUnmanagedHTMLModel();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) model.getDocument().getAdapterFor(PageDirectiveAdapter.class);
    pageDirectiveAdapter.addEmbeddedFactory(new MyEmbeddedFactory());
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)

Example 17 with PageDirectiveAdapter

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

the class TestModelEmbeddedContentType method checkEmbeddedType.

protected void checkEmbeddedType(IStructuredModel clonedModel, Object expectedType) {
    Document doc = ((IDOMModel) clonedModel).getDocument();
    PageDirectiveAdapter embeddedTypeAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getAdapterFor(PageDirectiveAdapter.class);
    assertNotNull("cloned model did not have embedded adapter", embeddedTypeAdapter);
    EmbeddedTypeHandler embeddedHandler = embeddedTypeAdapter.getEmbeddedType();
    assertNotNull("cloned model did not have embedded handler", embeddedHandler);
    assertTrue("cloned model embeddedHandler is wrong type", embeddedHandler.equals(expectedType));
}
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 18 with PageDirectiveAdapter

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

the class TestModelEmbeddedContentType method doStructuredModelEmbeddedJSP.

protected IStructuredModel doStructuredModelEmbeddedJSP() throws IOException {
    // First make (empty) structuredDocument
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel model = modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
    assertTrue("model could not be created!", model != null);
    // should have an embedded type
    Document doc = ((IDOMModel) model).getDocument();
    PageDirectiveAdapter embeddedHandler = (PageDirectiveAdapter) ((INodeNotifier) doc).getAdapterFor(PageDirectiveAdapter.class);
    assertTrue("embededHanlder should NOT be null for JSP", embeddedHandler != null);
    // embedded type should be HTML since no content
    checkEmbeddedType(model, ModelHandlerUtility.getDefaultEmbeddedType());
    String testContent = "<%@ page contentType=\"text/html\" %>";
    model.getStructuredDocument().replaceText(this, 0, 0, testContent);
    assertTrue("reinit should NOT be needed in this case", !model.isReinitializationNeeded());
    // embedded type should STILL be HTML since no contentType was
    // text/html
    checkEmbeddedType(model, ModelHandlerUtility.getDefaultEmbeddedType());
    return model;
// 
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Document(org.w3c.dom.Document)

Example 19 with PageDirectiveAdapter

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

the class TestModelClone method testCloneStructuredModelJSP.

public void testCloneStructuredModelJSP() throws IOException {
    // First make (empty) structuredDocument
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel model = modelManager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
    assertTrue("model could not be created!", model != null);
    IStructuredModel clonedModel = model.newInstance();
    assertTrue("cloned model could not be created!", clonedModel != null);
    // make sure the embedded type is correct
    boolean passed = true;
    Document doc = ((IDOMModel) clonedModel).getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) doc).getExistingAdapter(PageDirectiveAdapter.class);
    assertNotNull("cloned model did not have embedded adapter", pageDirectiveAdapter);
    EmbeddedTypeHandler embeddedHandler = pageDirectiveAdapter.getEmbeddedType();
    assertNotNull("cloned model did not have embedded handler", embeddedHandler);
    // if (clonedModel.getEncodingMemento() == model.getEncodingMemento()) passed = false;
    // if (clonedModel.getParser() == model.getParser()) passed = false;
    // if (clonedModel.getReParser() == model.getReParser()) passed = false;
    assertTrue("newInstance of structured model is not correct", passed);
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Document(org.w3c.dom.Document)

Example 20 with PageDirectiveAdapter

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

the class TestModelClone method getEmbeddedModelQuery.

private ModelQuery getEmbeddedModelQuery(Node node) {
    ModelQuery embeddedModelQuery = null;
    if (node instanceof INodeNotifier) {
        Node ownerNode = node.getOwnerDocument();
        if (ownerNode == null) {
            // then must be the document itself
            ownerNode = node;
        }
        PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) ownerNode).getAdapterFor(PageDirectiveAdapter.class);
        if (pageDirectiveAdapter != null) {
            String effectiveContentType = null;
            ModelQuery potentialModelQueryObject = null;
            String familyId = pageDirectiveAdapter.getEmbeddedType().getFamilyId();
            // if (ContentTypeFamilyForHTML.HTML_FAMILY.equals(familyId)) {
            if ("org.eclipse.wst.html.core.contentfamily.html".equals(familyId)) {
                effectiveContentType = "text/html";
            } else {
                effectiveContentType = pageDirectiveAdapter.getContentType();
            }
            potentialModelQueryObject = (ModelQuery) embeddedModelQueries.get(effectiveContentType);
            if (potentialModelQueryObject == null) {
                ModelQueryAdapter embeddedAdapter = (ModelQueryAdapter) pageDirectiveAdapter.adapt((INodeNotifier) node, ModelQueryAdapter.class);
                if (embeddedAdapter != null) {
                    // we will cache one model query per content type
                    embeddedModelQuery = embeddedAdapter.getModelQuery();
                    embeddedModelQueries.put(effectiveContentType, embeddedModelQuery);
                }
            } else {
                embeddedModelQuery = potentialModelQueryObject;
            }
        }
    }
    return embeddedModelQuery;
}
Also used : ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) Node(org.w3c.dom.Node) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

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