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;
}
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;
}
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());
}
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);
}
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;
}
Aggregations