use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap 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.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class JSPActionValidator method processDirective.
private void processDirective(IReporter reporter, IFile file, IStructuredModel model, IStructuredDocumentRegion documentRegion) {
IndexedRegion ir = model.getIndexedRegion(documentRegion.getStartOffset());
if (ir instanceof IDOMElement) {
IDOMElement element = (IDOMElement) ir;
ModelQuery query = ModelQueryUtil.getModelQuery(model);
if (query != null) {
CMElementDeclaration cmElement = query.getCMElementDeclaration(element);
if (cmElement != null) {
CMNamedNodeMap cmAttributes = null;
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl();
List nodes = query.getAvailableContent(element, cmElement, ModelQuery.INCLUDE_ATTRIBUTES);
for (int k = 0; k < nodes.size(); k++) {
CMNode cmnode = (CMNode) nodes.get(k);
if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
allAttributes.put(cmnode);
}
}
cmAttributes = allAttributes;
boolean foundjspattribute = checkUnknownAttributes(element, cmElement, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
// missing required attributes
if (!foundjspattribute && fSeverityMissingRequiredAttribute != ValidationMessage.IGNORE)
checkRequiredAttributes(element, cmAttributes, reporter, file, model.getStructuredDocument(), documentRegion);
if (fSeverityNonEmptyInlineTag != ValidationMessage.IGNORE)
checkNonEmptyInlineTag(element, cmElement, reporter, file, model.getStructuredDocument());
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class JSPModelQueryExtension method getAvailableElementContent.
/**
* Originally taken from JSPContentAssistProcessor
*
* @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension#getAvailableElementContent(org.w3c.dom.Element, java.lang.String, int)
*/
public CMNode[] getAvailableElementContent(Element parentElement, String namespace, int includeOptions) {
CMNode[] nodes = EMPTY_CMNODE_ARRAY;
ArrayList nodeList = new ArrayList();
// only returns anything if looking for child nodes
if (((includeOptions & ModelQuery.INCLUDE_CHILD_NODES) != 0) && parentElement instanceof IDOMNode) {
IDOMNode node = (IDOMNode) parentElement;
// get position dependent CMDocuments and insert their tags as
// proposals
ModelQueryAdapter mqAdapter = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
mqAdapter = (ModelQueryAdapter) node.getAdapterFor(ModelQueryAdapter.class);
} else {
mqAdapter = (ModelQueryAdapter) ((IDOMNode) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
}
if (mqAdapter != null) {
CMDocument doc = mqAdapter.getModelQuery().getCorrespondingCMDocument(node);
if (doc != null) {
CMDocument jcmdoc = getDefaultJSPCMDocument(node);
CMNamedNodeMap jspelements = jcmdoc.getElements();
/* For a built-in JSP action the content model is properly
* set up, so don't just blindly add the rest--unless this
* will be a direct child of the document
*/
if (jspelements != null && (!(doc instanceof JSPCMDocument) || node.getNodeType() == Node.DOCUMENT_NODE)) {
List rejectElements = new ArrayList();
// determine if the document is in XML form
Document domDoc = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
domDoc = (Document) node;
} else {
domDoc = node.getOwnerDocument();
}
// Show XML tag forms of JSP markers if jsp:root is
// the document element OR it's HTML but
// isn't really in the text.
// If the document isn't strictly XML, pull out the
// XML tag forms it is xml format
rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET);
rejectElements.add(JSP12Namespace.ElementName.EXPRESSION);
rejectElements.add(JSP12Namespace.ElementName.DECLARATION);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE);
rejectElements.add(JSP12Namespace.ElementName.TEXT);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_TAG);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_ATTRIBUTE);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_VARIABLE);
if (isXMLFormat(domDoc)) {
// jsp actions
rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
rejectElements.add(JSP12Namespace.ElementName.USEBEAN);
rejectElements.add(JSP12Namespace.ElementName.GETPROPERTY);
rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY);
rejectElements.add(JSP12Namespace.ElementName.INCLUDE);
rejectElements.add(JSP12Namespace.ElementName.FORWARD);
rejectElements.add(JSP12Namespace.ElementName.PLUGIN);
rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
rejectElements.add(JSP12Namespace.ElementName.PARAM);
rejectElements.add(JSP12Namespace.ElementName.PARAMS);
}
// don't show jsp:root if a document element already
// exists
Element docElement = domDoc.getDocumentElement();
if (docElement != null && ((docElement.getNodeName().equals(TAG_JSP_ROOT)) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() != null || ((IDOMNode) docElement).getEndStructuredDocumentRegion() != null)))) {
rejectElements.add(JSP12Namespace.ElementName.ROOT);
}
for (int j = 0; j < jspelements.getLength(); j++) {
CMElementDeclaration ed = (CMElementDeclaration) jspelements.item(j);
if (!rejectElements.contains(ed.getNodeName())) {
nodeList.add(ed);
}
}
}
} else // No cm document (such as for the Document (a non-Element) node itself)
{
CMNamedNodeMap jspElements = getDefaultJSPCMDocument(node).getElements();
int length = jspElements.getLength();
for (int i = 0; i < length; i++) {
nodeList.add(jspElements.item(i));
}
}
}
nodes = (CMNode[]) nodeList.toArray(new CMNode[nodeList.size()]);
}
return nodes;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class TaglibModelQueryExtension method getAvailableElementContent.
/**
* @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension#getAvailableElementContent(org.w3c.dom.Element, java.lang.String, int)
*/
public CMNode[] getAvailableElementContent(Element parentElement, String namespace, int includeOptions) {
CMNode[] nodes = EMPTY_CMNODE_ARRAY;
ArrayList nodeList = new ArrayList();
// only returns anything if looking for child nodes
if (((includeOptions & ModelQuery.INCLUDE_CHILD_NODES) != 0) && parentElement instanceof IDOMElement) {
// get the trackers
IDOMElement elem = (IDOMElement) parentElement;
IStructuredDocument structDoc = elem.getModel().getStructuredDocument();
TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(structDoc);
if (manager != null) {
List trackers = new ArrayList(manager.getTaglibTrackers());
Set prefixes = new HashSet();
// for each tracker add each of its elements to the node list
for (int trackerIndex = 0; trackerIndex < trackers.size(); ++trackerIndex) {
TaglibTracker tracker = ((TaglibTracker) trackers.get(trackerIndex));
CMNamedNodeMap elements = tracker.getElements();
for (int elementIndex = 0; elementIndex < elements.getLength(); ++elementIndex) {
nodeList.add(elements.item(elementIndex));
}
prefixes.add(tracker.getPrefix());
}
String prefix = parentElement.getPrefix();
if (prefixes.contains(prefix)) {
Node parent = parentElement;
while ((parent = parent.getParentNode()) != null && parent.getNodeType() == Node.ELEMENT_NODE) {
prefix = parent.getPrefix();
if (prefix == null || !prefixes.contains(prefix)) {
ModelQuery query = ModelQueryUtil.getModelQuery(parentElement.getOwnerDocument());
if (query != null) {
CMElementDeclaration decl = query.getCMElementDeclaration((Element) parent);
if (decl != null && !fExtensions.contains(this)) {
fExtensions.push(this);
nodeList.addAll(query.getAvailableContent((Element) parent, decl, includeOptions));
fExtensions.pop();
}
}
break;
}
}
}
nodes = (CMNode[]) nodeList.toArray(new CMNode[nodeList.size()]);
}
}
return nodes;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap 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