use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class CMVisitor method visitCMDocument.
public void visitCMDocument(CMDocument document) {
CMNamedNodeMap map = document.getElements();
int size = map.getLength();
for (int i = 0; i < size; i++) {
visitCMNode(map.item(i));
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap 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.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class CMDescriptionBuilder method visitCMDocument.
public void visitCMDocument(CMDocument document) {
CMNamedNodeMap map = document.getElements();
int size = map.getLength();
for (int i = 0; i < size; i++) {
visitCMNode(map.item(i));
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class ContentBuilder method visitCMElementDeclaration.
public void visitCMElementDeclaration(CMElementDeclaration ed) {
int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0;
int min = Math.max(ed.getMinOccur(), forcedMin);
alwaysVisit = false;
if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) {
visitedCMElementDeclarationList.add(ed);
for (int i = 1; i <= min; i++) {
createElementNodeStart(ed);
// instead of calling super.visitCMElementDeclaration()
// we duplicate the code with some minor modifications
CMNamedNodeMap nodeMap = ed.getAttributes();
int size = nodeMap.getLength();
for (int j = 0; j < size; j++) {
visitCMNode(nodeMap.item(j));
}
CMContent content = ed.getContent();
if (content != null) {
visitCMNode(content);
}
if (ed.getContentType() == CMElementDeclaration.PCDATA) {
CMDataType dataType = ed.getDataType();
if (dataType != null) {
visitCMDataType(dataType);
}
}
// end duplication
createElementNodeEnd(ed);
}
int size = visitedCMElementDeclarationList.size();
visitedCMElementDeclarationList.remove(size - 1);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class DOMContentBuilderImpl method testPopulateDocumentFromGrammarFile.
public static void testPopulateDocumentFromGrammarFile(Document document, String grammarFileName, String rootElementName, boolean hack) {
try {
CMDocument cmDocument = ContentModelManager.getInstance().createCMDocument(grammarFileName, null);
CMNamedNodeMap elementMap = cmDocument.getElements();
CMElementDeclaration element = (CMElementDeclaration) elementMap.getNamedItem(rootElementName);
DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(document);
contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = hack;
contentBuilder.createDefaultRootContent(cmDocument, element);
System.out.println();
// $NON-NLS-1$
System.out.println("-----------------------------");
DOMWriter writer = new DOMWriter();
if (hack) {
writer.print(document, grammarFileName);
} else {
writer.print(document);
}
// $NON-NLS-1$
System.out.println("-----------------------------");
} catch (Exception e) {
// $NON-NLS-1$
System.out.println("Error: " + e);
e.printStackTrace();
}
}
Aggregations