Search in sources :

Example 51 with CMDocument

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

the class JSPModelQueryCMProvider method getCorrespondingCMDocument.

/**
 * Returns the CMDocument that corresponds to the DOM Node. or null if no
 * CMDocument is appropriate for the DOM Node.
 */
public CMDocument getCorrespondingCMDocument(Node node) {
    CMDocument jcmdoc = null;
    if (node instanceof IDOMNode) {
        IDOMModel model = ((IDOMNode) node).getModel();
        String modelPath = model.getBaseLocation();
        if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
            float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
            jcmdoc = JSPCMDocumentFactory.getCMDocument(version);
        }
    }
    if (jcmdoc == null) {
        jcmdoc = JSPCMDocumentFactory.getCMDocument();
    }
    CMDocument result = null;
    try {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String elementName = node.getNodeName();
            // test to see if this node belongs to JSP's CMDocument (case
            // sensitive)
            CMElementDeclaration dec = (CMElementDeclaration) jcmdoc.getElements().getNamedItem(elementName);
            if (dec != null) {
                result = jcmdoc;
            }
        }
        String prefix = node.getPrefix();
        if (result == null && prefix != null && prefix.length() > 0 && node instanceof IDOMNode) {
            // check position dependent
            IDOMNode xmlNode = (IDOMNode) node;
            TLDCMDocumentManager tldmgr = TaglibController.getTLDCMDocumentManager(xmlNode.getStructuredDocument());
            if (tldmgr != null) {
                List documents = tldmgr.getCMDocumentTrackers(node.getPrefix(), xmlNode.getStartOffset());
                // there shouldn't be more than one cmdocument returned
                if (documents != null && documents.size() > 0)
                    result = (CMDocument) documents.get(0);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Path(org.eclipse.core.runtime.Path) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) List(java.util.List)

Example 52 with CMDocument

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

the class TagModelQueryCMProvider method getCorrespondingCMDocument.

/**
 * Returns the CMDocument that corresponds to the DOM Node. or null if no
 * CMDocument is appropriate for the DOM Node.
 */
public CMDocument getCorrespondingCMDocument(Node node) {
    CMDocument tagdoc = null;
    if (node instanceof IDOMNode) {
        IDOMModel model = ((IDOMNode) node).getModel();
        String modelPath = model.getBaseLocation();
        if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
            float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
            tagdoc = TAGCMDocumentFactory.getCMDocument(version);
        }
    }
    CMDocument result = null;
    try {
        if (node.getNodeType() == Node.ELEMENT_NODE && tagdoc != null) {
            String elementName = node.getNodeName();
            // test to see if this node belongs to JSP's CMDocument (case
            // sensitive)
            CMElementDeclaration dec = (CMElementDeclaration) tagdoc.getElements().getNamedItem(elementName);
            if (dec != null) {
                result = tagdoc;
            }
        }
        String prefix = node.getPrefix();
        if (result == null && prefix != null && prefix.length() > 0 && node instanceof IDOMNode) {
            // check position dependent
            IDOMNode xmlNode = (IDOMNode) node;
            TLDCMDocumentManager tldmgr = TaglibController.getTLDCMDocumentManager(xmlNode.getStructuredDocument());
            if (tldmgr != null) {
                List documents = tldmgr.getCMDocumentTrackers(node.getPrefix(), xmlNode.getStartOffset());
                // there shouldn't be more than one cmdocument returned
                if (documents != null && !documents.isEmpty())
                    result = (CMDocument) documents.get(0);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    // }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Path(org.eclipse.core.runtime.Path) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) List(java.util.List)

Example 53 with CMDocument

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

the class HTML5ContentModelTest method checkAttrValues.

private void checkAttrValues(String documentKey, String elementName, String attrName, String[] attrValues) {
    CMDocument document = HTMLCMDocumentFactory.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();
    final CMNode node = attributes.getNamedItem(attrName);
    assertNotNull("No attribute [" + attrName + "]", node);
    final String[] actualValues = ((HTMLAttributeDeclaration) node).getAttrType().getEnumeratedValues();
    assertEquals(attrValues.length, actualValues.length);
    Set valueSet = new HashSet(actualValues.length);
    for (int i = 0; i < actualValues.length; i++) {
        valueSet.add(actualValues[i]);
    }
    for (int i = 0; i < attrValues.length; i++) {
        if (!valueSet.remove(attrValues[i]))
            fail("Type did not contain attribute value [" + attrValues[i] + "]");
    }
    assertTrue("Type had unexpected attribute values", valueSet.isEmpty());
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Set(java.util.Set) HashSet(java.util.HashSet) 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) HashSet(java.util.HashSet)

Example 54 with CMDocument

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

the class HTML5ContentModelTest method checkAttrNames.

/**
 * @param cm_doc_type
 * @param elementName
 * @param attrNameImport
 */
private void checkAttrNames(String documentKey, String elementName, String[] attrNames) {
    CMDocument document = HTMLCMDocumentFactory.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] + " for element: " + elementName, attributes.getNamedItem(attrNames[i]));
    }
    assertEquals("Attributes defined in content model that are not expected by the test for element: " + elementName, 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 55 with CMDocument

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

the class CMDocumentManagerImpl method getCMDocument.

public CMDocument getCMDocument(String publicId) {
    CMDocument result = null;
    String resolvedURI = lookupResolvedURI(publicId);
    if (resolvedURI != null) {
        result = cmDocumentCache.getCMDocument(resolvedURI);
    }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Aggregations

CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)83 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)33 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)26 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)20 List (java.util.List)15 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)14 Document (org.w3c.dom.Document)12 Element (org.w3c.dom.Element)11 ArrayList (java.util.ArrayList)10 Path (org.eclipse.core.runtime.Path)8 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)8 JSPCMDocument (org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument)7 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 URL (java.net.URL)6 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)6 Node (org.w3c.dom.Node)6 NodeList (org.w3c.dom.NodeList)6 Iterator (java.util.Iterator)5 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)5