Search in sources :

Example 1 with NamespaceInfo

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

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

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

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

the class AddExtensionAttributeCommand method handleNamespacePrefices.

/**
 * Create a namespace prefix if needed, other wise retrieve
 * a predefined namespace prefix
 * @return
 */
private String handleNamespacePrefices() {
    Element schemaElement = component.getSchema().getElement();
    String prefix = null;
    // If target namespace of the attribute already exists
    List namespacePrefices = manager.getNamespaceInfoList(schemaElement);
    for (int i = 0; i < namespacePrefices.size(); i++) {
        NamespaceInfo info = (NamespaceInfo) namespacePrefices.get(i);
        if (info.uri.equals(attribute.getTargetNamespace())) {
            prefix = info.prefix;
        }
    }
    // Create unquie namespace prefix
    if (prefix == null) {
        prefix = createUniquePrefix(component);
    }
    // $NON-NLS-1$
    NamespaceInfo info = new NamespaceInfo(attribute.getTargetNamespace(), prefix, "");
    List infoList = new ArrayList(1);
    infoList.add(info);
    manager.addNamespaceInfo(schemaElement, infoList, false);
    return prefix;
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 5 with NamespaceInfo

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

the class NamespaceInfoTable method updateButtonEnabledState.

public void updateButtonEnabledState() {
    ISelection selection = tableViewer.getSelection();
    Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null;
    NamespaceInfo info = (NamespaceInfo) selectedObject;
    editButton.setEnabled(info != null);
    // $NON-NLS-1$
    deleteButton.setEnabled((info != null) && (info.getProperty("unremovable") == null));
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Aggregations

NamespaceInfo (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)30 List (java.util.List)9 Iterator (java.util.Iterator)8 Element (org.w3c.dom.Element)6 NamespaceTable (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable)5 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)4 IFile (org.eclipse.core.resources.IFile)3 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)3 NodeList (org.w3c.dom.NodeList)3 Path (org.eclipse.core.runtime.Path)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Shell (org.eclipse.swt.widgets.Shell)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IPathEditorInput (org.eclipse.ui.IPathEditorInput)2 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)2 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)2