Search in sources :

Example 6 with NamespaceInfo

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

the class NamespaceInfoErrorHelper method computeErrorMessage.

public String computeErrorMessage(List namespaceInfoList, URIResolver idResolver) {
    String result = null;
    Hashtable prefixTable = new Hashtable();
    Hashtable uriTable = new Hashtable();
    for (Iterator iterator = namespaceInfoList.iterator(); iterator.hasNext(); ) {
        NamespaceInfo nsInfo = (NamespaceInfo) iterator.next();
        nsInfo.normalize();
        // $NON-NLS-1$
        String urikey = nsInfo.uri != null ? nsInfo.uri : "";
        NamespaceInfo nsInfo2 = null;
        if ((nsInfo2 = (NamespaceInfo) uriTable.get(urikey)) != null) {
            if ((nsInfo.uri != null) && nsInfo.uri.equals(nsInfo2.uri)) {
                // $NON-NLS-1$ //$NON-NLS-2$
                result = XMLUIMessages._UI_WARNING_MORE_THAN_ONE_NS_WITH_NAME + "'" + nsInfo.uri + "'";
            } else {
                result = XMLUIMessages._UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_NAME;
            }
            break;
        } else {
            uriTable.put(urikey, nsInfo);
        }
        if (nsInfo.uri != null) {
            // $NON-NLS-1$
            String key = nsInfo.prefix != null ? nsInfo.prefix : "";
            if (prefixTable.get(key) != null) {
                if (nsInfo.prefix != null) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    result = XMLUIMessages._UI_WARNING_MORE_THAN_ONE_NS_WITH_PREFIX + "'" + nsInfo.prefix + "'";
                    break;
                } else {
                    result = XMLUIMessages._UI_WARNING_MORE_THAN_ONE_NS_WITHOUT_PREFIX;
                    break;
                }
            } else {
                prefixTable.put(key, nsInfo);
            }
            if ((nsInfo.locationHint != null) && (idResolver != null)) {
                String grammarURI = idResolver.resolve(null, nsInfo.locationHint, nsInfo.locationHint);
                if (!URIHelper.isReadableURI(grammarURI, false)) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    result = XMLUIMessages._UI_WARNING_SCHEMA_CAN_NOT_BE_LOCATED + " '" + nsInfo.locationHint + "'";
                    break;
                }
            }
            if ((idResolver != null) && (nsInfo.locationHint == null) && !nsInfo.uri.equals(DOMNamespaceInfoManager.XSI_URI)) {
                // $NON-NLS-1$ //$NON-NLS-2$
                result = XMLUIMessages._UI_WARNING_LOCATION_HINT_NOT_SPECIFIED + " '" + nsInfo.uri + "'";
                break;
            }
        } else {
            if (nsInfo.prefix != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                result = XMLUIMessages._UI_WARNING_NAMESPACE_NAME_NOT_SPECIFIED + " '" + nsInfo.prefix + "'";
                break;
            }
        }
    }
    // additional tests
    if (result == null) {
        for (Iterator iterator = namespaceInfoList.iterator(); iterator.hasNext(); ) {
            NamespaceInfo nsInfo = (NamespaceInfo) iterator.next();
            nsInfo.normalize();
            if ((nsInfo.uri != null) && nsInfo.isPrefixRequired && (nsInfo.prefix == null)) {
                // $NON-NLS-1$ //$NON-NLS-2$
                result = XMLUIMessages._UI_WARNING_PREFIX_NOT_SPECIFIED + " '" + nsInfo.uri + "'";
                break;
            }
        }
    }
    return result;
}
Also used : Hashtable(java.util.Hashtable) Iterator(java.util.Iterator) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 7 with NamespaceInfo

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

the class ExcludeResultPrefixesContentAssist method getCompletionProposals.

/**
 * (non-Javadoc)
 * @see org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest#getCompletionProposals()
 */
@Override
public ArrayList<ICompletionProposal> getCompletionProposals() {
    proposals.clear();
    IDOMAttr attrNode = (IDOMAttr) ((IDOMElement) getNode()).getAttributeNode(EXCLUDE_RESULT_PREFIXES);
    String excludeResultPrefixes = attrNode.getValue();
    int offset = getCursorPosition();
    if (excludeResultPrefixes == null || excludeResultPrefixes.equals(DEFAULT)) {
        return getAllCompletionProposals();
    }
    // $NON-NLS-1$
    tokens = excludeResultPrefixes.split("\\s");
    if (tokens[0].equals("")) {
        // $NON-NLS-1$
        CustomCompletionProposal proposal = new CustomCompletionProposal(DEFAULT, offset, 0, DEFAULT.length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_PREFIX), DEFAULT, null, null, 0);
        addProposal(proposal);
    }
    Collection<NamespaceInfo> namespaces = this.getNamespaces((IDOMElement) node);
    for (NamespaceInfo namespace : namespaces) {
        if (includePrefix(namespace)) {
            CustomCompletionProposal proposal = new CustomCompletionProposal(namespace.prefix, offset, 0, namespace.prefix.length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_PREFIX), namespace.prefix, null, namespace.uri, 0);
            addProposal(proposal);
        }
    }
    return getAllCompletionProposals();
}
Also used : IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 8 with NamespaceInfo

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

the class CommonAddNamespacesDialog method addBuiltInNamespaces.

protected void addBuiltInNamespaces(List list) {
    // $NON-NLS-1$
    String xsiNamespace = "http://www.w3.org/2001/XMLSchema-instance";
    // $NON-NLS-1$
    String xsdNamespace = "http://www.w3.org/2001/XMLSchema";
    if (!isAlreadyDeclared(xsiNamespace)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        list.add(new NamespaceInfo("http://www.w3.org/2001/XMLSchema-instance", "xsi", null));
    }
    if (!isAlreadyDeclared(xsdNamespace)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        list.add(new NamespaceInfo("http://www.w3.org/2001/XMLSchema", "xsd", null));
    }
}
Also used : NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 9 with NamespaceInfo

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

the class CommonAddNamespacesDialog method addCatalogMapToList.

protected void addCatalogMapToList(ICatalog catalog, List list) {
    ICatalogEntry[] entries = catalog.getCatalogEntries();
    for (int i = 0; i < entries.length; i++) {
        ICatalogEntry entry = entries[i];
        if ((entry.getEntryType() == ICatalogEntry.ENTRY_TYPE_PUBLIC) && entry.getURI().endsWith(".xsd")) {
            // $NON-NLS-1$
            if (!isAlreadyDeclared(entry.getKey())) {
                // $NON-NLS-1$
                NamespaceInfo namespaceInfo = new NamespaceInfo(entry.getKey(), "xx", null);
                list.add(namespaceInfo);
            }
        }
    }
}
Also used : ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 10 with NamespaceInfo

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

the class CommonAddNamespacesDialog method computeAddablePrefixes.

public void computeAddablePrefixes(List addableList, List exisitingList) {
    HashMap map = new HashMap();
    for (Iterator i = exisitingList.iterator(); i.hasNext(); ) {
        NamespaceInfo info = (NamespaceInfo) i.next();
        if (info.prefix != null) {
            map.put(info.prefix, info);
        }
    }
    for (Iterator i = addableList.iterator(); i.hasNext(); ) {
        NamespaceInfo info = (NamespaceInfo) i.next();
        if (info.uri != null) {
            String prefix = (String) preferredPrefixTable.get(info.uri);
            info.prefix = getUniquePrefix(map, prefix, info.uri);
            map.put(info.prefix, info);
        }
    }
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) 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