use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class HTMLElementAncestorValidator method validate.
/**
* Check exclusion which is defined in only HTML DTD (SGML).
*/
public void validate(IndexedRegion node) {
Element target = (Element) node;
if (CMUtil.isForeign(target))
return;
CMElementDeclaration dec = CMUtil.getDeclaration(target);
if (dec == null)
// cannot validate.
return;
if (!CMUtil.isHTML(dec))
// no need to validate
return;
if (!dec.supports(HTMLCMProperties.PROHIBITED_ANCESTORS))
// cannot validate.
return;
CMNamedNodeMap prohibited = (CMNamedNodeMap) dec.getProperty(HTMLCMProperties.PROHIBITED_ANCESTORS);
if (prohibited.getLength() <= 0)
// no prohibited ancestors.
return;
Element parent = SMUtil.getParentElement(target);
while (parent != null) {
CMNode pdec = prohibited.getNamedItem(parent.getNodeName());
if (pdec != null) {
// prohibited element is found in ancestors.
Segment errorSeg = FMUtil.getSegment((IDOMNode) node, FMUtil.SEG_START_TAG);
if (errorSeg != null)
reporter.report(new ErrorInfoImpl(ErrorState.INVALID_CONTENT_ERROR, errorSeg, target));
// If one prohibited ancestor is found, it's enough.
break;
}
parent = SMUtil.getParentElement(parent);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap 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.CMNamedNodeMap 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