use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class CMGroupWrapperImpl method getChildNodes.
/**
* getChildNodes method
* @return CMNodeList
*
* Returns child CMNodeList, which includes ElementDefinition or CMElement.
*/
public CMNodeList getChildNodes() {
if (fChildNodes == null) {
CMNodeListImpl childNodes = new CMNodeListImpl();
CMNodeList children = fGroup.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
CMNode child = children.item(i);
if (child instanceof CMGroup)
childNodes.appendItem(new CMGroupWrapperImpl(fPrefix, (CMGroup) child));
else if (child instanceof CMElementDeclaration)
childNodes.appendItem(new CMElementDeclarationWrapperImpl(fPrefix, (CMElementDeclaration) child));
else
// error?
childNodes.appendItem(new CMNodeWrapperImpl(fPrefix, child));
}
fChildNodes = childNodes;
}
return fChildNodes;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForHTMLTag method setupHTMLTags.
/**
*/
private static String[] setupHTMLTags() {
CMDocument cmdoc = HTMLCMDocumentFactory.getCMDocument(CMDocType.HTML_DOC_TYPE);
CMNamedNodeMap elements = cmdoc.getElements();
Vector names = new Vector();
int nElements = elements.getLength();
for (int i = 0; i < nElements; i++) {
CMElementDeclaration edec = (CMElementDeclaration) elements.item(i);
if (isAttrDefined(edec, HTML40Namespace.ATTR_NAME_STYLE)) {
names.add(edec.getElementName());
}
}
Collections.sort(names);
String[] tags = new String[names.size()];
Iterator iNames = names.iterator();
for (int i = 0; iNames.hasNext(); i++) {
tags[i] = (String) iNames.next();
}
return tags;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration 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.CMElementDeclaration 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.CMElementDeclaration 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;
}
Aggregations