use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class JSPModelLoader method createModel.
public IStructuredModel createModel(IStructuredModel oldModel) {
IStructuredModel model = super.createModel(oldModel);
// For JSPs, the ModelQueryAdapter must be "attached" to the document
// before content is set in the model, so taglib initialization can
// take place.
// In this "clone model" case, we create a ModelQuery adapter
// create a new instance from the old data. Note: I think this
// "forced fit" only works here since the implementation of
// ModelQueryAdapter does not
// have to be released.
ModelQueryAdapter modelQueryAdapter = getModelQueryAdapter(model);
if (modelQueryAdapter == null) {
modelQueryAdapter = getModelQueryAdapter(oldModel);
IDOMDocument document = ((IDOMModel) model).getDocument();
document.addAdapter(new JSPModelQueryAdapterImpl(modelQueryAdapter.getCMDocumentCache(), modelQueryAdapter.getModelQuery(), modelQueryAdapter.getIdResolver()));
}
return model;
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class JSPModelLoader method getModelQueryAdapter.
private ModelQueryAdapter getModelQueryAdapter(IStructuredModel model) {
IDOMDocument document = ((IDOMModel) model).getDocument();
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) ((INodeNotifier) document).getAdapterFor(ModelQueryAdapter.class);
return modelQueryAdapter;
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class JSPModelQueryImpl method getEmbeddedModelQuery.
// ISSUE: shouldn't this be private?
protected ModelQuery getEmbeddedModelQuery(Node node) {
ModelQuery embeddedModelQuery = null;
if (node instanceof INodeNotifier) {
Node ownerNode = node.getOwnerDocument();
if (ownerNode == null) {
// then must be the document itself
ownerNode = node;
}
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) ownerNode).getAdapterFor(PageDirectiveAdapter.class);
if (pageDirectiveAdapter != null) {
String effectiveContentType = null;
ModelQuery potentialModelQueryObject = null;
String familyId = pageDirectiveAdapter.getEmbeddedType().getFamilyId();
if (ContentTypeFamilyForHTML.HTML_FAMILY.equals(familyId)) {
effectiveContentType = "text/html";
} else {
effectiveContentType = pageDirectiveAdapter.getContentType();
}
potentialModelQueryObject = (ModelQuery) embeddedModelQueries.get(effectiveContentType);
if (potentialModelQueryObject == null) {
ModelQueryAdapter embeddedAdapter = (ModelQueryAdapter) pageDirectiveAdapter.adapt((INodeNotifier) node, ModelQueryAdapter.class);
if (embeddedAdapter != null) {
// we will cache one model query per content type
embeddedModelQuery = embeddedAdapter.getModelQuery();
embeddedModelQueries.put(effectiveContentType, embeddedModelQuery);
}
} else {
embeddedModelQuery = potentialModelQueryObject;
}
}
}
return embeddedModelQuery;
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter in project webtools.sourceediting by eclipse.
the class JSPModelQueryExtension method getAvailableElementContent.
/**
* Originally taken from JSPContentAssistProcessor
*
* @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension#getAvailableElementContent(org.w3c.dom.Element, java.lang.String, int)
*/
public CMNode[] getAvailableElementContent(Element parentElement, String namespace, int includeOptions) {
CMNode[] nodes = EMPTY_CMNODE_ARRAY;
ArrayList nodeList = new ArrayList();
// only returns anything if looking for child nodes
if (((includeOptions & ModelQuery.INCLUDE_CHILD_NODES) != 0) && parentElement instanceof IDOMNode) {
IDOMNode node = (IDOMNode) parentElement;
// get position dependent CMDocuments and insert their tags as
// proposals
ModelQueryAdapter mqAdapter = null;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
mqAdapter = (ModelQueryAdapter) 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(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 (docElement != null && ((docElement.getNodeName().equals(TAG_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())) {
nodeList.add(ed);
}
}
}
} else // No cm document (such as for the Document (a non-Element) node itself)
{
CMNamedNodeMap jspElements = getDefaultJSPCMDocument(node).getElements();
int length = jspElements.getLength();
for (int i = 0; i < length; i++) {
nodeList.add(jspElements.item(i));
}
}
}
nodes = (CMNode[]) nodeList.toArray(new CMNode[nodeList.size()]);
}
return nodes;
}
use of org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter 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();
}
}
}
Aggregations