Search in sources :

Example 16 with CMElementDeclaration

use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration 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 17 with CMElementDeclaration

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

the class XMLAssociationProvider method getDerivedCMElementDeclaration.

protected CMElementDeclaration getDerivedCMElementDeclaration(Element element, CMElementDeclaration ed, NamespaceTable namespaceTable) {
    CMElementDeclaration result = null;
    // $NON-NLS-1$
    String xsiPrefix = namespaceTable.getPrefixForURI("http://www.w3.org/2001/XMLSchema-instance");
    if (xsiPrefix != null) {
        // $NON-NLS-1$
        String xsiTypeValue = element.getAttribute(xsiPrefix + ":type");
        if (xsiTypeValue != null && xsiTypeValue.length() > 0) {
            String typePrefix = DOMNamespaceHelper.getPrefix(xsiTypeValue);
            String typeName = DOMNamespaceHelper.getUnprefixedName(xsiTypeValue);
            String typeURI = namespaceTable.getURIForPrefix(typePrefix);
            String uriQualifiedTypeName = typeName;
            if (typeURI != null && typeURI.length() > 0) {
                // $NON-NLS-1$ //$NON-NLS-2$
                uriQualifiedTypeName = "[" + typeURI + "]" + typeName;
            }
            // $NON-NLS-1$
            result = (CMElementDeclaration) ed.getProperty("DerivedElementDeclaration=" + uriQualifiedTypeName);
            if (result == null) {
                String reference = null;
                NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(typePrefix);
                if (namespaceInfo != null) {
                    String locationHint = resolveGrammarURI(element.getOwnerDocument(), namespaceInfo.uri, namespaceInfo.locationHint);
                    if (locationHint != null) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        reference = "[" + locationHint + "]" + typeName;
                    }
                }
                if (reference != null) {
                    // $NON-NLS-1$
                    result = (CMElementDeclaration) ed.getProperty("ExternallyDerivedElementDeclaration=" + reference);
                }
            }
        }
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 18 with CMElementDeclaration

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

the class InferredGrammarFactory method debugPrint.

public void debugPrint(Collection collection) {
    for (Iterator iter = collection.iterator(); iter.hasNext(); ) {
        CMDocument cmDocument = (CMDocument) iter.next();
        // $NON-NLS-1$
        System.out.println("-----------------------------------------------");
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        System.out.println("cmDocument (" + cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI") + ")");
        CMNamedNodeMapImpl elementMap = (CMNamedNodeMapImpl) cmDocument.getElements();
        int size = elementMap.getLength();
        for (int i = 0; i < size; i++) {
            CMElementDeclaration ed = (CMElementDeclaration) elementMap.item(i);
            CMDescriptionBuilder builder = new CMDescriptionBuilder();
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.println("  ELEMENT " + ed.getNodeName() + " = " + builder.buildDescription(ed));
        }
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Iterator(java.util.Iterator) CMDescriptionBuilder(org.eclipse.wst.xml.core.internal.contentmodel.util.CMDescriptionBuilder)

Example 19 with CMElementDeclaration

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

the class CMDocumentFactoryTLD method buildCMDocumentFromFolder.

/**
 * @param fileName
 * @return
 */
private CMDocumentImpl buildCMDocumentFromFolder(IPath path) {
    if (_debug) {
        // $NON-NLS-1$
        System.out.println("tagdir loading for " + path);
    }
    // EBNF is listed at 1.3.10
    CMDocumentImpl document = new CMDocumentImpl();
    document.setBaseLocation(path.toString());
    // $NON-NLS-1$
    document.setTlibversion("1.0");
    IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
    IResource[] tagfiles;
    try {
        tagfiles = folder.members();
        for (int i = 0; i < tagfiles.length; i++) {
            if (tagfiles[i].getType() == IResource.FILE) {
                if (tagfiles[i].getType() != IResource.FILE)
                    continue;
                String extension = tagfiles[i].getFileExtension();
                if (extension != null && (extension.equals("tag") || extension.equals("tagx"))) {
                    CMElementDeclaration ed = createElementDeclaration(document, (IFile) tagfiles[i]);
                    if (ed != null) {
                        document.fElements.setNamedItem(ed.getNodeName(), ed);
                    }
                }
            }
        }
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return document;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 20 with CMElementDeclaration

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

the class AbstractBreakpointProvider method isCustomTagRegion.

private static boolean isCustomTagRegion(IndexedRegion node) {
    if (node instanceof Element) {
        Element xmlElement = (Element) node;
        ModelQuery mq = ModelQueryUtil.getModelQuery(xmlElement.getOwnerDocument());
        CMElementDeclaration decl = mq.getCMElementDeclaration(xmlElement);
        if (decl instanceof CMNodeWrapper) {
            CMNode cmNode = ((CMNodeWrapper) decl).getOriginNode();
            return cmNode instanceof TLDElementDeclaration;
        }
    }
    return false;
}
Also used : CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) Element(org.w3c.dom.Element) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode)

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