use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class QuickAssistProcessorXML method getRequiredAttrs.
protected List getRequiredAttrs(Node node) {
List result = new ArrayList();
ModelQuery modelQuery = getModelQuery(node);
if (modelQuery != null) {
CMElementDeclaration elementDecl = modelQuery.getCMElementDeclaration((Element) node);
if (elementDecl != null) {
CMNamedNodeMap attrMap = elementDecl.getAttributes();
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrMap);
List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
for (int k = 0; k < nodes.size(); k++) {
CMNode cmnode = (CMNode) nodes.get(k);
if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
allAttributes.put(cmnode);
}
}
attrMap = allAttributes;
Iterator it = attrMap.iterator();
CMAttributeDeclaration attr = null;
while (it.hasNext()) {
attr = (CMAttributeDeclaration) it.next();
if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) {
result.add(attr);
}
}
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class XMLHyperlinkDetector method getLinkableAttr.
/**
* Attempts to find an attribute within element that is openable.
*
* @param element -
* cannot be null
* @return Attr attribute that can be used for open on, null if no
* attribute could be found
*/
private Attr getLinkableAttr(Element element) {
CMElementDeclaration ed = getCMElementDeclaration(element);
// get the list of attributes for this node
NamedNodeMap attrs = element.getAttributes();
for (int i = 0; i < attrs.getLength(); ++i) {
// check if this attribute is "openOn-able"
Attr att = (Attr) attrs.item(i);
if (isLinkableAttr(att, ed)) {
return att;
}
}
return null;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class XMLPropertySource method resetPropertyValue.
/**
* Resets the specified property's value to its default value.
*/
public void resetPropertyValue(Object propertyObject) {
String property = propertyObject.toString();
CMNamedNodeMap attrDecls = null;
CMElementDeclaration ed = getDeclaration();
if (ed != null) {
attrDecls = ed.getAttributes();
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrDecls);
List nodes = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()).getAvailableContent((Element) fNode, ed, ModelQuery.INCLUDE_ATTRIBUTES);
for (int k = 0; k < nodes.size(); k++) {
CMNode cmnode = (CMNode) nodes.get(k);
if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
allAttributes.put(cmnode);
}
}
attrDecls = allAttributes;
}
NamedNodeMap attrMap = fNode.getAttributes();
if (attrDecls != null) {
CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attrDecls.getNamedItem(property);
String defValue = null;
if (attrDecl != null) {
if (attrDecl.getAttrType() != null) {
CMDataType helper = attrDecl.getAttrType();
if ((helper.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && (helper.getImpliedValue() != null)) {
defValue = helper.getImpliedValue();
}
}
}
if ((defValue != null) && (defValue.length() > 0)) {
// implied values will be in the DOM, but not the source
attrMap.removeNamedItem(property);
} else {
// $NON-NLS-1$
((Attr) attrMap.getNamedItem(property)).setValue("");
}
} else {
// remember, this method is for reset, not remove
// $NON-NLS-1$
((Attr) attrMap.getNamedItem(property)).setValue("");
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class BugFixesTest method testXSITypeVsTypeAttr.
public void testXSITypeVsTypeAttr() {
// See bug 225447, 225819
// Load the XSD file
String XSD_FILE_NAME = "XSITypeTest.xsd";
String fileURI = FILE_PROTOCOL + PLUGIN_ABSOLUTE_PATH + SAMPLES_DIR + XSD_FILE_NAME;
CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
assertNotNull("Assert factory is not null", factory);
CMDocument cmDocument = factory.createCMDocument(fileURI);
assertNotNull("Assert CMDocument is not null", cmDocument);
// Check and obtain the two global elements (elementA and elementB)
CMNamedNodeMap elements = cmDocument.getElements();
assertEquals(elements.getLength(), 2);
CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) elements.item(0);
CMElementDeclaration cmElementDeclarationA = null;
CMElementDeclaration cmElementDeclarationB = null;
if ("elementA".equals(cmElementDeclaration.getElementName())) {
cmElementDeclarationA = cmElementDeclaration;
cmElementDeclarationB = (CMElementDeclaration) elements.item(1);
} else {
cmElementDeclarationB = cmElementDeclaration;
cmElementDeclarationA = (CMElementDeclaration) elements.item(1);
}
// elementA has a "type" attribute with "X" enumerated value, make sure it appears in the model
CMNamedNodeMap attributesA = cmElementDeclarationA.getAttributes();
assertEquals(attributesA.getLength(), 1);
CMAttributeDeclaration cmAttributeDeclarationA = (CMAttributeDeclaration) attributesA.item(0);
assertEquals("type", cmAttributeDeclarationA.getAttrName());
CMDataType attrTypeA = cmAttributeDeclarationA.getAttrType();
String[] enumeratedValuesA = attrTypeA.getEnumeratedValues();
assertEquals(1, enumeratedValuesA.length);
assertEquals("X", enumeratedValuesA[0]);
// elementB does not have a "type" attribute, make sure the xsi:type appears in the model
CMNamedNodeMap attributesB = cmElementDeclarationB.getAttributes();
assertEquals(attributesB.getLength(), 1);
CMAttributeDeclaration cmAttributeDeclarationB = (CMAttributeDeclaration) attributesB.item(0);
assertEquals("type", cmAttributeDeclarationB.getAttrName());
CMDataType attrTypeB = cmAttributeDeclarationB.getAttrType();
assertEquals("typeNames", attrTypeB.getDataTypeName());
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class BugFixesTest method testGlobalElementDocumentation.
public void testGlobalElementDocumentation() {
// See bug 157254
Bundle bundle = Platform.getBundle("org.eclipse.wst.xsd.core.tests");
URL url = bundle.getEntry("/testresources/samples/documentation/globalreftest.xsd");
CMDocument document = XSDImpl.buildCMDocument(url.toExternalForm());
assertNotNull("Content model loaded Null", document);
CMNamedNodeMap elements = document.getElements();
CMElementDeclaration node = (CMElementDeclaration) elements.getNamedItem("rootTest");
assertNotNull("Missing rootElement", node);
CMElementDeclaration testElement = (CMElementDeclaration) node.getLocalElements().getNamedItem("test");
assertNotNull("Missing test element", testElement);
CMNodeList documentation = (CMNodeList) testElement.getProperty("documentation");
if (documentation.getLength() == 0) {
fail("test global element missing documentation.");
}
for (int cnt = 0; cnt < documentation.getLength(); cnt++) {
DocumentationImpl doc = (DocumentationImpl) documentation.item(cnt);
assertEquals("Test global element missing documentation.", "This some global documentation", doc.getValue());
}
testElement = (CMElementDeclaration) node.getLocalElements().getNamedItem("testElement");
documentation = (CMNodeList) testElement.getProperty("documentation");
if (documentation.getLength() == 0) {
fail("testElement local element missing documentation.");
}
for (int cnt = 0; cnt < documentation.getLength(); cnt++) {
DocumentationImpl doc = (DocumentationImpl) documentation.item(cnt);
assertEquals("testElement documentation wrong.", "This is an override", doc.getValue());
}
}
Aggregations