Search in sources :

Example 1 with CMNodeWrapper

use of org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper in project webtools.sourceediting by eclipse.

the class AbstractBreakpointProvider method isCustomTagRegion.

private static boolean isCustomTagRegion(IndexedRegion node) {
    if (node instanceof Element) {
        Element xmlElement = (Element) node;
        ModelQuery mq = ModelQueryUtil.getModelQuery(xmlElement.getOwnerDocument());
        CMElementDeclaration decl = mq.getCMElementDeclaration(xmlElement);
        if (decl instanceof CMNodeWrapper) {
            CMNode cmNode = ((CMNodeWrapper) decl).getOriginNode();
            return cmNode instanceof TLDElementDeclaration;
        }
    }
    return false;
}
Also used : CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) Element(org.w3c.dom.Element) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode)

Example 2 with CMNodeWrapper

use of org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper in project webtools.sourceediting by eclipse.

the class JSPActionValidator method checkUnknownAttributes.

private boolean checkUnknownAttributes(IDOMElement element, CMElementDeclaration elementDecl, CMNamedNodeMap cmAttrs, IReporter reporter, IFile file, IStructuredDocument document, IStructuredDocumentRegion documentRegion) {
    boolean foundjspattribute = false;
    boolean dynamicAttributesAllowed = false;
    CMElementDeclaration decl = elementDecl;
    if (decl instanceof CMNodeWrapper)
        decl = (CMElementDeclaration) ((CMNodeWrapper) decl).getOriginNode();
    if (decl instanceof TLDElementDeclaration) {
        String dynamicAttributes = ((TLDElementDeclaration) decl).getDynamicAttributes();
        dynamicAttributesAllowed = dynamicAttributes != null ? Boolean.valueOf(dynamicAttributes).booleanValue() : false;
    }
    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr a = (Attr) attrs.item(i);
        CMAttributeDeclaration adec = (CMAttributeDeclaration) cmAttrs.getNamedItem(a.getName());
        if (adec == null) {
            /*
				 * No attr declaration was found. That is, the attr name is
				 * undefined. Disregard it includes JSP structure or this
				 * element supports dynamic attributes
				 */
            if (!hasJSPRegion(((IDOMNode) a).getNameRegion()) && fSeverityUnknownAttribute != ValidationMessage.IGNORE) {
                if (!dynamicAttributesAllowed) {
                    String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_6, a.getName());
                    LocalizedMessage message = new LocalizedMessage(fSeverityUnknownAttribute, msgText, file);
                    int start = ((IDOMAttr) a).getNameRegionStartOffset();
                    int length = ((IDOMAttr) a).getNameRegionEndOffset() - start;
                    int lineNo = document.getLineOfOffset(start);
                    message.setLineNo(lineNo);
                    message.setOffset(start);
                    message.setLength(length);
                    reporter.addMessage(fMessageOriginator, message);
                }
            } else {
                foundjspattribute = true;
            }
        } else {
            if (fSeverityUnexpectedRuntimeExpression != ValidationMessage.IGNORE && adec instanceof TLDAttributeDeclaration) {
                // The attribute cannot have a runtime evaluation of an expression
                if (!isTrue(((TLDAttributeDeclaration) adec).getRtexprvalue())) {
                    IDOMAttr attr = (IDOMAttr) a;
                    if (checkRuntimeValue(attr) && !fIsELIgnored) {
                        String msg = NLS.bind(JSPCoreMessages.JSPActionValidator_1, a.getName());
                        LocalizedMessage message = new LocalizedMessage(fSeverityUnexpectedRuntimeExpression, msg, file);
                        ITextRegion region = attr.getValueRegion();
                        int start = attr.getValueRegionStartOffset();
                        int length = region != null ? region.getTextLength() : 0;
                        int lineNo = document.getLineOfOffset(start);
                        message.setLineNo(lineNo);
                        message.setOffset(start);
                        message.setLength(length);
                        reporter.addMessage(fMessageOriginator, message);
                    }
                }
            }
        }
    }
    return foundjspattribute;
}
Also used : IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) TLDAttributeDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration) Attr(org.w3c.dom.Attr) IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 3 with CMNodeWrapper

use of org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper in project webtools.sourceediting by eclipse.

the class TaglibHelper method getCustomTag.

public CustomTag getCustomTag(String tagToAdd, IStructuredDocument structuredDoc, ITextRegionCollection customTag, List problems) {
    List results = new ArrayList();
    boolean isIterationTag = false;
    String tagClass = null;
    String teiClass = null;
    if (problems == null)
        problems = new ArrayList();
    ModelQuery mq = getModelQuery(structuredDoc);
    if (mq != null) {
        TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(structuredDoc);
        if (mgr != null) {
            List trackers = mgr.getCMDocumentTrackers(-1);
            Iterator taglibs = trackers.iterator();
            CMDocument doc = null;
            CMNamedNodeMap elements = null;
            while (taglibs.hasNext()) {
                doc = (CMDocument) taglibs.next();
                CMNode node = null;
                if ((elements = doc.getElements()) != null && (node = elements.getNamedItem(tagToAdd)) != null && node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
                    if (node instanceof CMNodeWrapper) {
                        node = ((CMNodeWrapper) node).getOriginNode();
                    }
                    TLDElementDeclaration tldElementDecl = (TLDElementDeclaration) node;
                    tagClass = tldElementDecl.getTagclass();
                    teiClass = tldElementDecl.getTeiclass();
                    isIterationTag = isIterationTag(tldElementDecl, structuredDoc, customTag, problems);
                    /*
						 * Although clearly not the right place to add validation
						 * design-wise, this is the first time we have the
						 * necessary information to validate the tag class.
						 */
                    validateTagClass(structuredDoc, customTag, tldElementDecl, problems);
                    // 1.2+ taglib style
                    addVariables(results, node, customTag);
                    // for 1.1 need more info from taglib tracker
                    if (doc instanceof TaglibTracker) {
                        String uri = ((TaglibTracker) doc).getURI();
                        String prefix = ((TaglibTracker) doc).getPrefix();
                        // only for 1.1 taglibs
                        addTEIVariables(structuredDoc, customTag, results, tldElementDecl, prefix, uri, problems);
                    }
                    break;
                }
            }
        }
    }
    return new CustomTag(tagToAdd, tagClass, teiClass, (TaglibVariable[]) results.toArray(new TaglibVariable[results.size()]), isIterationTag);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) ArrayList(java.util.ArrayList) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 4 with CMNodeWrapper

use of org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper in project webtools.sourceediting by eclipse.

the class TaglibHelper method getTaglibVariables.

/**
 * @param tagToAdd
 *            is the name of the tag whose variables we want
 * @param structuredDoc
 *            is the IStructuredDocument where the tag is found
 * @param customTag
 *            is the IStructuredDocumentRegion opening tag for the custom
 *            tag
 * @param problems problems that are generated while creating variables are added to this collection
 */
public TaglibVariable[] getTaglibVariables(String tagToAdd, IStructuredDocument structuredDoc, ITextRegionCollection customTag, List problems) {
    List results = new ArrayList();
    if (problems == null)
        problems = new ArrayList();
    ModelQuery mq = getModelQuery(structuredDoc);
    if (mq != null) {
        TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(structuredDoc);
        // mq).getTaglibSupport();
        if (mgr == null)
            return new TaglibVariable[0];
        List trackers = mgr.getCMDocumentTrackers(-1);
        Iterator taglibs = trackers.iterator();
        // TaglibSupport support = ((TaglibModelQuery)
        // mq).getTaglibSupport();
        // if (support == null)
        // return new TaglibVariable[0];
        // 
        // Iterator taglibs =
        // support.getCMDocuments(customTag.getStartOffset()).iterator();
        CMDocument doc = null;
        CMNamedNodeMap elements = null;
        while (taglibs.hasNext()) {
            doc = (CMDocument) taglibs.next();
            CMNode node = null;
            if ((elements = doc.getElements()) != null && (node = elements.getNamedItem(tagToAdd)) != null && node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
                if (node instanceof CMNodeWrapper) {
                    node = ((CMNodeWrapper) node).getOriginNode();
                }
                TLDElementDeclaration tldElementDecl = (TLDElementDeclaration) node;
                /*
					 * Although clearly not the right place to add validation
					 * design-wise, this is the first time we have the
					 * necessary information to validate the tag class.
					 */
                boolean tagClassFound = validateTagClass(structuredDoc, customTag, tldElementDecl, problems);
                // 1.2+ taglib style
                addVariables(results, node, customTag);
                // for 1.1 need more info from taglib tracker
                if (tagClassFound && doc instanceof TaglibTracker) {
                    String uri = ((TaglibTracker) doc).getURI();
                    String prefix = ((TaglibTracker) doc).getPrefix();
                    // only for 1.1 taglibs
                    addTEIVariables(structuredDoc, customTag, results, tldElementDecl, prefix, uri, problems);
                }
            }
        }
    }
    return (TaglibVariable[]) results.toArray(new TaglibVariable[results.size()]);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) TaglibTracker(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker) ArrayList(java.util.ArrayList) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 5 with CMNodeWrapper

use of org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper in project webtools.sourceediting by eclipse.

the class TestIndex method testUtilityProjectSupport.

public void testUtilityProjectSupport() throws Exception {
    // Create project 1
    IProject project = BundleResourceUtil.createSimpleProject("test-jar", null, null);
    assertTrue(project.exists());
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug183756/test-jar", "/test-jar");
    // Create project 2
    IProject project2 = BundleResourceUtil.createSimpleProject("test-war", null, null);
    assertTrue(project2.exists());
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug183756/test-war", "/test-war");
    IFile testFile = project2.getFile(new Path("src/main/webapp/test.jsp"));
    assertTrue("missing test JSP file!", testFile.isAccessible());
    IDOMModel jspModel = null;
    try {
        jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(testFile);
        NodeList tests = jspModel.getDocument().getElementsByTagName("test:test");
        assertTrue("test:test element not found", tests.getLength() > 0);
        CMElementDeclaration elementDecl = ModelQueryUtil.getModelQuery(jspModel).getCMElementDeclaration(((Element) tests.item(0)));
        assertNotNull("No element declaration was found for test:test at runtime", elementDecl);
        assertTrue("element declaration was not the expected kind", elementDecl instanceof CMNodeWrapper);
        CMNode originNode = ((CMNodeWrapper) elementDecl).getOriginNode();
        assertTrue("element declaration was not from a tag library", originNode instanceof TLDElementDeclaration);
        assertEquals("element declaration was not from expected tag library", "http://foo.com/testtags", ((TLDDocument) ((TLDElementDeclaration) originNode).getOwnerDocument()).getUri());
    } finally {
        if (jspModel != null) {
            jspModel.releaseFromRead();
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) IProject(org.eclipse.core.resources.IProject)

Aggregations

CMNodeWrapper (org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper)9 TLDElementDeclaration (org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration)6 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)6 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)5 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 List (java.util.List)4 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)4 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)4 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)3 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 TaglibTracker (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker)2 JSPCMDocument (org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument)2