use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode 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.CMNode 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.CMNode in project webtools.sourceediting by eclipse.
the class BugFixesTest method testForBug176420.
public void testForBug176420() {
// Obtain the model from /testresources/samples/testSchemaForBug176420.xsd
Bundle bundle = Platform.getBundle("org.eclipse.wst.xsd.core.tests");
URL url = bundle.getEntry("/testresources/samples/testSchemaForBug176420.xsd");
CMDocument document = XSDImpl.buildCMDocument(url.toExternalForm());
assertNotNull("Content model loaded Null", document);
// Obtain the enumerated values of the root element
CMNode cmNode = document.getElements().item(0);
String[] enumeratedValues = ((CMElementDeclaration) cmNode).getDataType().getEnumeratedValues();
// Verify that all 12 enumerated values are included
assertEquals(12, enumeratedValues.length);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class BugFixesTest method testXSIType.
// Add tests here
@SuppressWarnings("unchecked")
public void testXSIType() {
String soapSchemaURI = locateFileUsingCatalog("http://schemas.xmlsoap.org/wsdl/soap/");
CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
assertNotNull("Assert factory is not null", factory);
CMDocument cmDocument = factory.createCMDocument(soapSchemaURI);
assertNotNull("Assert CMDocument is not null", cmDocument);
CMNamedNodeMap elements = cmDocument.getElements();
boolean foundDesiredElement = false;
for (Iterator<CMElementDeclaration> i = elements.iterator(); i.hasNext(); ) {
CMElementDeclaration element = i.next();
if ("binding".equals(element.getElementName())) {
foundDesiredElement = true;
CMNamedNodeMap attributes = element.getAttributes();
// Three attributes: required, transport and style
assertNotNull(attributes);
// If the xsi:type was present, it would be 4 attributes
assertTrue(attributes.getLength() == 3);
CMNode attrNode = null;
attrNode = attributes.getNamedItem("required");
assertNotNull(attrNode);
attrNode = attributes.getNamedItem("transport");
assertNotNull(attrNode);
attrNode = attributes.getNamedItem("style");
assertNotNull(attrNode);
// Should be null!
attrNode = attributes.getNamedItem("type");
assertNull(attrNode);
break;
}
}
// if we didn't even find the binding element, then something terrible went wrong
assertTrue(foundDesiredElement);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method getValidChildElementDeclarations.
// returns a list of CMNodes that can be validly inserted at this
// childPosition
// Given the grammar shown below and a snippet of XML code (where the '|'
// indicated the cursor position)
// the list would return only the element declarations can be inserted
// while maintaing validity of the content.
//
// grammar : Foo -> (A, B, C)
// snippet : <Foo><A>|
// result : {B}
//
protected List getValidChildElementDeclarations(Element parent, int childPosition, int kindOfAction) {
List modelQueryActions = getAvailableChildrenAtIndex(parent, childPosition, ModelQuery.VALIDITY_STRICT);
Iterator iterator = modelQueryActions.iterator();
List cmnodes = new Vector();
while (iterator.hasNext()) {
ModelQueryAction action = (ModelQueryAction) iterator.next();
if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())) && (action.getKind() == kindOfAction))) {
CMNode actionCMNode = action.getCMNode();
if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
cmnodes.add(actionCMNode);
}
}
}
return cmnodes;
}
Aggregations