use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class ModelQueryTester method testDTDLoadFromSystemID_1.
/**
* A short test to ensure that a DTD can be loaded from a system
* reference.
*
* Note: May require a functioning network connection for the references
* to be resolved properly.
*
* @throws IOException
*/
public void testDTDLoadFromSystemID_1() throws IOException {
if (testShippedDTDLookup) {
setUpXML();
URL installationPath = Platform.getBundle(JSPUITestsPlugin.ID).getEntry("/");
String diskLocation = null;
diskLocation = FileLocator.resolve(installationPath).toExternalForm();
assertTrue("failed to resolve plugin install path", diskLocation != null);
String content = "<?xml version=\"1.0\"?><!DOCTYPE html SYSTEM " + diskLocation + "TestFiles/DTDs/wapDTDs/WAP-2-0/wml20.dtd\"" + "><html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:wml=\"http://www.wapforum.org/2001/wml\"></html>";
fModel.getStructuredDocument().set(content);
CMDocumentManager documentManagaer = fModelQuery.getCMDocumentManager();
documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, false);
documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, true);
Node domNode = (Node) fModel.getIndexedRegion(content.length() - 2);
CMNode node = fModelQuery.getCMNode(domNode);
assertTrue("wml20.dtd failed to load", node != null && node.getNodeName().equalsIgnoreCase("html"));
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class TestIndex method testUtilityProjectSupport.
public void testUtilityProjectSupport() throws Exception {
// Create project 1
IProject project = BundleResourceUtil.createSimpleProject("test-jar", null, null);
assertTrue(project.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug183756/test-jar", "/test-jar");
// Create project 2
IProject project2 = BundleResourceUtil.createSimpleProject("test-war", null, null);
assertTrue(project2.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug183756/test-war", "/test-war");
IFile testFile = project2.getFile(new Path("src/main/webapp/test.jsp"));
assertTrue("missing test JSP file!", testFile.isAccessible());
IDOMModel jspModel = null;
try {
jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(testFile);
NodeList tests = jspModel.getDocument().getElementsByTagName("test:test");
assertTrue("test:test element not found", tests.getLength() > 0);
CMElementDeclaration elementDecl = ModelQueryUtil.getModelQuery(jspModel).getCMElementDeclaration(((Element) tests.item(0)));
assertNotNull("No element declaration was found for test:test at runtime", elementDecl);
assertTrue("element declaration was not the expected kind", elementDecl instanceof CMNodeWrapper);
CMNode originNode = ((CMNodeWrapper) elementDecl).getOriginNode();
assertTrue("element declaration was not from a tag library", originNode instanceof TLDElementDeclaration);
assertEquals("element declaration was not from expected tag library", "http://foo.com/testtags", ((TLDDocument) ((TLDElementDeclaration) originNode).getOwnerDocument()).getUri());
} finally {
if (jspModel != null) {
jspModel.releaseFromRead();
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode in project webtools.sourceediting by eclipse.
the class TestFixedCMDocuments method verifyElementDeclarationHasName.
private void verifyElementDeclarationHasName(CMNode item) {
assertTrue(item.getNodeType() == CMNode.ELEMENT_DECLARATION);
assertNotNull("no name on an element declaration", item.getNodeName());
CMNamedNodeMap attrs = ((CMElementDeclaration) item).getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
CMNode attr = attrs.item(i);
verifyAttributeDeclaration(((CMElementDeclaration) item), attr);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode 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);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNode 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);
}
Aggregations