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;
}
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;
}
Aggregations