use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration 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.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XMLHyperlinkDetector method isLinkableAttr.
/**
* Checks to see if the given attribute is openable. Attribute is openable
* if it is a namespace declaration attribute or if the attribute value is
* of type URI.
*
* @param attr
* cannot be null
* @param cmElement
* CMElementDeclaration associated with the attribute (can be
* null)
* @return true if this attribute is "openOn-able" false otherwise
*/
private boolean isLinkableAttr(Attr attr, CMElementDeclaration cmElement) {
String attrName = attr.getName();
String prefix = DOMNamespaceHelper.getPrefix(attrName);
String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attrName);
// determine if attribute is namespace declaration
if ((XMLNS.equals(prefix)) || (XMLNS.equals(unprefixedName))) {
return true;
}
// determine if attribute contains schema location
if ((XSI_NAMESPACE_URI.equals(DOMNamespaceHelper.getNamespaceURI(attr))) && ((SCHEMA_LOCATION.equals(unprefixedName)) || (NO_NAMESPACE_SCHEMA_LOCATION.equals(unprefixedName)))) {
return true;
}
// determine if attribute value is of type URI
if (cmElement != null) {
CMNamedNodeMap attrDecls = cmElement.getAttributes();
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrDecls);
List nodes = ModelQueryUtil.getModelQuery(attr.getOwnerDocument()).getAvailableContent(attr.getOwnerElement(), cmElement, 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;
CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attrDecls.getNamedItem(attrName);
if ((attrDecl != null) && (attrDecl.getAttrType() != null) && (CMDataType.URI.equals(attrDecl.getAttrType().getDataTypeName()))) {
return true;
}
}
return false;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration 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.CMAttributeDeclaration 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.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class BugFixesTest method testGlobalAttr1Documentation.
private void testGlobalAttr1Documentation(CMNamedNodeMap attributes) {
CMAttributeDeclaration attribute = (CMAttributeDeclaration) attributes.getNamedItem("globalAttr1");
assertNotNull("Missing globalAttr1 attribute.");
CMNodeList documentation = (CMNodeList) attribute.getProperty("documentation");
if (documentation.getLength() == 0) {
fail("Unable to find documentation for globalAttr1");
}
assertEquals("Wrong number of documentation annotations.", 2, documentation.getLength());
assertEquals("Incorrect first annotation for globalAttr1:", "PASS! Documentation for attribute ref overrides the resolved attribute ref documentation", ((DocumentationImpl) documentation.item(0)).getValue().trim());
assertEquals("Incorrect second annotation for globalAttr1:", "PASS! Multiple documentation elements.", ((DocumentationImpl) documentation.item(1)).getValue().trim());
}
Aggregations