use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration 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.CMElementDeclaration 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.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class InferredGrammarFactory method debugPrint.
public void debugPrint(Collection collection) {
for (Iterator iter = collection.iterator(); iter.hasNext(); ) {
CMDocument cmDocument = (CMDocument) iter.next();
// $NON-NLS-1$
System.out.println("-----------------------------------------------");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
System.out.println("cmDocument (" + cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI") + ")");
CMNamedNodeMapImpl elementMap = (CMNamedNodeMapImpl) cmDocument.getElements();
int size = elementMap.getLength();
for (int i = 0; i < size; i++) {
CMElementDeclaration ed = (CMElementDeclaration) elementMap.item(i);
CMDescriptionBuilder builder = new CMDescriptionBuilder();
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println(" ELEMENT " + ed.getNodeName() + " = " + builder.buildDescription(ed));
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class CMDocumentFactoryTLD method buildCMDocumentFromFolder.
/**
* @param fileName
* @return
*/
private CMDocumentImpl buildCMDocumentFromFolder(IPath path) {
if (_debug) {
// $NON-NLS-1$
System.out.println("tagdir loading for " + path);
}
// EBNF is listed at 1.3.10
CMDocumentImpl document = new CMDocumentImpl();
document.setBaseLocation(path.toString());
// $NON-NLS-1$
document.setTlibversion("1.0");
IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
IResource[] tagfiles;
try {
tagfiles = folder.members();
for (int i = 0; i < tagfiles.length; i++) {
if (tagfiles[i].getType() == IResource.FILE) {
if (tagfiles[i].getType() != IResource.FILE)
continue;
String extension = tagfiles[i].getFileExtension();
if (extension != null && (extension.equals("tag") || extension.equals("tagx"))) {
CMElementDeclaration ed = createElementDeclaration(document, (IFile) tagfiles[i]);
if (ed != null) {
document.fElements.setNamedItem(ed.getNodeName(), ed);
}
}
}
}
} catch (CoreException e) {
Logger.logException(e);
}
return document;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class AbstractBreakpointProvider method isCustomTagRegion.
private static boolean isCustomTagRegion(IndexedRegion node) {
if (node instanceof Element) {
Element xmlElement = (Element) node;
ModelQuery mq = ModelQueryUtil.getModelQuery(xmlElement.getOwnerDocument());
CMElementDeclaration decl = mq.getCMElementDeclaration(xmlElement);
if (decl instanceof CMNodeWrapper) {
CMNode cmNode = ((CMNodeWrapper) decl).getOriginNode();
return cmNode instanceof TLDElementDeclaration;
}
}
return false;
}
Aggregations