Search in sources :

Example 51 with CMAttributeDeclaration

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;
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) List(java.util.List) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 52 with CMAttributeDeclaration

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;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 53 with CMAttributeDeclaration

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()));
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 54 with CMAttributeDeclaration

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();
        }
    }
}
Also used : CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Stack(java.util.Stack)

Example 55 with CMAttributeDeclaration

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;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Aggregations

CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)57 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)30 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)29 List (java.util.List)24 ArrayList (java.util.ArrayList)18 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)17 NamedNodeMap (org.w3c.dom.NamedNodeMap)17 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)14 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)13 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)12 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)12 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)11 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)11 Attr (org.w3c.dom.Attr)11 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)10 Element (org.w3c.dom.Element)10 Iterator (java.util.Iterator)9 NodeList (org.w3c.dom.NodeList)8 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)7 HashMap (java.util.HashMap)4