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