Search in sources :

Example 6 with CMDocument

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

the class XMLAssociationProvider method getCMElementDeclaration.

protected CMElementDeclaration getCMElementDeclaration(Element targetElement, List list, NamespaceTable namespaceTable) {
    CMElementDeclaration currentED = null;
    try {
        int listSize = list.size();
        for (int i = 0; i < listSize; i++) {
            Element element = (Element) list.get(i);
            if (i != 0) {
                namespaceTable.addElement(element);
            }
            String nodeName = element.getNodeName();
            String unprefixedName = DOMNamespaceHelper.getUnprefixedName(nodeName);
            String prefix = DOMNamespaceHelper.getPrefix(nodeName);
            CMElementDeclaration ed = null;
            // 
            if (currentED != null) {
                ed = (CMElementDeclaration) currentED.getLocalElements().getNamedItem(unprefixedName);
            }
            if (ed == null) {
                NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(prefix);
                if (namespaceInfo != null) {
                    // $NON-NLS-1$
                    CMDocument cmDocument = getCMDocument(namespaceInfo.uri, namespaceInfo.locationHint, "XSD");
                    if (cmDocument != null) {
                        ed = (CMElementDeclaration) cmDocument.getElements().getNamedItem(unprefixedName);
                    }
                }
            }
            currentED = ed;
            // handle XSIType
            if (currentED != null) {
                CMElementDeclaration derivedED = getDerivedCMElementDeclaration(element, currentED, namespaceTable);
                if (derivedED != null) {
                    currentED = derivedED;
                }
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        Logger.logException("exception locating element declaration for " + targetElement, e);
    }
    return currentED;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Element(org.w3c.dom.Element) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 7 with CMDocument

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

the class XMLAssociationProvider method getCMDocument.

public CMDocument getCMDocument(Element element, String uri) {
    CMDocument result = null;
    NamespaceTable namespaceTable = new NamespaceTable(element.getOwnerDocument());
    namespaceTable.addElementLineage(element);
    NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForURI(uri);
    if (namespaceInfo != null) {
        // $NON-NLS-1$
        result = getCMDocument(namespaceInfo.uri, namespaceInfo.locationHint, "XSD");
    }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 8 with CMDocument

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

the class XMLAssociationProvider method getCMElementDeclaration.

public CMElementDeclaration getCMElementDeclaration(Element element) {
    CMElementDeclaration result = null;
    Document document = element.getOwnerDocument();
    String[] doctypeInfo = getDoctypeInfo(document);
    if (doctypeInfo != null) {
        // we have detected doctype information so we assume that we can locate the CMElementDeclaration
        // in the CMDocument's table of global elements
        CMDocument cmDocument = getCorrespondingCMDocument(element, false);
        if (cmDocument != null) {
            result = (CMElementDeclaration) cmDocument.getElements().getNamedItem(element.getNodeName());
            // grammar behaviour via some established model query setting
            if (result == null && getImplictDoctype(document) != null) {
                Node parent = element.getParentNode();
                if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
                    result = getCMElementDeclaration((Element) parent);
                }
            }
        }
    } else {
        // here we use a namespaceTable to consider if the root element has any namespace information
        // 
        NamespaceTable namespaceTable = new NamespaceTable(element.getOwnerDocument());
        List list = NamespaceTable.getElementLineage(element);
        Element rootElement = (Element) list.get(0);
        namespaceTable.addElement(rootElement);
        if (namespaceTable.isNamespaceEncountered()) {
            // we assume that this is an XMLSchema style namespace aware document
            result = getCMElementDeclaration(element, list, namespaceTable);
        } else {
            result = checkExternalSchema(element);
            if (result == null) {
                // we assume that this is an inferred CMDocument for a DTD style 'namespaceless' document
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                CMDocument cmDocument = getCMDocument("", "", "DTD");
                if (cmDocument != null) {
                    result = (CMElementDeclaration) cmDocument.getElements().getNamedItem(element.getNodeName());
                } else {
                    IPath path = CMDocumentLoader.getInternalSubsetPath(document);
                    if (!Path.EMPTY.equals(path)) {
                        // $NON-NLS-1$
                        cmDocument = getCMDocument(path.toPortableString(), path.toFile().toURI().toString(), "DTD");
                        if (cmDocument != null) {
                            result = (CMElementDeclaration) cmDocument.getElements().getNamedItem(element.getNodeName());
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IPath(org.eclipse.core.runtime.IPath) NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Example 9 with CMDocument

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

the class ModelQueryExtensionManagerImpl method getNamespace.

private String getNamespace(CMNode cmNode) {
    String namespace = null;
    // $NON-NLS-1$
    CMDocument cmDocument = (CMDocument) cmNode.getProperty("CMDocument");
    if (cmDocument != null) {
        // $NON-NLS-1$
        namespace = (String) cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI");
    }
    return namespace;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Example 10 with CMDocument

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

the class DOMValidator method createContentSpecificationForCMElementDeclaration.

/**
 */
protected String createContentSpecificationForCMElementDeclaration(CMElementDeclaration ed) {
    // $NON-NLS-1$
    CMDocument document = (CMDocument) ed.getProperty("CMDocument");
    // $NON-NLS-1$
    String uri = document != null ? (String) document.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI") : null;
    String string = ed.getNodeName();
    if (uri != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        string = "[" + uri + "]" + string;
    }
    return string;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Aggregations

CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)83 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)33 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)26 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)20 List (java.util.List)15 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)14 Document (org.w3c.dom.Document)12 Element (org.w3c.dom.Element)11 ArrayList (java.util.ArrayList)10 Path (org.eclipse.core.runtime.Path)8 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)8 JSPCMDocument (org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument)7 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 URL (java.net.URL)6 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)6 Node (org.w3c.dom.Node)6 NodeList (org.w3c.dom.NodeList)6 Iterator (java.util.Iterator)5 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)5