use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testLoadCustomTagsThroughJSPSyntax.
public void testLoadCustomTagsThroughJSPSyntax() throws IOException, CoreException {
IFile jspFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.ROOT.append(PROJECT_NAME).append("web stuff/test1.jsp"));
assertTrue("test file " + jspFile.getFullPath() + " does not exist", jspFile.exists());
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(jspFile);
NodeList presents = model.getDocument().getElementsByTagName(TAG_NAME);
assertNotNull(TAG_NAME + " was missing from document", presents.item(0));
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) presents.item(0)).getAdapterFor(ModelQueryAdapter.class);
CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration((Element) presents.item(0));
assertNotNull("no CMElementDelcaration for " + TAG_NAME, declaration);
assertEquals("qualified name from element declaration was different", TAG_NAME, declaration.getNodeName());
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testTagRuntimeExpressionValues.
public void testTagRuntimeExpressionValues() throws Exception {
final String testName = "testLoadTagFiles";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
if (!project.exists()) {
project = BundleResourceUtil.createSimpleProject(testName, null, null);
BundleResourceUtil.copyBundleEntriesIntoWorkspace(TESTFILES_PATHSTRING + testName, "/" + testName);
}
project.refreshLocal(IResource.DEPTH_INFINITE, null);
CMDocumentFactoryTLD factory = new CMDocumentFactoryTLD();
ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/" + testName + "/"));
assertEquals("There should only be one taglib record", 1, records.length);
CMDocument document = factory.createCMDocument(records[0]);
CMNamedNodeMap elements = document.getElements();
assertNotNull("No elements for the CM Document", elements);
CMNode node = elements.getNamedItem("test");
assertTrue("Node must be a CMElementDeclarationImpl", node instanceof CMElementDeclarationImpl);
CMNamedNodeMap attributes = ((CMElementDeclaration) node).getAttributes();
assertNotNull("No attributes", attributes);
node = attributes.getNamedItem("myAttr");
assertTrue("Node must be a CMAttributeDeclarationImpl", node instanceof CMAttributeDeclarationImpl);
assertEquals("Default rtexprvalue for tags should be true", JSP11Namespace.ATTR_VALUE_TRUE, ((CMAttributeDeclarationImpl) node).getRtexprvalue());
node = attributes.getNamedItem("noRuntimeAttr");
assertTrue("Node must be a CMAttributeDeclarationImpl", node instanceof CMAttributeDeclarationImpl);
assertEquals("rtexprvalue for should be false since explicitly set", JSP11Namespace.ATTR_VALUE_FALSE, ((CMAttributeDeclarationImpl) node).getRtexprvalue());
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testTagFileHasTagContentModel.
public void testTagFileHasTagContentModel() throws IOException, CoreException {
String DPROJECT_NAME = getName();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(DPROJECT_NAME);
if (!project.exists()) {
// Create new project
project = BundleResourceUtil.createSimpleProject(DPROJECT_NAME, null, null);
}
project.refreshLocal(IResource.DEPTH_INFINITE, null);
IFile tagFile = project.getFile("test1.tag");
tagFile.create(new ByteArrayInputStream(new byte[0]), IResource.FORCE, null);
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tagFile);
model.getStructuredDocument().set("<" + JSP20Namespace.ElementName.DOBODY + "/>");
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) model.getDocument().getDocumentElement()).getAdapterFor(ModelQueryAdapter.class);
CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration(model.getDocument().getDocumentElement());
assertNotNull("no CMElementDeclaration for '" + JSP20Namespace.ElementName.DOBODY + "'", declaration);
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
project.delete(true, null);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration 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;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration 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();
}
}
}
Aggregations