Search in sources :

Example 21 with CMNamedNodeMap

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.

the class TestFixedCMDocuments method checkDocument.

private void checkDocument(Object documentKey) {
    CMDocument document = JSPCMDocumentFactory.getCMDocument(documentKey.toString());
    assertNotNull("missing doc:" + documentKey.toString(), document);
    CMNamedNodeMap elements = document.getElements();
    for (int i = 0; i < elements.getLength(); i++) {
        CMNode item = elements.item(i);
        verifyElementDeclarationHasName(item);
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 22 with CMNamedNodeMap

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.

the class TestFixedCMDocuments method checkAttrNames.

/**
 * @param cm_doc_type
 * @param elementName
 * @param attrNameImport
 */
private void checkAttrNames(String documentKey, String elementName, String[] attrNames) {
    CMDocument document = JSPCMDocumentFactory.getCMDocument(documentKey);
    CMNode elementDeclaration = document.getElements().getNamedItem(elementName);
    assertEquals("not an element declaration:" + elementDeclaration, CMNode.ELEMENT_DECLARATION, elementDeclaration.getNodeType());
    assertNotNull("missing element declaration:" + elementName, elementDeclaration);
    CMNamedNodeMap attributes = ((CMElementDeclaration) elementDeclaration).getAttributes();
    for (int i = 0; i < attrNames.length; i++) {
        assertNotNull("missing attribute declaration:" + attrNames[i], attributes.getNamedItem(attrNames[i]));
    }
    assertEquals("Attributes defined in content model that are not expected by the test", attributes.getLength(), attrNames.length);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 23 with CMNamedNodeMap

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.

the class DocumentImpl method getCMAttributes.

/**
 * Provides an element's attribute declarations
 * @param element the element to retrieve the attribute map of
 * @return a <code>CMNamedNodeMap</code> of attributes if the declaration exists; null otherwise.
 */
CMNamedNodeMap getCMAttributes(Element element) {
    CMNamedNodeMap map = (CMNamedNodeMap) fCMCache.get(element);
    if (map == null) {
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(this);
        CMElementDeclaration decl = modelQuery != null ? modelQuery.getCMElementDeclaration(element) : null;
        if (decl != null) {
            map = decl.getAttributes();
            fCMCache.put(element, map);
        }
    }
    return map;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 24 with CMNamedNodeMap

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.

the class DocumentImpl method getCharValue.

/**
 * getCharValue method
 *
 * @return java.lang.String
 * @param name
 *            java.lang.String
 */
protected String getCharValue(String name) {
    if (name == null)
        return null;
    int length = name.length();
    if (length == 0)
        return null;
    if (name.charAt(0) == '#') {
        // character reference
        if (length == 1)
            return null;
        int radix = 10;
        String s = null;
        // now allow hexadecimal also for non XML document
        if (name.charAt(1) == 'x') {
            // hexadecimal
            radix = 16;
            s = name.substring(2);
        } else {
            // decimal
            s = name.substring(1);
        }
        if (s == null || s.length() == 0)
            return null;
        if (s.charAt(0) == '-')
            // no minus accepted
            return null;
        char c = 0;
        try {
            c = (char) Integer.parseInt(s, radix);
        } catch (NumberFormatException ex) {
        }
        if (c == 0)
            return null;
        return String.valueOf(c);
    }
    // implicit character entities for XML
    if (name.equals(IXMLCharEntity.LT_NAME))
        return IXMLCharEntity.LT_VALUE;
    if (name.equals(IXMLCharEntity.GT_NAME))
        return IXMLCharEntity.GT_VALUE;
    if (name.equals(IXMLCharEntity.AMP_NAME))
        return IXMLCharEntity.AMP_VALUE;
    if (name.equals(IXMLCharEntity.QUOT_NAME))
        return IXMLCharEntity.QUOT_VALUE;
    if (isXMLType()) {
        if (name.equals(IXMLCharEntity.APOS_NAME))
            return IXMLCharEntity.APOS_VALUE;
    }
    CMDocument cm = getCMDocument();
    if (cm != null) {
        CMNamedNodeMap map = cm.getEntities();
        if (map != null) {
            CMEntityDeclaration decl = (CMEntityDeclaration) map.getNamedItem(name);
            if (decl != null) {
                String value = decl.getValue();
                if (value == null)
                    return null;
                int valueLength = value.length();
                if (valueLength > 1 && value.charAt(0) == '&' && value.charAt(1) == '#' && value.charAt(valueLength - 1) == ';') {
                    // character reference
                    return getCharValue(value.substring(1, valueLength - 1));
                }
                return value;
            }
        }
    }
    return null;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMEntityDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 25 with CMNamedNodeMap

use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.

the class DOMContentBuilderImpl method visitCMElementDeclaration.

public void visitCMElementDeclaration(CMElementDeclaration ed) {
    int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
    int min = Math.max(ed.getMinOccur(), forcedMin);
    // a group.
    if (!cmGroupStack.isEmpty()) {
        CMGroup group = (CMGroup) cmGroupStack.peek();
        int gmin = group.getMinOccur();
        if (gmin == 0)
            if (buildOptionalElements(buildPolicy)) {
            /* do nothing: min = min */
            } else {
                // min = 0
                min = min * gmin;
            }
        else {
            min = min * gmin;
        }
    }
    int max = Math.min(ed.getMaxOccur(), getNumOfRepeatableElements());
    if (max < min)
        max = min;
    alwaysVisit = false;
    // involved.
    if (// leave
    buildFirstSubstitution(buildPolicy) || isAbstract(ed)) // this
    // for
    // backward
    // compatibility
    // for now
    {
        // Note - To change so that if ed is optional, we do not
        // generate anything here.
        ed = getSubstitution(ed);
    // Note - the returned ed may be an abstract element in
    // which case the xml will be invalid.
    }
    if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) {
        visitedCMElementDeclarationList.add(ed);
        for (int i = 1; i <= max; i++) {
            // create an Element for each
            Element element = null;
            if (rootElement != null) {
                element = rootElement;
                rootElement = null;
            } else {
                element = createElement(ed, computeName(ed, currentParent), currentParent);
            }
            // visit the children of the GrammarElement
            Node oldParent = currentParent;
            currentParent = element;
            handlePushParent(element, ed);
            namespaceTable.addElement(element);
            boolean oldAttachNodesToParent = attachNodesToParent;
            attachNodesToParent = true;
            // instead of calling super.visitCMElementDeclaration()
            // we duplicate the code with some minor modifications
            CMNamedNodeMap nodeMap = ed.getAttributes();
            int size = nodeMap.getLength();
            for (int j = 0; j < size; j++) {
                visitCMNode(nodeMap.item(j));
            }
            CMContent content = ed.getContent();
            if (content != null) {
                visitCMNode(content);
            }
            if (ed.getContentType() == CMElementDeclaration.PCDATA) {
                CMDataType dataType = ed.getDataType();
                if (dataType != null) {
                    visitCMDataType(dataType);
                }
            }
            // end duplication
            attachNodesToParent = oldAttachNodesToParent;
            handlePopParent(element, ed);
            currentParent = oldParent;
            linkNode(element);
        }
        int size = visitedCMElementDeclarationList.size();
        visitedCMElementDeclarationList.remove(size - 1);
    }
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) CMAnyElement(org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent)

Aggregations

CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)68 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)39 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)36 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)26 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)23 List (java.util.List)21 ArrayList (java.util.ArrayList)18 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)16 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)14 Element (org.w3c.dom.Element)14 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)13 NamedNodeMap (org.w3c.dom.NamedNodeMap)10 CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)9 NodeList (org.w3c.dom.NodeList)9 Iterator (java.util.Iterator)8 Attr (org.w3c.dom.Attr)8 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)7 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)6 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)6 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)6