use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class CMImageUtil method getDeclaration.
public static CMNode getDeclaration(Node node) {
CMNode decl = null;
ModelQuery mq = null;
switch(node.getNodeType()) {
case Node.ATTRIBUTE_NODE:
{
mq = ModelQueryUtil.getModelQuery(((Attr) node).getOwnerDocument());
decl = mq.getCMAttributeDeclaration((Attr) node);
}
break;
case Node.ELEMENT_NODE:
{
mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
decl = mq.getCMElementDeclaration((Element) node);
}
break;
}
return decl;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class XMLAnnotationsView method selectionChanged.
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
IEditorPart edPart = getSite().getPage().getActiveEditor();
if (part.equals(edPart)) {
if (selection instanceof IStructuredSelection) {
currentSelection = (IStructuredSelection) selection;
if (!selection.isEmpty() && (currentSelection.getFirstElement() instanceof Node)) {
Node node = (Node) currentSelection.getFirstElement();
ModelQuery mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
if (mq != null) {
cmNode = mq.getCMNode(node);
MarkupTagInfoProvider tagInfo = new MarkupTagInfoProvider();
xmlDoc = tagInfo.getInfo(cmNode);
} else {
xmlDoc = XMLUIMessages.Documentation_view_default_msg;
}
doStyledTextInput();
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class HTML5ContentModelTest method checkAttrValues.
private void checkAttrValues(String documentKey, String elementName, String attrName, String[] attrValues) {
CMDocument document = HTMLCMDocumentFactory.getCMDocument(documentKey);
CMNode elementDeclaration = document.getElements().getNamedItem(elementName);
assertEquals("not an element declaration:" + elementDeclaration, CMNode.ELEMENT_DECLARATION, elementDeclaration.getNodeType());
assertNotNull("missing element declaration:" + elementName, elementDeclaration);
CMNamedNodeMap attributes = ((CMElementDeclaration) elementDeclaration).getAttributes();
final CMNode node = attributes.getNamedItem(attrName);
assertNotNull("No attribute [" + attrName + "]", node);
final String[] actualValues = ((HTMLAttributeDeclaration) node).getAttrType().getEnumeratedValues();
assertEquals(attrValues.length, actualValues.length);
Set valueSet = new HashSet(actualValues.length);
for (int i = 0; i < actualValues.length; i++) {
valueSet.add(actualValues[i]);
}
for (int i = 0; i < attrValues.length; i++) {
if (!valueSet.remove(attrValues[i]))
fail("Type did not contain attribute value [" + attrValues[i] + "]");
}
assertTrue("Type had unexpected attribute values", valueSet.isEmpty());
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class HTML5ContentModelTest method checkAttrNames.
/**
* @param cm_doc_type
* @param elementName
* @param attrNameImport
*/
private void checkAttrNames(String documentKey, String elementName, String[] attrNames) {
CMDocument document = HTMLCMDocumentFactory.getCMDocument(documentKey);
CMNode elementDeclaration = document.getElements().getNamedItem(elementName);
assertEquals("not an element declaration:" + elementDeclaration, CMNode.ELEMENT_DECLARATION, elementDeclaration.getNodeType());
assertNotNull("missing element declaration:" + elementName, elementDeclaration);
CMNamedNodeMap attributes = ((CMElementDeclaration) elementDeclaration).getAttributes();
for (int i = 0; i < attrNames.length; i++) {
assertNotNull("missing attribute declaration:" + attrNames[i] + " for element: " + elementName, attributes.getNamedItem(attrNames[i]));
}
assertEquals("Attributes defined in content model that are not expected by the test for element: " + elementName, attributes.getLength(), attrNames.length);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class ModelQueryImpl method getOrigin.
public CMNode getOrigin(Node node) {
CMNode result = null;
// todo... make sure parent is right
//
Node parentNode = getParentOrOwnerNode(node);
if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
Element parentElement = (Element) parentNode;
CMNode[] array = getOriginArray(parentElement);
if (array != null) {
int index = getIndexOfNode(parentElement.getChildNodes(), node);
if (index < array.length) {
result = array[index];
}
}
}
return result;
}
Aggregations