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;
}
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;
}
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;
}
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) {
}
}
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();
}
}
Aggregations