use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo 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.util.NamespaceInfo 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.NamespaceInfo in project webtools.sourceediting by eclipse.
the class XMLAssociationProvider method getDerivedCMElementDeclaration.
protected CMElementDeclaration getDerivedCMElementDeclaration(Element element, CMElementDeclaration ed, NamespaceTable namespaceTable) {
CMElementDeclaration result = null;
// $NON-NLS-1$
String xsiPrefix = namespaceTable.getPrefixForURI("http://www.w3.org/2001/XMLSchema-instance");
if (xsiPrefix != null) {
// $NON-NLS-1$
String xsiTypeValue = element.getAttribute(xsiPrefix + ":type");
if (xsiTypeValue != null && xsiTypeValue.length() > 0) {
String typePrefix = DOMNamespaceHelper.getPrefix(xsiTypeValue);
String typeName = DOMNamespaceHelper.getUnprefixedName(xsiTypeValue);
String typeURI = namespaceTable.getURIForPrefix(typePrefix);
String uriQualifiedTypeName = typeName;
if (typeURI != null && typeURI.length() > 0) {
// $NON-NLS-1$ //$NON-NLS-2$
uriQualifiedTypeName = "[" + typeURI + "]" + typeName;
}
// $NON-NLS-1$
result = (CMElementDeclaration) ed.getProperty("DerivedElementDeclaration=" + uriQualifiedTypeName);
if (result == null) {
String reference = null;
NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(typePrefix);
if (namespaceInfo != null) {
String locationHint = resolveGrammarURI(element.getOwnerDocument(), namespaceInfo.uri, namespaceInfo.locationHint);
if (locationHint != null) {
// $NON-NLS-1$ //$NON-NLS-2$
reference = "[" + locationHint + "]" + typeName;
}
}
if (reference != null) {
// $NON-NLS-1$
result = (CMElementDeclaration) ed.getProperty("ExternallyDerivedElementDeclaration=" + reference);
}
}
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.
the class AddExtensionAttributeCommand method handleNamespacePrefices.
/**
* Create a namespace prefix if needed, other wise retrieve
* a predefined namespace prefix
* @return
*/
private String handleNamespacePrefices() {
Element schemaElement = component.getSchema().getElement();
String prefix = null;
// If target namespace of the attribute already exists
List namespacePrefices = manager.getNamespaceInfoList(schemaElement);
for (int i = 0; i < namespacePrefices.size(); i++) {
NamespaceInfo info = (NamespaceInfo) namespacePrefices.get(i);
if (info.uri.equals(attribute.getTargetNamespace())) {
prefix = info.prefix;
}
}
// Create unquie namespace prefix
if (prefix == null) {
prefix = createUniquePrefix(component);
}
// $NON-NLS-1$
NamespaceInfo info = new NamespaceInfo(attribute.getTargetNamespace(), prefix, "");
List infoList = new ArrayList(1);
infoList.add(info);
manager.addNamespaceInfo(schemaElement, infoList, false);
return prefix;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo in project webtools.sourceediting by eclipse.
the class NamespaceInfoTable method updateButtonEnabledState.
public void updateButtonEnabledState() {
ISelection selection = tableViewer.getSelection();
Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null;
NamespaceInfo info = (NamespaceInfo) selectedObject;
editButton.setEnabled(info != null);
// $NON-NLS-1$
deleteButton.setEnabled((info != null) && (info.getProperty("unremovable") == null));
}
Aggregations