Search in sources :

Example 6 with NamespaceTable

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

the class XPathUIPlugin method getNamespaceInfo.

public List<NamespaceInfo> getNamespaceInfo(IDOMDocument document) {
    XPathUIPlugin plugin = XPathUIPlugin.getDefault();
    String modelID = document.getModel().getId();
    Map<String, List<NamespaceInfo>> namespaceInfo = plugin.getNamespaceInfo();
    List<NamespaceInfo> info = namespaceInfo.get(modelID);
    if (info == null) {
        if (document.getDocumentElement() != 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(modelID, info);
            plugin.setNamespaceInfo(namespaceInfo);
            ensureDefault(namespaceTable, "xs", "http://www.w3.org/2001/XMLSchema");
        }
    }
    return info;
}
Also used : NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable) ArrayList(java.util.ArrayList) List(java.util.List) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 7 with NamespaceTable

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

the class XMLAssociationProvider method getCMDocumentReferences.

/**
 * This method returns a list of CMDocumentReferences associated with a particular node or subtree
 */
public List getCMDocumentReferences(Node node, boolean deep) {
    List result = new ArrayList();
    Document document = (node.getNodeType() == Node.DOCUMENT_NODE) ? (Document) node : node.getOwnerDocument();
    DocumentType doctype = document.getDoctype();
    // so that the implict DTD (if any) can be used
    if (doctype != null && (doctype.getPublicId() != null || doctype.getSystemId() != null)) {
        String uri = resolveGrammarURI(document, doctype.getPublicId(), doctype.getSystemId());
        result.add(new CMDocumentReferenceImpl(doctype.getPublicId(), uri));
    } else if (getImplictDoctype(document) != null) {
        String[] implicitDoctype = getImplictDoctype(document);
        String uri = resolveGrammarURI(document, implicitDoctype[0], implicitDoctype[1]);
        result.add(new CMDocumentReferenceImpl(implicitDoctype[0], uri));
    } else {
        NamespaceTable namespaceTable = new NamespaceTable(document);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            namespaceTable.addElement((Element) node);
        }
        if (deep) {
            addChildElementsToNamespaceTable(node, namespaceTable);
        }
        List list = namespaceTable.getNamespaceInfoList();
        for (Iterator i = list.iterator(); i.hasNext(); ) {
            NamespaceInfo info = (NamespaceInfo) i.next();
            String uri = resolveGrammarURI(document, info.uri, info.locationHint);
            result.add(new CMDocumentReferenceImpl(info.uri, uri));
        }
    }
    return result;
}
Also used : NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) DocumentType(org.w3c.dom.DocumentType) 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) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 8 with NamespaceTable

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

the class AddExtensionElementCommand method addNamespaceDeclarationIfRequired.

// TODO... common this up with wsdl.ui
private 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 9 with NamespaceTable

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

the class ExtensibleAddExtensionCommand method addSchemaAttribute.

protected void addSchemaAttribute(Element schemaElement, String namespace, String attributeName, String attributeValue) {
    String prefix = null;
    NamespaceTable namespaceTable = new NamespaceTable(schemaElement.getOwnerDocument());
    namespaceTable.addElement(schemaElement);
    prefix = namespaceTable.getPrefixForURI(namespace);
    try {
        if (prefix != null) {
            if (schemaElement.getAttributeNode(prefix + ":" + attributeName) == null)
                schemaElement.setAttribute(prefix + ":" + attributeName, attributeValue);
        } else {
            if (schemaElement.getAttributeNode(attributeName) == null)
                schemaElement.setAttribute(attributeName, attributeValue);
        }
    } catch (Exception e) {
    }
}
Also used : NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable)

Example 10 with NamespaceTable

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

the class CommonSelectContentAssistRequest method addSelectProposals.

@Override
protected void addSelectProposals(Element rootElement, int offset) {
    Document doc = rootElement.getOwnerDocument();
    NamespaceTable namespaceTable = new NamespaceTable(doc);
    namespaceTable.addElement(doc.getDocumentElement());
    prefix = namespaceTable.getPrefixForURI(EXSLTCore.EXSLT_COMMON_NAMESPACE);
    if (prefix != null) {
        addNodeSetProposal();
        addObjectTypeProposal();
    }
}
Also used : NamespaceTable(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable) Document(org.w3c.dom.Document)

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