Search in sources :

Example 46 with CMNamedNodeMap

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));
    }
}
Also used : CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 47 with CMNamedNodeMap

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);
            }
        }
    }
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) DocumentType(org.w3c.dom.DocumentType) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 48 with CMNamedNodeMap

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));
    }
}
Also used : CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 49 with CMNamedNodeMap

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);
    }
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent)

Example 50 with CMNamedNodeMap

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();
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Aggregations

CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)68 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)39 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)36 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)26 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)23 List (java.util.List)21 ArrayList (java.util.ArrayList)18 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)16 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)14 Element (org.w3c.dom.Element)14 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)13 NamedNodeMap (org.w3c.dom.NamedNodeMap)10 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)9 NodeList (org.w3c.dom.NodeList)9 Iterator (java.util.Iterator)8 Attr (org.w3c.dom.Attr)8 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)7 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)6 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)6 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)6