use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class CMValidator method validatAllGroupContent.
private void validatAllGroupContent(List elementContent, ElementContentComparator comparator, CMGroup allGroup, Result result) {
boolean isValid = true;
boolean isPartiallyValid = true;
HashMap map = new HashMap();
CMNodeList list = allGroup.getChildNodes();
for (int j = list.getLength() - 1; j >= 0; j--) {
CMNode node = list.item(j);
if (map.get(node) == null) {
map.put(node, new ItemCount());
}
}
int validitionCount = 0;
for (Iterator i = elementContent.iterator(); i.hasNext(); validitionCount++) {
Object o = i.next();
if (comparator.isElement(o)) {
// test to see if the element is listed in the all group
//
CMNode matchingCMNode = null;
for (int j = list.getLength() - 1; j >= 0; j--) {
CMNode node = list.item(j);
if (comparator.matches(o, node)) {
matchingCMNode = node;
break;
}
}
if (matchingCMNode == null) {
isPartiallyValid = false;
isValid = false;
break;
} else {
// test to see that the element occurs only once
//
ItemCount itemCount = (ItemCount) map.get(matchingCMNode);
if (itemCount != null) {
if (itemCount.count > 0) {
// we don't want to allow too many elements!
// we consider 'not enough' to be partially valid... but not 'too many'
isPartiallyValid = false;
break;
} else {
itemCount.count++;
}
}
}
}
}
if (isValid) {
for (int j = list.getLength() - 1; j >= 0; j--) {
CMNode node = list.item(j);
if (node.getNodeType() == CMNode.ELEMENT_DECLARATION) {
CMContent content = (CMContent) node;
ItemCount itemCount = (ItemCount) map.get(node);
// System.out.print("content " + content.getNodeName() + " " + content.getMinOccur());
if (itemCount.count < content.getMinOccur()) {
isValid = false;
break;
}
}
}
}
if (result instanceof ElementPathRecordingResult && isPartiallyValid) {
((ElementPathRecordingResult) result).setPartialValidationCount(validitionCount);
}
result.isValid = isValid;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class MarkupTagInfoProvider method printDocumentation.
/**
* Adds the tag documentation property of the CMNode to the string buffer,
* sb
*/
protected void printDocumentation(StringBuffer sb, CMNode node) {
// $NON-NLS-1$
CMNodeList nodeList = (CMNodeList) node.getProperty("documentation");
if ((nodeList != null) && (nodeList.getLength() > 0)) {
for (int i = 0; i < nodeList.getLength(); i++) {
CMDocumentation documentation = (CMDocumentation) nodeList.item(i);
String doc = documentation.getValue();
if (doc != null) {
sb.append(PARAGRAPH_START + doc.trim() + PARAGRAPH_END);
}
}
sb.append(NEW_LINE);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class ModelQueryActionHelper method getReplaceActions.
public void getReplaceActions(Element parent, CMElementDeclaration ed, List selectedChildren, int includeOptions, int validityChecking, List actionList) {
int[] range = getRange(parent, selectedChildren);
if (range != null) {
if (isContiguous(parent, range, selectedChildren)) {
List tempList = new Vector();
getReplaceActions(parent, ed, includeOptions, validityChecking, tempList);
if ((includeOptions & ModelQuery.INCLUDE_ENCLOSING_REPLACE_ACTIONS) != 0) {
removeActionsNotContainingRange(tempList, range[0], range[1]);
} else {
removeActionsNotMatchingRange(tempList, range[0], range[1]);
}
actionList.addAll(tempList);
}
}
if (selectedChildren.size() == 1) {
Node node = (Node) selectedChildren.get(0);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) node;
CMNode childEd = modelQuery.getCMElementDeclaration(childElement);
if (childEd != null) {
CMNode childOrigin = modelQuery.getOrigin(childElement);
CMNodeList cmNodeList = childOrigin != null ? // $NON-NLS-1$
(CMNodeList) childOrigin.getProperty("SubstitutionGroup") : // $NON-NLS-1$
(CMNodeList) childEd.getProperty("SubstitutionGroup");
if (cmNodeList != null && cmNodeList.getLength() > 1) {
int replaceIndex = getIndex(parent, childElement);
String childEdName = childEd.getNodeName();
for (int i = 0; i < cmNodeList.getLength(); i++) {
CMNode substitution = cmNodeList.item(i);
if (// $NON-NLS-1$
!substitution.getNodeName().equals(childEdName) && !Boolean.TRUE.equals(substitution.getProperty("Abstract"))) {
Action action = new Action(ModelQueryAction.REPLACE, parent, cmNodeList.item(i), replaceIndex, replaceIndex);
actionList.add(action);
}
}
}
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class ModelQueryActionHelper method isSimpleChoiceGroupContentModel.
protected boolean isSimpleChoiceGroupContentModel(CMElementDeclaration ed) {
boolean result = false;
CMNode cmNode = ed.getContent();
if (cmNode != null && cmNode.getNodeType() == CMNode.GROUP) {
CMGroup cmGroup = (CMGroup) cmNode;
if (cmGroup.getOperator() == CMGroup.CHOICE && cmGroup.getMaxOccur() == -1) {
result = true;
CMNodeList list = cmGroup.getChildNodes();
for (int i = list.getLength() - 1; i >= 0; i--) {
if (list.item(i).getNodeType() != CMNode.ELEMENT_DECLARATION) {
result = false;
break;
}
}
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList in project webtools.sourceediting by eclipse.
the class CMDescriptionBuilder method visitCMGroup.
public void visitCMGroup(CMGroup group) {
int op = group.getOperator();
if (op == CMGroup.ALL) {
// $NON-NLS-1$
sb.append("all");
}
// $NON-NLS-1$
sb.append("(");
// $NON-NLS-1$
String separator = ", ";
if (op == CMGroup.CHOICE) {
// $NON-NLS-1$
separator = " | ";
}
CMNodeList nodeList = group.getChildNodes();
int size = nodeList.getLength();
for (int i = 0; i < size; i++) {
visitCMNode(nodeList.item(i));
if (i < size - 1) {
sb.append(separator);
}
}
// $NON-NLS-1$
sb.append(")");
addOccurenceSymbol(group);
}
Aggregations