use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XMLTagInfoHoverProcessor method getCMAttributeDeclaration.
/**
* Retreives CMAttributeDeclaration indicated by attribute name within
* elementDecl
*/
protected CMAttributeDeclaration getCMAttributeDeclaration(IDOMNode node, CMElementDeclaration elementDecl, String attName) {
CMAttributeDeclaration attrDecl = null;
if (elementDecl != null) {
CMNamedNodeMap attributes = elementDecl.getAttributes();
CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes);
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);
}
}
attributes = allAttributes;
String noprefixName = DOMNamespaceHelper.getUnprefixedName(attName);
if (attributes != null) {
attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(noprefixName);
if (attrDecl == null) {
attrDecl = (CMAttributeDeclaration) attributes.getNamedItem(attName);
}
}
}
return attrDecl;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class NamespaceValidator method isUnknownAttr.
private boolean isUnknownAttr(IDOMAttr attr, Element target) {
CMElementDeclaration dec = CMUtil.getDeclaration(target);
if (dec == null)
// unknown.
return true;
CMNamedNodeMap adecls = dec.getAttributes();
CMAttributeDeclaration adec = (CMAttributeDeclaration) adecls.getNamedItem(attr.getName());
return adec == null;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XMLGeneratorImpl method isBooleanAttr.
/**
*/
private boolean isBooleanAttr(Attr attr) {
if (attr == null)
return false;
CMAttributeDeclaration decl = CMNodeUtil.getAttributeDeclaration(attr);
if (decl == null)
return false;
CMDataType type = decl.getAttrType();
if (type == null)
return false;
String[] values = type.getEnumeratedValues();
if (values == null)
return false;
return (values.length == 1 && values[0].equals(decl.getAttrName()));
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class ElementImpl method getDefaultValue.
/**
* Get the implied default value for attribute <code>name</code>
*
* @param name
* @return returns the default value for attribute <code>name</code> if it
* is found in the content model, <code>unknownDefault</code> otherwise
*/
private String getDefaultValue(String name, String unknownDefault) {
synchronized (STACK_LOCK) {
if (fDefaultValueLookups != null && fDefaultValueLookups.contains(name))
return null;
try {
if (fDefaultValueLookups == null)
fDefaultValueLookups = new Stack();
fDefaultValueLookups.push(name);
CMNamedNodeMap map = ((DocumentImpl) getOwnerDocument()).getCMAttributes(this);
if (map != null) {
CMNode attribute = map.getNamedItem(name);
if (attribute instanceof CMAttributeDeclaration)
return ((CMAttributeDeclaration) attribute).getAttrType().getImpliedValue();
}
return unknownDefault;
} finally {
fDefaultValueLookups.pop();
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration in project webtools.sourceediting by eclipse.
the class ElementNodeCleanupHandler 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();
Iterator it = attrMap.iterator();
CMAttributeDeclaration attr = null;
while (it.hasNext()) {
attr = (CMAttributeDeclaration) it.next();
if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) {
result.add(attr);
}
}
}
}
return result;
}
Aggregations