Search in sources :

Example 1 with NamespaceTable

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

the class ModelQueryImpl method addValuesForXSIType.

protected void addValuesForXSIType(Element element, CMNode cmNode, List list) {
    if (cmNode != null && cmNode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
        CMAttributeDeclaration ad = (CMAttributeDeclaration) cmNode;
        if (valueHelper.isXSIType(ad)) {
            NamespaceTable table = new NamespaceTable(element.getOwnerDocument());
            table.addElementLineage(element);
            list.addAll(valueHelper.getQualifiedXSITypes(ad, table));
        }
    }
}
Also used : NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 2 with NamespaceTable

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable 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 3 with NamespaceTable

use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable 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 4 with NamespaceTable

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

the class ExtensibleAddExtensionCommand method addNamespaceDeclarationIfRequired.

// TODO... common this up with wsdl.ui
protected String addNamespaceDeclarationIfRequired(Element schemaElement, String prefixHint, String namespace) {
    String prefix = null;
    NamespaceTable namespaceTable = new NamespaceTable(schemaElement.getOwnerDocument());
    namespaceTable.addElement(schemaElement);
    prefix = namespaceTable.getPrefixForURI(namespace);
    if (prefix == null) {
        String basePrefix = prefixHint;
        prefix = basePrefix;
        // $NON-NLS-1$
        String xmlnsColon = "xmlns:";
        String attributeName = xmlnsColon + prefix;
        int count = 0;
        while (schemaElement.hasAttribute(attributeName)) {
            count++;
            prefix = basePrefix + count;
            attributeName = xmlnsColon + prefix;
        }
        schemaElement.setAttribute(attributeName, namespace);
    }
    return prefix;
}
Also used : NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable)

Example 5 with NamespaceTable

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

the class NamespaceSelectionAdapter method createNamespaceInfo.

private List<NamespaceInfo> createNamespaceInfo(Document document) {
    List<NamespaceInfo> info = namespaceInfo.get(document);
    if (info == null) {
        info = new ArrayList<NamespaceInfo>();
        NamespaceTable namespaceTable = new NamespaceTable(document);
        namespaceTable.visitElement(document.getDocumentElement());
        Collection<?> namespaces = namespaceTable.getNamespaceInfoCollection();
        info.addAll((Collection<NamespaceInfo>) namespaces);
        namespaceInfo.put(document, info);
    }
    return info;
}
Also used : NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Aggregations

NamespaceTable (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable)11 NamespaceInfo (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)3 Document (org.w3c.dom.Document)3 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 Iterator (java.util.Iterator)1 IPath (org.eclipse.core.runtime.IPath)1 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)1 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)1 DocumentType (org.w3c.dom.DocumentType)1 Node (org.w3c.dom.Node)1