use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument 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;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument 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.CMDocument 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.CMDocument in project webtools.sourceediting by eclipse.
the class ModelQueryExtensionManagerImpl method getNamespace.
private String getNamespace(CMNode cmNode) {
String namespace = null;
// $NON-NLS-1$
CMDocument cmDocument = (CMDocument) cmNode.getProperty("CMDocument");
if (cmDocument != null) {
// $NON-NLS-1$
namespace = (String) cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI");
}
return namespace;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDocument in project webtools.sourceediting by eclipse.
the class DOMValidator method createContentSpecificationForCMElementDeclaration.
/**
*/
protected String createContentSpecificationForCMElementDeclaration(CMElementDeclaration ed) {
// $NON-NLS-1$
CMDocument document = (CMDocument) ed.getProperty("CMDocument");
// $NON-NLS-1$
String uri = document != null ? (String) document.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI") : null;
String string = ed.getNodeName();
if (uri != null) {
// $NON-NLS-1$ //$NON-NLS-2$
string = "[" + uri + "]" + string;
}
return string;
}
Aggregations