Search in sources :

Example 1 with PageDirectiveAdapter

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

the class TestPageDirective method testGetTarget.

public void testGetTarget() {
    IDOMModel model = createUnmanagedHTMLModel();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) model.getDocument().getAdapterFor(PageDirectiveAdapter.class);
    INodeNotifier notifier = pageDirectiveAdapter.getTarget();
    assertNotNull("target is null", notifier);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 2 with PageDirectiveAdapter

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

the class TestPageDirective method testBasicPD.

public void testBasicPD() 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);
    // Now, assigning use a page directive, but leaving embedded type the same as default
    model.getStructuredDocument().setText(this, "<%@ page contentType=\"text/html\" language=\"java\" %>");
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((IDOMModel) model).getDocument().getAdapterFor(PageDirectiveAdapter.class);
    String contentType = pageDirectiveAdapter.getContentType();
    String language = pageDirectiveAdapter.getLanguage();
    assertTrue("contentType should be html", "text/html".equals(contentType));
    assertTrue("language should be java", "java".equals(language));
}
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)

Example 3 with PageDirectiveAdapter

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

the class TestPageDirective method testSetLanguage.

public void testSetLanguage() {
    IDOMModel model = createUnmanagedHTMLModel();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) model.getDocument().getAdapterFor(PageDirectiveAdapter.class);
    pageDirectiveAdapter.setLanguage("text/xml");
    assertTrue("set language failed", pageDirectiveAdapter.getLanguage().equals("text/xml"));
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)

Example 4 with PageDirectiveAdapter

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

the class JSPModelQueryImpl method getEmbeddedModelQuery.

// ISSUE: shouldn't this be private?
protected 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)) {
                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) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) 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)

Example 5 with PageDirectiveAdapter

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

the class JSPActionValidator method isElIgnored.

/**
 * Determines if EL should be ignored. Checks
 * <ol>
 *  <li>JSP version</li>
 * 	<li>Page directive isELIgnored</li>
 *  <li>Deployment descriptor's el-ignored</li>
 * </ol>
 * @return true if EL should be ignored, false otherwise. If the JSP version is < 2.0, EL is ignored by default
 */
private boolean isElIgnored(IPath path, IStructuredModel model) {
    if (DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(path) < 2.0f)
        return true;
    PageDirectiveAdapter pdAdapter = ((PageDirectiveAdapter) (((IDOMModel) model).getDocument().getAdapterFor(PageDirectiveAdapter.class)));
    if (pdAdapter == null) {
        // double-check the factory (although there just might not be a page directive in the file)
        if (model.getFactoryRegistry().getFactoryFor(PageDirectiveAdapter.class) == null) {
            model.getFactoryRegistry().addFactory(new PageDirectiveAdapterFactory());
            pdAdapter = ((PageDirectiveAdapter) (((IDOMModel) model).getDocument().getAdapterFor(PageDirectiveAdapter.class)));
        }
    }
    if (pdAdapter != null) {
        String directiveIsELIgnored = pdAdapter.getElIgnored();
        // isELIgnored directive found
        if (directiveIsELIgnored != null)
            return Boolean.valueOf(directiveIsELIgnored).booleanValue();
    }
    // Check the deployment descriptor for el-ignored
    PropertyGroup[] groups = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroups(path);
    if (groups.length > 0)
        return groups[0].isELignored();
    // JSP version >= 2.0 defaults to evaluating EL
    return false;
}
Also used : PropertyGroup(org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache.PropertyGroup) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) PageDirectiveAdapterFactory(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapterFactory) 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