use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method testClone.
private void testClone(IStructuredModel structuredModel) throws IOException {
IDOMDocument document = ((IDOMModel) structuredModel).getDocument();
INodeNotifier notifier = document;
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) notifier.getAdapterFor(ModelQueryAdapter.class);
assertNotNull("initial modelQueryAdapter should not be null", modelQueryAdapter);
IStructuredModel newModel = structuredModel.newInstance();
IDOMDocument newDocument = ((IDOMModel) newModel).getDocument();
INodeNotifier newNotifier = newDocument;
ModelQueryAdapter result = (ModelQueryAdapter) newNotifier.getAdapterFor(ModelQueryAdapter.class);
assertNotNull("newInstance modelQueryAdapter should not be null", result);
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testTagFileHasHTMLContentModel.
public void testTagFileHasHTMLContentModel() 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("<b/>");
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) model.getDocument().getDocumentElement()).getAdapterFor(ModelQueryAdapter.class);
CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration(model.getDocument().getDocumentElement());
assertNotNull("no CMElementDeclaration for 'b'", declaration);
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
project.delete(true, null);
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testTagFileReferencedInTLD.
public void testTagFileReferencedInTLD() throws IOException, CoreException {
String DPROJECT_NAME = "DynamicWebProject";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(DPROJECT_NAME);
if (!project.exists()) {
// Create new project
project = BundleResourceUtil.createSimpleProject(DPROJECT_NAME, null, null);
BundleResourceUtil.copyBundleZippedEntriesIntoWorkspace("/testfiles/jspErrorProject.zip", Path.ROOT);
}
project.refreshLocal(IResource.DEPTH_INFINITE, null);
IFile jspFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.ROOT.append("DynamicWebProject/WebContent/index.jsp"));
assertTrue("test file " + jspFile.getFullPath() + " does not exist", jspFile.exists());
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(jspFile);
String DTAGNAME = "date:returndate";
NodeList returnDates = model.getDocument().getElementsByTagName(DTAGNAME);
assertNotNull("date:returndate was missing from document", returnDates.item(0));
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) returnDates.item(0)).getAdapterFor(ModelQueryAdapter.class);
CMElementDeclaration declaration = modelQueryAdapter.getModelQuery().getCMElementDeclaration((Element) returnDates.item(0));
assertNotNull("no CMElementDeclaration for date:returndate", declaration);
assertEquals("qualified name from element declaration was different", DTAGNAME, declaration.getNodeName());
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class TestTaglibCMTests method testLoadCustomTagsThroughXMLSyntax.
public void testLoadCustomTagsThroughXMLSyntax() throws IOException, CoreException {
IFile jspFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.ROOT.append(PROJECT_NAME).append("web stuff/testX.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 CMElementDeclaration 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.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class LibraryTagsCompletionProposalComputer method forciblyGetTagLibAndJSPElements.
/**
* <p><b>NOTE: </b>This should be removed as soon as Bug 311961 is fixed</p>
* <p>This is bad because it does not use the ModelQuery framework, it
* access the TLDCMDocumentManager directly</p>
* <p>This is essentially a combination of the {@link TaglibModelQueryExtension} and
* the {@link JSPModelQueryExtension} but it means any other extensions get left
* out when creating content assist suggestion at the document root level</p>
*
* @param elementDecls
* @param node
* @param childIndex
* @return
*/
private List forciblyGetTagLibAndJSPElements(List elementDecls, Node node, int childIndex) {
if (node instanceof IDOMNode) {
/*
* find the location of the intended insertion as it will give us
* the correct offset for checking position dependent CMDocuments
*/
int textInsertionOffset = 0;
NodeList children = node.getChildNodes();
if (children.getLength() >= childIndex && childIndex >= 0) {
Node nodeAlreadyAtIndex = children.item(childIndex);
if (nodeAlreadyAtIndex instanceof IDOMNode)
textInsertionOffset = ((IDOMNode) nodeAlreadyAtIndex).getEndOffset();
} else {
textInsertionOffset = ((IDOMNode) node).getStartOffset();
}
TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(((IDOMNode) node).getStructuredDocument());
if (mgr != null) {
List moreCMDocuments = mgr.getCMDocumentTrackers(textInsertionOffset);
if (moreCMDocuments != null) {
for (int i = 0; i < moreCMDocuments.size(); i++) {
CMDocument doc = (CMDocument) moreCMDocuments.get(i);
CMNamedNodeMap elements = doc.getElements();
if (elements != null) {
for (int j = 0; j < elements.getLength(); j++) {
CMElementDeclaration ed = (CMElementDeclaration) elements.item(j);
elementDecls.add(ed);
}
}
}
}
}
// get position dependent CMDocuments and insert their tags as
// proposals
ModelQueryAdapter mqAdapter = null;
if (node.getNodeType() == Node.DOCUMENT_NODE)
mqAdapter = (ModelQueryAdapter) ((IDOMNode) node).getAdapterFor(ModelQueryAdapter.class);
else
mqAdapter = (ModelQueryAdapter) ((IDOMNode) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
if (mqAdapter != null) {
CMDocument doc = mqAdapter.getModelQuery().getCorrespondingCMDocument(node);
if (doc != null) {
CMDocument jcmdoc = getDefaultJSPCMDocument((IDOMNode) node);
CMNamedNodeMap jspelements = jcmdoc.getElements();
/*
* For a built-in JSP action the content model is properly
* set up, so don't just blindly add the rest--unless this
* will be a direct child of the document
*/
if (jspelements != null && (!(doc instanceof JSPCMDocument) || node.getNodeType() == Node.DOCUMENT_NODE)) {
List rejectElements = new ArrayList();
// determine if the document is in XML form
Document domDoc = null;
if (node.getNodeType() == Node.DOCUMENT_NODE)
domDoc = (Document) node;
else
domDoc = node.getOwnerDocument();
// Show XML tag forms of JSP markers if jsp:root is
// the document element OR it's HTML but
// isn't really in the text.
// If the document isn't strictly XML, pull out the
// XML tag forms it is xml format
rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET);
rejectElements.add(JSP12Namespace.ElementName.EXPRESSION);
rejectElements.add(JSP12Namespace.ElementName.DECLARATION);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE);
rejectElements.add(JSP12Namespace.ElementName.TEXT);
rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_TAG);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_ATTRIBUTE);
rejectElements.add(JSP20Namespace.ElementName.DIRECTIVE_VARIABLE);
if (isXMLFormat(domDoc)) {
// jsp actions
rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
rejectElements.add(JSP12Namespace.ElementName.USEBEAN);
rejectElements.add(JSP12Namespace.ElementName.GETPROPERTY);
rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY);
rejectElements.add(JSP12Namespace.ElementName.INCLUDE);
rejectElements.add(JSP12Namespace.ElementName.FORWARD);
rejectElements.add(JSP12Namespace.ElementName.PLUGIN);
rejectElements.add(JSP12Namespace.ElementName.FALLBACK);
rejectElements.add(JSP12Namespace.ElementName.PARAM);
rejectElements.add(JSP12Namespace.ElementName.PARAMS);
}
// don't show jsp:root if a document element already
// exists
Element docElement = domDoc.getDocumentElement();
if (// $NON-NLS-1$
docElement != null && ((docElement.getNodeName().equals("jsp:root")) || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() != null || ((IDOMNode) docElement).getEndStructuredDocumentRegion() != null))))
rejectElements.add(JSP12Namespace.ElementName.ROOT);
for (int j = 0; j < jspelements.getLength(); j++) {
CMElementDeclaration ed = (CMElementDeclaration) jspelements.item(j);
if (rejectElements.contains(ed.getNodeName()))
continue;
elementDecls.add(ed);
}
}
} else // No cm document (such as for the Document (a non-Element) node itself)
{
CMNamedNodeMap jspElements = getDefaultJSPCMDocument((IDOMNode) node).getElements();
int length = jspElements.getLength();
for (int i = 0; i < length; i++) {
elementDecls.add(jspElements.item(i));
}
}
}
}
return elementDecls;
}
Aggregations