use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class XMLAssociationProvider method getCorrespondingCMDocument.
protected CMDocument getCorrespondingCMDocument(Node node, boolean getDocumentFromCMNode) {
CMDocument result = null;
try {
Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument();
String[] doctypeInfo = getDoctypeInfo(document);
if (doctypeInfo != null) {
// $NON-NLS-1$
result = getCMDocument(doctypeInfo[0], doctypeInfo[1], "DTD");
} else // TODO... see if there is a way to re-organize to avoid the need for this flag
if (getDocumentFromCMNode) {
CMNode cmNode = getCMNode(node);
if (cmNode != null) {
// todo... add a getCMDocument() methods to CMNode
// for now use the getProperty interface
// $NON-NLS-1$
result = (CMDocument) cmNode.getProperty("CMDocument");
}
}
} catch (Exception e) {
// $NON-NLS-1$
Logger.logException("exception locating CMDocument for " + node, e);
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class ModelQueryActionHelper method getInsertChildNodeActions.
protected void getInsertChildNodeActions(Element parent, CMElementDeclaration ed, int includeOptions, int validityChecking, List actionList) {
int size = parent.getChildNodes().getLength();
List contentSpecificationList = modelQuery.getValidator().createContentSpecificationList(parent, ed);
List availableChildNodeList = modelQuery.getAvailableContent(parent, ed, includeOptions);
boolean isSimpleChoice = isSimpleChoiceGroupContentModel(ed);
for (Iterator iterator = availableChildNodeList.iterator(); iterator.hasNext(); ) {
CMNode cmNode = (CMNode) iterator.next();
for (int i = size; i >= 0; i--) {
if (isSimpleChoice || modelQuery.canInsert(parent, ed, cmNode, i, validityChecking, contentSpecificationList)) {
Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, i, i);
actionList.add(action);
break;
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class ModelQueryActionHelper method getInsertChildNodeActionsAtIndex.
protected void getInsertChildNodeActionsAtIndex(Element parent, CMElementDeclaration ed, int index, int includeOptions, int validityChecking, List actionList) {
// get actions for each insertable attribute
//
int size = parent.getChildNodes().getLength();
if (index <= size) {
List contentSpecificationList = modelQuery.getValidator().createContentSpecificationList(parent, ed);
List availableChildNodeList = modelQuery.getAvailableContent(parent, ed, includeOptions);
boolean isSimpleChoice = isSimpleChoiceGroupContentModel(ed);
for (Iterator i = availableChildNodeList.iterator(); i.hasNext(); ) {
CMNode cmNode = (CMNode) i.next();
if (isSimpleChoice || modelQuery.canInsert(parent, ed, cmNode, index, validityChecking, contentSpecificationList)) {
Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, index, index);
actionList.add(action);
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class ModelQueryActionHelper method getInsertActions.
public void getInsertActions(Document parent, CMDocument cmDocument, int index, int includeOptions, int validityChecking, List actionList) {
// get the root element and doctype index (if any)
//
int doctypeIndex = -1;
DocumentType doctype = null;
Element rootElement = null;
NodeList nodeList = parent.getChildNodes();
int nodeListLength = nodeList.getLength();
for (int i = 0; i < nodeListLength; i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
rootElement = (Element) childNode;
break;
} else if (childNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
doctype = (DocumentType) childNode;
doctypeIndex = i;
}
}
// make sure that root elements are only added after the doctype (if any)
if (rootElement == null && index > doctypeIndex) {
CMNamedNodeMap map = cmDocument.getElements();
int mapLength = map.getLength();
for (int i = 0; i < mapLength; i++) {
CMNode cmNode = map.item(i);
boolean canAdd = true;
if (validityChecking == ModelQuery.VALIDITY_STRICT) {
canAdd = doctype == null || doctype.getName().equals(cmNode.getNodeName());
}
if (canAdd) {
Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, index, index);
actionList.add(action);
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class DOMContentBuilderImpl method visitCMGroup.
public void visitCMGroup(CMGroup e) {
cmGroupStack.push(e);
int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
int min = Math.max(e.getMinOccur(), forcedMin);
int max = 0;
if (// unbounded
e.getMaxOccur() == -1)
max = getNumOfRepeatableElements();
else
max = Math.min(e.getMaxOccur(), getNumOfRepeatableElements());
if (max < min)
max = min;
alwaysVisit = false;
for (int i = 1; i <= max; i++) {
if (e.getOperator() == CMGroup.CHOICE && buildFirstChoice(buildPolicy)) {
CMNode hintNode = null;
// todo... the CMGroup should specify the hint... but it seems
// as though
// the Yamato guys are making the CMElement specify the hint.
// I do it that way for now until... we should fix this post
// GA
//
int listSize = visitedCMElementDeclarationList.size();
if (listSize > 0) {
CMElementDeclaration ed = (CMElementDeclaration) visitedCMElementDeclarationList.get(listSize - 1);
// $NON-NLS-1$
Object contentHint = ed.getProperty("contentHint");
if (contentHint instanceof CMNode) {
hintNode = (CMNode) contentHint;
}
}
// see if this hint corresponds to a valid choice
//
CMNode cmNode = null;
if (hintNode != null) {
CMNodeList nodeList = e.getChildNodes();
int nodeListLength = nodeList.getLength();
for (int j = 0; j < nodeListLength; j++) {
if (hintNode == nodeList.item(j)) {
cmNode = hintNode;
}
}
}
//
if (cmNode == null) {
CMNodeList nodeList = e.getChildNodes();
if (nodeList.getLength() > 0) {
cmNode = nodeList.item(0);
}
}
if (cmNode != null) {
// Visit the node only if it is not a GROUP (model group). If it is an element, then visit it.
if (!(cmNode.getNodeType() == CMNode.GROUP && min > 0)) {
visitCMNode(cmNode);
}
}
} else if (// ALL
e.getOperator() == CMGroup.ALL || // SEQUENCE
e.getOperator() == CMGroup.SEQUENCE) {
// visit all of the content
super.visitCMGroup(e);
}
}
cmGroupStack.pop();
}
Aggregations