Search in sources :

Example 6 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.

the class HTMLFormatter method getBreakSpaces.

/**
 */
protected String getBreakSpaces(Node node) {
    if (node == null)
        return null;
    StringBuffer buffer = new StringBuffer();
    String delim = ((IDOMNode) node).getModel().getStructuredDocument().getLineDelimiter();
    if (delim != null && delim.length() > 0)
        buffer.append(delim);
    String indent = getIndent();
    if (indent != null && indent.length() > 0) {
        for (Node parent = node.getParentNode(); parent != null; parent = parent.getParentNode()) {
            if (parent.getNodeType() != Node.ELEMENT_NODE)
                break;
            // ignore omitted tag
            if (((IDOMNode) parent).getStartStructuredDocumentRegion() == null)
                continue;
            IDOMElement element = (IDOMElement) parent;
            if (element.getPrefix() != null) {
                String localName = element.getLocalName();
                // special for html:html
                if (localName != null && !localName.equals(HTML_NAME)) {
                    buffer.append(indent);
                }
                continue;
            } else {
                String localName = element.getLocalName();
                if (HTML_NAME.equalsIgnoreCase(localName) || HEAD_NAME.equalsIgnoreCase(localName))
                    break;
            }
            CMElementDeclaration decl = getElementDeclaration(element);
            if (decl != null && decl.supports(HTMLCMProperties.SHOULD_INDENT_CHILD_SOURCE)) {
                boolean shouldIndent = isIdentable(node, parent);
                if (shouldIndent)
                    buffer.append(indent);
            }
        }
    }
    return buffer.toString();
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 7 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.

the class BaseAssociationProvider method getCMDataType.

public CMDataType getCMDataType(Text text) {
    CMDataType result = null;
    Node parentNode = text.getParentNode();
    if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
        CMElementDeclaration ed = getCMElementDeclaration((Element) parentNode);
        result = ed.getDataType();
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode)

Example 8 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.

the class InferredGrammarBuildingCMDocumentLoader method handleElement.

public void handleElement(Element element) {
    CMElementDeclaration parentInferredCMElementDeclaration = inferredCMElementDeclaration;
    if (inferredCMDocument == null) {
        // $NON-NLS-1$
        String cacheKey = "inferred-document";
        // $NON-NLS-1$
        inferredCMDocument = inferredGrammarFactory.createCMDocument("");
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        cmDocumentManager.addCMDocument("", "", cacheKey, "DTD", inferredCMDocument);
        createdCMDocumentTable.put(cacheKey, inferredCMDocument);
    }
    inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, false);
    if (parentInferredCMElementDeclaration != null) {
        inferredGrammarFactory.createCMContent(inferredCMDocument, parentInferredCMElementDeclaration, inferredCMDocument, inferredCMElementDeclaration, false, null);
    }
    visitChildNodes(element);
    // reset the 'current' state to inital values
    inferredCMElementDeclaration = parentInferredCMElementDeclaration;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)

Example 9 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.

the class InferredGrammarBuildingCMDocumentLoader method handleElementNS.

public void handleElementNS(Element element) {
    CMDocument parentInferredCMDocument = inferredCMDocument;
    CMElementDeclaration parentInferredCMElementDeclaration = inferredCMElementDeclaration;
    inferredCMDocument = null;
    inferredCMElementDeclaration = null;
    // by adding the element to the namespaceTable, handleGrammar() will get called for any schema references
    if (element.getParentNode() != document) {
        namespaceTable.addElement(element);
    }
    String prefix = element.getPrefix();
    String uri = namespaceTable.getURIForPrefix(prefix);
    if (uri == null && element.getParentNode() == document) {
        // when this is the root element
        // we need to add an implied "no namespace schema location"
        // $NON-NLS-1$
        uri = "ommitted-namespace";
        // $NON-NLS-1$
        namespaceTable.addNamespaceInfo(prefix, uri, "");
    }
    // here's where we update the inferred grammar if required
    // 
    boolean createCMElementDeclaration = true;
    boolean isLocal = (uri == null && prefix == null);
    if (isLocal) {
        if (parentInferredCMDocument == null) {
            // this is a local element... and the parent is not inferred (e.g) it has a known grammar
            // so we don't need to create an element declaration for this element
            createCMElementDeclaration = false;
        } else {
            if (uri == null) {
                // $NON-NLS-1$
                uri = "ommitted-namespace";
            }
        }
    }
    if (createCMElementDeclaration) {
        if (isLocal) {
            inferredCMDocument = parentInferredCMDocument;
            inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, true);
        } else {
            boolean createCMDocument = false;
            // $NON-NLS-1$
            String cacheKey = "inferred-document" + uri;
            inferredCMDocument = (CMDocument) createdCMDocumentTable.get(cacheKey);
            if (inferredCMDocument == null) {
                // we don't have an inferred document for this uri yet... let's see of we need one
                int status = cmDocumentManager.getCMDocumentStatus(uri);
                if (status == CMDocumentCache.STATUS_NOT_LOADED || status == CMDocumentCache.STATUS_ERROR) {
                    // the cache does not contain a 'proper' CMDocument for this uri
                    // so we need to create an inferred one
                    createCMDocument = true;
                }
            }
            if (createCMDocument) {
                // System.out.println("encountered element {" + element.getNodeName() + "} ... creating inferred CMDocument for " + uri);
                inferredCMDocument = inferredGrammarFactory.createCMDocument(uri);
                // $NON-NLS-1$ //$NON-NLS-2$
                cmDocumentManager.addCMDocument(uri, "", cacheKey, "XSD", inferredCMDocument);
                createdCMDocumentTable.put(cacheKey, inferredCMDocument);
            }
            if (inferredCMDocument != null) {
                inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, false);
            }
        }
        if (parentInferredCMElementDeclaration != null) {
            inferredGrammarFactory.createCMContent(parentInferredCMDocument, parentInferredCMElementDeclaration, inferredCMDocument, inferredCMElementDeclaration, isLocal, uri);
        }
    }
    visitChildNodes(element);
    // reset the 'current' state to inital values
    inferredCMElementDeclaration = parentInferredCMElementDeclaration;
    inferredCMDocument = parentInferredCMDocument;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)

Example 10 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.

the class ModelQueryImpl method canInsert.

public boolean canInsert(Element parent, CMNode cmNode, int index, int validityChecking) {
    boolean result = true;
    CMElementDeclaration ed = getCMElementDeclaration(parent);
    if (ed != null) {
        result = canInsert(parent, ed, cmNode, index, validityChecking);
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)

Aggregations

CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)147 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)53 List (java.util.List)46 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)43 Element (org.w3c.dom.Element)41 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)38 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)37 ArrayList (java.util.ArrayList)35 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)33 Node (org.w3c.dom.Node)32 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)30 NodeList (org.w3c.dom.NodeList)28 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)24 Iterator (java.util.Iterator)19 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)17 NamedNodeMap (org.w3c.dom.NamedNodeMap)17 Image (org.eclipse.swt.graphics.Image)15 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)15