Search in sources :

Example 1 with TLDAttributeDeclaration

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration 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 2 with TLDAttributeDeclaration

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration in project webtools.sourceediting by eclipse.

the class TaglibHelper method getTagInfo.

/**
 * @param decl
 * @return the TagInfo for the TLDELementDeclaration if the declaration is
 *         valid, otherwise null
 */
private TagInfo getTagInfo(final TLDElementDeclaration decl, TagExtraInfo tei, String prefix, String uri) {
    TagLibraryInfo libInfo = new TagLibraryInfoImpl(prefix, uri, decl);
    CMNamedNodeMap attrs = decl.getAttributes();
    TagAttributeInfo[] attrInfos = new TagAttributeInfo[attrs.getLength()];
    TLDAttributeDeclaration attr = null;
    // $NON-NLS-1$
    String type = "";
    // get tag attribute infos
    for (int i = 0; i < attrs.getLength(); i++) {
        attr = (TLDAttributeDeclaration) attrs.item(i);
        type = attr.getType();
        // default value for type is String
        if (// $NON-NLS-1$
        attr.getType() == null || attr.getType().equals(""))
            // $NON-NLS-1$
            type = "java.lang.String";
        attrInfos[i] = new TagAttributeInfo(attr.getAttrName(), attr.isRequired(), type, false);
    }
    String tagName = decl.getNodeName();
    String tagClass = decl.getTagclass();
    String bodyContent = decl.getBodycontent();
    if (tagName != null && tagClass != null && bodyContent != null)
        return new TagInfo(tagName, tagClass, bodyContent, decl.getInfo(), libInfo, tei, attrInfos);
    return null;
}
Also used : TLDAttributeDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration) TagAttributeInfo(javax.servlet.jsp.tagext.TagAttributeInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo)

Aggregations

TLDAttributeDeclaration (org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration)2 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)2 TagAttributeInfo (javax.servlet.jsp.tagext.TagAttributeInfo)1 TagInfo (javax.servlet.jsp.tagext.TagInfo)1 TagLibraryInfo (javax.servlet.jsp.tagext.TagLibraryInfo)1 TLDElementDeclaration (org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)1 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 CMNodeWrapper (org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper)1 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)1 Attr (org.w3c.dom.Attr)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1