Author: ayukhovich
Date: 2007-10-02 11:36:48 -0400 (Tue, 02 Oct 2007)
New Revision: 3967
Added:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/TLDEditorDocumentManager.java
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/XHTMLTaglibController.java
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelhandler/
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelhandler/ModelHandlerForXHTML.java
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelhandler/XHTMLModelLoader.java
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelquery/
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelquery/ModelQueryAdapterFactoryForXHTML.java
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelquery/XHTMLModelQueryCMProvider.java
Modified:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/plugin.properties
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/RedHatHtmlContentAssistProcessor.java
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/RedHatJSPContentAssistProcessor.java
Log:
Initial commit
Modified:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/plugin.properties
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/plugin.properties 2007-10-02
15:34:02 UTC (rev 3966)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/plugin.properties 2007-10-02
15:36:48 UTC (rev 3967)
@@ -7,3 +7,4 @@
occurrenceStructureProvidersExtensionPoint= Occurrence Structure Providers
defaultOccurrenceStructureProviderName= Default Occurrence Provider
+%Structured_XHTML_Document_Setup_participant.name=XHTML
Modified:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2007-10-02
15:34:02 UTC (rev 3966)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2007-10-02
15:36:48 UTC (rev 3967)
@@ -105,6 +105,23 @@
id="org.eclipse.wst.sse.ui.preferences.jsp.occurrences">
</page>
</extension>
+
+ <extension
+ id="XHTML_Document_Setup"
+ name="XHTML_Document_Setup"
+ point="org.eclipse.core.filebuffers.documentSetup">
+ <participant
+ extensions="xhtml"
+ class="org.jboss.tools.jst.jsp.jspeditor.XHTMLTaglibController" />
+ </extension>
+
+ <extension point="org.eclipse.wst.sse.core.modelHandler">
+ <modelHandler
+ class="org.jboss.tools.jst.jsp.modelhandler.ModelHandlerForXHTML"
+ associatedContentTypeId="org.eclipse.wst.html.core.htmlsource"
+ id="org.jboss.tools.jst.jsp.modelhandler.xhtml">
+ </modelHandler>
+ </extension>
<extension point="org.eclipse.ui.editors">
<editor
@@ -117,7 +134,8 @@
matchingStrategy =
"org.jboss.tools.common.core.resources.MatchingStrategyImpl"
extensions="jsp, jsf, jspf, jspx, tag, tagf, inc">
<contentTypeBinding
contentTypeId="org.eclipse.jst.jsp.core.jspsource"/>
- </editor>
+ </editor>
+
<editor
class="org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor"
contributorClass="org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageContributor"
@@ -147,7 +165,8 @@
id="StructureSelectNext"
label="Next Element">
</action>
- </editorContribution>
+ </editorContribution>
+
<editorContribution
id="ACleanupDocument"
targetID="org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor">
@@ -300,6 +319,6 @@
class="org.jboss.tools.jst.jsp.outline.JSPCellEditorProviderImpl"/>
<xclass id="org.jboss.tools.jst.jsp.outline.VpeProperties"
class="org.jboss.tools.jst.jsp.outline.VpeProperties"/>
- </extension>
+ </extension>
-</plugin>
\ No newline at end of file
+</plugin>
Modified:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/RedHatHtmlContentAssistProcessor.java
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/RedHatHtmlContentAssistProcessor.java 2007-10-02
15:34:02 UTC (rev 3966)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/RedHatHtmlContentAssistProcessor.java 2007-10-02
15:36:48 UTC (rev 3967)
@@ -20,11 +20,11 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
-import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorInput;
+import org.eclipse.wst.html.core.internal.contentmodel.HTMLElementDeclaration;
+import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties;
import org.eclipse.wst.html.ui.internal.HTMLUIPlugin;
import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor;
import org.eclipse.wst.html.ui.internal.preferences.HTMLUIPreferenceNames;
@@ -32,13 +32,19 @@
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction;
import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper;
import org.eclipse.wst.xml.core.internal.document.AttrImpl;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
+import org.eclipse.wst.xml.ui.internal.contentassist.NonValidatingModelQueryAction;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
@@ -56,6 +62,8 @@
import org.jboss.tools.common.reporting.ProblemReportingHelper;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.editor.TLDRegisterHelper;
+import org.jboss.tools.jst.jsp.jspeditor.TLDEditorDocumentManager;
+import org.jboss.tools.jst.jsp.jspeditor.XHTMLTaglibController;
import org.jboss.tools.jst.jsp.outline.ValueHelper;
import org.jboss.tools.jst.jsp.support.kb.FaceletsJsfCResource;
import org.jboss.tools.jst.jsp.support.kb.WTPKbdBeanMethodResource;
@@ -69,6 +77,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* @author Igels
@@ -398,6 +407,11 @@
} catch(Exception e) {
JspEditorPlugin.getPluginLog().logError(e);
}
+
+ if (kbProposals.size() == 0) {
+
+ }
+
for (Iterator iter = kbProposals.iterator(); iter.hasNext();) {
KbProposal kbProposal = (KbProposal) iter.next();
if(ignoreProposal(kbProposal)) {
@@ -481,7 +495,7 @@
public void updateActiveContentAssistProcessor(IDocument document) {
if(tldManager==null) {
- TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(document);
+ TLDEditorDocumentManager manager =
XHTMLTaglibController.getTLDCMDocumentManager(document);
if (manager != null) {
List list = manager.getTaglibTrackers();
for(int i=0; i<list.size(); i++) {
@@ -539,4 +553,93 @@
jspActiveCAP = new JSPActiveContentAssistProcessor();
jspActiveCAP.init();
}
+
+ protected List getAvailableChildrenAtIndex(Element parent, int index, int
validityChecking) {
+ List list = new ArrayList();
+ List additionalElements = getAdditionalChildren(new ArrayList(), parent, index);
+ for (int i = 0; i < additionalElements.size(); i++) {
+ ModelQueryAction insertAction = new
NonValidatingModelQueryAction((CMElementDeclaration) additionalElements.get(i),
ModelQueryAction.INSERT, 0, parent.getChildNodes().getLength(), null);
+ list.add(insertAction);
+ }
+
+ // add allowed children of implicit tags that don't already exist
+ NodeList children = parent.getChildNodes();
+ List childNames = new ArrayList();
+ if (children != null) {
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE)
+ childNames.add(child.getNodeName().toLowerCase());
+ }
+ }
+ List allActions = new ArrayList();
+ Iterator iterator = list.iterator();
+ ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument());
+ while (iterator.hasNext()) {
+ ModelQueryAction action = (ModelQueryAction) iterator.next();
+ allActions.add(action);
+ if (action.getCMNode() instanceof HTMLElementDeclaration) {
+ HTMLElementDeclaration ed = (HTMLElementDeclaration) action.getCMNode();
+ String ommission = (String) ed.getProperty(HTMLCMProperties.OMIT_TYPE);
+ if (!childNames.contains(ed.getNodeName().toLowerCase()) && ((ommission !=
null) && (ommission.equals(HTMLCMProperties.Values.OMIT_BOTH)))) {
+ List implicitValidActions = new ArrayList();
+ modelQuery.getInsertActions(parent, ed, 0, ModelQuery.INCLUDE_CHILD_NODES,
ModelQuery.VALIDITY_NONE, implicitValidActions);
+ if (implicitValidActions != null) {
+ Iterator implicitValidActionsIterator = implicitValidActions.iterator();
+ while (implicitValidActionsIterator.hasNext()) {
+ ModelQueryAction insertAction = new
NonValidatingModelQueryAction(((ModelQueryAction)
implicitValidActionsIterator.next()).getCMNode(), ModelQueryAction.INSERT, 0,
parent.getChildNodes().getLength(), null);
+ allActions.add(insertAction);
+ }
+ }
+ }
+ }
+ }
+ return allActions;
+ }
+
+ private List getAdditionalChildren(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();
+ }
+ TLDEditorDocumentManager mgr =
XHTMLTaglibController.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);
+ }
+ return elementDecls;
+ }
+
}
Modified:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/RedHatJSPContentAssistProcessor.java
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/RedHatJSPContentAssistProcessor.java 2007-10-02
15:34:02 UTC (rev 3966)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/RedHatJSPContentAssistProcessor.java 2007-10-02
15:36:48 UTC (rev 3967)
@@ -23,12 +23,17 @@
import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
+import org.eclipse.jst.jsp.core.internal.provisional.JSP12Namespace;
+import org.eclipse.jst.jsp.core.internal.provisional.JSP20Namespace;
import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin;
import org.eclipse.jst.jsp.ui.internal.contentassist.JSPContentAssistProcessor;
import org.eclipse.jst.jsp.ui.internal.preferences.JSPUIPreferenceNames;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor;
+import org.eclipse.wst.html.core.internal.contentmodel.HTMLElementDeclaration;
+import org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument;
+import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties;
import
org.eclipse.wst.javascript.ui.internal.common.contentassist.JavaScriptContentAssistProcessor;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
@@ -37,15 +42,21 @@
import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
+import org.eclipse.wst.xml.ui.internal.contentassist.NonValidatingModelQueryAction;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentModelGenerator;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil;
@@ -61,6 +72,8 @@
import org.jboss.tools.common.kb.wtp.TLDVersionHelper;
import org.jboss.tools.common.kb.wtp.WtpKbConnector;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.jspeditor.TLDEditorDocumentManager;
+import org.jboss.tools.jst.jsp.jspeditor.XHTMLTaglibController;
import org.jboss.tools.jst.web.project.WebProject;
import org.jboss.tools.jst.web.tld.TaglibData;
import org.jboss.tools.jst.web.tld.VpeTaglibListener;
@@ -69,6 +82,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* @author Igels
@@ -196,7 +210,7 @@
public void updateActiveContentAssistProcessor(IDocument document) {
unregisterTagsFromActiveCAP();
if(tldManager == null) {
- TLDCMDocumentManager manager = TaglibController.getTLDCMDocumentManager(document);
+ TLDEditorDocumentManager manager =
XHTMLTaglibController.getTLDCMDocumentManager(document);
if (manager != null) {
List list = manager.getTaglibTrackers();
for(int i=0; i<list.size(); i++) {
@@ -622,4 +636,93 @@
private boolean isCommentNode(IDOMNode node) {
return (node != null && node instanceof IDOMElement && ((IDOMElement)
node).isCommentTag());
}
-}
\ No newline at end of file
+
+ protected List getAvailableChildrenAtIndex(Element parent, int index, int
validityChecking) {
+ List list = new ArrayList();
+ List additionalElements = getAdditionalChildren(new ArrayList(), parent, index);
+ for (int i = 0; i < additionalElements.size(); i++) {
+ ModelQueryAction insertAction = new
NonValidatingModelQueryAction((CMElementDeclaration) additionalElements.get(i),
ModelQueryAction.INSERT, 0, parent.getChildNodes().getLength(), null);
+ list.add(insertAction);
+ }
+
+ // add allowed children of implicit tags that don't already exist
+ NodeList children = parent.getChildNodes();
+ List childNames = new ArrayList();
+ if (children != null) {
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE)
+ childNames.add(child.getNodeName().toLowerCase());
+ }
+ }
+ List allActions = new ArrayList();
+ Iterator iterator = list.iterator();
+ ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument());
+ while (iterator.hasNext()) {
+ ModelQueryAction action = (ModelQueryAction) iterator.next();
+ allActions.add(action);
+ if (action.getCMNode() instanceof HTMLElementDeclaration) {
+ HTMLElementDeclaration ed = (HTMLElementDeclaration) action.getCMNode();
+ String ommission = (String) ed.getProperty(HTMLCMProperties.OMIT_TYPE);
+ if (!childNames.contains(ed.getNodeName().toLowerCase()) && ((ommission !=
null) && (ommission.equals(HTMLCMProperties.Values.OMIT_BOTH)))) {
+ List implicitValidActions = new ArrayList();
+ modelQuery.getInsertActions(parent, ed, 0, ModelQuery.INCLUDE_CHILD_NODES,
ModelQuery.VALIDITY_NONE, implicitValidActions);
+ if (implicitValidActions != null) {
+ Iterator implicitValidActionsIterator = implicitValidActions.iterator();
+ while (implicitValidActionsIterator.hasNext()) {
+ ModelQueryAction insertAction = new
NonValidatingModelQueryAction(((ModelQueryAction)
implicitValidActionsIterator.next()).getCMNode(), ModelQueryAction.INSERT, 0,
parent.getChildNodes().getLength(), null);
+ allActions.add(insertAction);
+ }
+ }
+ }
+ }
+ }
+ return allActions;
+ }
+
+ private List getAdditionalChildren(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();
+ }
+ TLDEditorDocumentManager mgr =
XHTMLTaglibController.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);
+ }
+ return elementDecls;
+ }
+
+}
Added:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/TLDEditorDocumentManager.java
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/TLDEditorDocumentManager.java
(rev 0)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/TLDEditorDocumentManager.java 2007-10-02
15:36:48 UTC (rev 3967)
@@ -0,0 +1,840 @@
+/*******************************************************************************
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.jspeditor;
+
+import java.io.File;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Stack;
+
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentFactoryTLD;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.JSP11TLDNames;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.JSP12TLDNames;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.JSP20TLDNames;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDDocument;
+import
org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration;
+import org.eclipse.jst.jsp.core.internal.regions.DOMJSPRegionContexts;
+import org.eclipse.jst.jsp.core.taglib.IJarRecord;
+import org.eclipse.jst.jsp.core.taglib.ITLDRecord;
+import org.eclipse.jst.jsp.core.taglib.ITagDirRecord;
+import org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta;
+import org.eclipse.jst.jsp.core.taglib.ITaglibIndexListener;
+import org.eclipse.jst.jsp.core.taglib.ITaglibRecord;
+import org.eclipse.jst.jsp.core.taglib.IURLRecord;
+import org.eclipse.jst.jsp.core.taglib.TaglibIndex;
+import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin;
+import org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker;
+import org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument;
+import org.eclipse.wst.sse.core.utils.StringUtils;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
+import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser;
+import org.eclipse.wst.xml.core.internal.parser.regions.AttributeNameRegion;
+import org.eclipse.wst.xml.core.internal.parser.regions.AttributeValueRegion;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.eclipse.wst.xml.core.internal.text.XMLStructuredDocumentRegion;
+import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.project.IModelNature;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.web.project.WebProject;
+import org.jboss.tools.jst.web.tld.TaglibMapping;
+
+/**
+ * @author Sergey Vasilyev (svasilyev(a)exadel.com))
+ *
+ */
+public class TLDEditorDocumentManager implements ITaglibIndexListener, IDocumentListener
{
+
+ class DirectiveStructuredDocumentRegionHandler implements
StructuredDocumentRegionHandler {
+
+ public void nodeParsed(
+ IStructuredDocumentRegion coreStructuredDocumentRegion) {
+ if (coreStructuredDocumentRegion.getNumberOfRegions() > 4
+ && (coreStructuredDocumentRegion.getType() == DOMRegionContext.XML_TAG_NAME
|| coreStructuredDocumentRegion
+ .getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME)) {
+ parseXmlns(coreStructuredDocumentRegion);
+ }
+ }
+
+ public void resetNodes() {
+ }
+ }
+
+ /**
+ * An entry in the shared cache map
+ */
+ static class TLDCacheEntry {
+ CMDocument document;
+ long modificationStamp;
+ int referenceCount;
+ }
+
+ private static class TLDCMDocumentDescriptor {
+ Object cacheKey;
+ CMDocument document;
+
+ TLDCMDocumentDescriptor() {
+ super();
+ }
+ }
+
+ private class TLDCMDocumentReference {
+ String prefix;
+ String uri;
+ }
+
+ private XMLSourceParser sourceParser;
+ private DirectiveStructuredDocumentRegionHandler structuredDocumentRegionHandler;
+ private IStructuredDocument document;
+
+ private Stack<?> fIncludes = null;
+
+ /** banned prefixes */
+ protected static List<String> bannedPrefixes = null;
+ static {
+ bannedPrefixes = new ArrayList<String>();
+ }
+
+ private static Hashtable<Object, Object> fCache = null;
+
+ private CMDocumentFactoryTLD fCMDocumentBuilder = null;
+
+ /** list of listTaglibTrackers */
+ private List<TaglibTracker> listTaglibTrackers;
+
+ /**
+ * The locally-know list of CMDocuments
+ */
+ private Hashtable<?, ?> fDocuments = null;
+
+ public TLDEditorDocumentManager() {
+
+ }
+
+ public XMLSourceParser getSourceParser() {
+ return sourceParser;
+ }
+
+ public void setSourceParser(XMLSourceParser sourceParser) {
+ if (sourceParser != null) {
+ sourceParser
+ .removeStructuredDocumentRegionHandler(getStructuredDocumentRegionHandler());
+ }
+
+ this.sourceParser = sourceParser;
+
+ if (this.sourceParser != null) {
+ this.sourceParser
+ .addStructuredDocumentRegionHandler(getStructuredDocumentRegionHandler());
+ }
+
+ }
+
+ public DirectiveStructuredDocumentRegionHandler getStructuredDocumentRegionHandler() {
+ if (structuredDocumentRegionHandler == null) {
+ structuredDocumentRegionHandler = new DirectiveStructuredDocumentRegionHandler();
+ }
+
+ return structuredDocumentRegionHandler;
+ }
+
+ public IStructuredDocument getDocument() {
+ return document;
+ }
+
+ public void setDocument(IStructuredDocument document) {
+ this.document = document;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.jst.jsp.core.taglib.ITaglibIndexListener#indexChanged(org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta)
+ */
+ public void indexChanged(ITaglibIndexDelta delta) {
+ }
+
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ }
+
+ public void documentChanged(DocumentEvent event) {
+ Object document = event.fDocument;
+ if (document instanceof BasicStructuredDocument) {
+ BasicStructuredDocument bsDocument = (BasicStructuredDocument) document;
+ IStructuredDocumentRegionList o = bsDocument.getRegionList();
+ int countElements = o.getLength();
+
+ for (int i = 0; i < countElements; i++) {
+ IStructuredDocumentRegion element = o.item(i);
+ if (element.containsOffset(event.fOffset)) {
+ parseXmlns2(element);
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("restriction")
+ public void parseXmlns(IStructuredDocumentRegion structuredDocumentRegion) {
+
+ ITextRegion name = structuredDocumentRegion.getRegions().get(1);
+ int startOffset = structuredDocumentRegion.getStartOffset(name);
+ String sName = getSourceParser().getText(startOffset,
+ name.getTextLength());
+
+ ITextRegionList regionList = structuredDocumentRegion.getRegions();
+
+ String attrName = null;
+ String attrValue = null;
+ String sTemp;
+ for (Iterator<?> iterator = regionList.iterator(); iterator.hasNext();) {
+ ITextRegion region = (ITextRegion) iterator.next();
+
+ startOffset = structuredDocumentRegion.getStartOffset(region);
+ sTemp = getSourceParser().getText(startOffset,
+ region.getTextLength());
+
+ if (region instanceof AttributeNameRegion) {
+ attrName = sTemp;
+ } else if (region instanceof AttributeValueRegion) {
+ attrValue = sTemp;
+ processXmlns(attrName, attrValue, structuredDocumentRegion);
+ }
+ }
+ }
+
+ @SuppressWarnings("restriction")
+ public void parseXmlns2(IStructuredDocumentRegion structuredDocumentRegion) {
+ ITextRegionList regionList = structuredDocumentRegion.getRegions();
+
+ String attrName = null;
+ String attrValue = null;
+ int startOffset = 0;
+ String sTemp;
+
+ for (Iterator<?> iterator = regionList.iterator(); iterator.hasNext();) {
+ ITextRegion region = (ITextRegion) iterator.next();
+
+ startOffset = structuredDocumentRegion.getStartOffset(region);
+ sTemp = structuredDocumentRegion.getText(region);
+
+ if (region instanceof AttributeNameRegion) {
+ attrName = sTemp;
+ } else if (region instanceof AttributeValueRegion) {
+ attrValue = sTemp;
+ processXmlns(attrName, attrValue, structuredDocumentRegion);
+ }
+ }
+ }
+
+ /**
+ *
+ * @param prefix
+ * @param uri
+ * @param structuredDocumentRegion
+ */
+ private void processXmlns(String prefix, String uri, IStructuredDocumentRegion
structuredDocumentRegion) {
+ if (prefix.startsWith("xmlns")) {
+ String tmpPrefix = "";
+
+ if (prefix.length() > 6) {
+ tmpPrefix = prefix.substring(6);
+ }
+ String tmpUri = StringUtils.strip(uri);
+ JspEditorPlugin.getPluginLog().logInfo("prefix " + tmpPrefix + " uri
" + tmpUri);
+ enableTaglibFromURI(tmpPrefix, tmpUri, structuredDocumentRegion);
+ }
+ }
+
+ /**
+ *
+ * @param prefix
+ * @param uri
+ * @param anchorStructuredDocumentRegion
+ */
+ private void enableTags(String prefix, String uri,
+ IStructuredDocumentRegion anchorStructuredDocumentRegion) {
+ if (prefix == null || uri == null || bannedPrefixes.contains(prefix))
+ return;
+ // Try to load the CMDocument for this URI
+ CMDocument tld = getCMDocument(uri);
+ if (tld == null || !(tld instanceof TLDDocument)) {
+ if (JspEditorPlugin.DEBIG_TLDCMDOCUMENT_MANAGER) {
+ JspEditorPlugin.getPluginLog().logInfo("TLDEditorDocumentManager failed to
create a CMDocument for " + uri);
+ }
+ return;
+ }
+ registerTaglib(prefix, uri, anchorStructuredDocumentRegion, tld);
+ }
+
+ /**
+ * Derives an unique cache key for the give URI. The URI is "resolved" and a
+ * unique value generated from the result. This ensures that two different
+ * relative references from different files do not have overlapping TLD
+ * records in the shared cache if they don't resolve to the same TLD.
+ *
+ * @param uri
+ * @return
+ */
+ protected Object getCacheKey(String uri) {
+ ITaglibRecord record = TaglibIndex.resolve(getCurrentParserPath()
+ .toString(), uri, false);
+ if (record != null) {
+ return getUniqueIdentifier(record);
+ }
+ String location = URIResolverPlugin.createResolver().resolve(
getCurrentBaseLocation().toString(), null, uri);
+ return location;
+ }
+
+ /**
+ * get the CMDocument at the uri (cached)
+ * @param uri
+ * @return the CMDocument at the uri (cached)
+ */
+ protected CMDocument getCMDocument(String uri) {
+ if (uri == null || uri.length() == 0)
+ return null;
+ String reference = uri;
+ Object cacheKey = getCacheKey(reference);
+ long lastModified = getModificationStamp(reference);
+ CMDocument doc = (CMDocument) getDocuments().get(cacheKey);
+ if (doc == null) {
+ /*
+ * If hasn't been moved into the local table, do so and increment
+ * the count. A local URI reference can be different depending on
+ * the file from which it was referenced. Use a computed key to keep
+ * them straight.
+ */
+ Object o = getSharedDocumentCache().get(cacheKey);
+ if (o != null) {
+ if (o instanceof TLDCacheEntry) {
+ TLDCacheEntry entry = (TLDCacheEntry) o;
+ if (JspEditorPlugin.DEBIG_TLDCMDOCUMENT_CACHE) {
+ JspEditorPlugin.getPluginLog().logInfo("TLDCMDocument cache hit on " +
cacheKey);
+ }
+ if (entry != null
+ && entry.modificationStamp != IResource.NULL_STAMP
+ && entry.modificationStamp >= lastModified) {
+ doc = entry.document;
+ entry.referenceCount++;
+ } else {
+ getSharedDocumentCache().remove(cacheKey);
+ }
+ } else if (o instanceof Reference) {
+ TLDCacheEntry entry = (TLDCacheEntry) ((Reference) o).get();
+ if (entry != null) {
+ if (entry.modificationStamp != IResource.NULL_STAMP
+ && entry.modificationStamp >= lastModified) {
+ doc = entry.document;
+ entry.referenceCount = 1;
+ getSharedDocumentCache().put(cacheKey, entry);
+ }
+ } else {
+ getSharedDocumentCache().remove(cacheKey);
+ }
+ }
+ }
+ /* No document was found cached, create a new one and share it */
+ if (doc == null) {
+ if (JspEditorPlugin.DEBIG_TLDCMDOCUMENT_CACHE) {
+ JspEditorPlugin.getPluginLog().logInfo("TLDCMDocument cache miss on " +
cacheKey);
+ }
+ TLDCMDocumentDescriptor descriptor = loadTaglib(reference);
+ if (descriptor != null) {
+ TLDCacheEntry entry = new TLDCacheEntry();
+ doc = entry.document = descriptor.document;
+ entry.referenceCount = 1;
+ entry.modificationStamp = getModificationStamp(reference);
+ getSharedDocumentCache().put(cacheKey, entry);
+ }
+ }
+ if (doc != null) {
+ getDocuments().put(cacheKey, doc);
+ }
+ }
+ return doc;
+ }
+
+ /**
+ * Return the filesystem location in the current parser. This method is
+ * called while recursing through included fragments, so it much check the
+ * include stack. The filesystem location is needed for common URI
+ * resolution in case the Taglib Index doesn't know the URI being loaded.
+ *
+ * @return
+ */
+ private IPath getCurrentBaseLocation() {
+ IPath baseLocation = null;
+ IPath path = getCurrentParserPath();
+ baseLocation = ResourcesPlugin.getWorkspace().getRoot().getFile(path)
+ .getLocation();
+ if (baseLocation == null) {
+ baseLocation = path;
+ }
+ return baseLocation;
+ }
+
+ /**
+ * Return the path used in the current parser. This method is called while
+ * recursing through included fragments, so it much check the include stack.
+ *
+ * @return
+ */
+ private IPath getCurrentParserPath() {
+ IPath path = null;
+ if (!getIncludes().isEmpty()) {
+ path = (IPath) getIncludes().peek();
+ } else {
+ path = XHTMLTaglibController.getFileBuffer(this).getLocation();
+ }
+
+ return path;
+ }
+
+ /**
+ * Gets the includes.
+ *
+ * @return Returns a Stack
+ */
+ protected Stack getIncludes() {
+ if (fIncludes == null)
+ fIncludes = new Stack();
+ return fIncludes;
+ }
+
+ public static Object getUniqueIdentifier(ITaglibRecord reference) {
+ if (reference == null)
+ return null;
+ Object identifier = null;
+ switch (reference.getRecordType()) {
+ case (ITaglibRecord.TLD): {
+ ITLDRecord record = (ITLDRecord) reference;
+ identifier = record.getPath();
+ }
+ break;
+ case (ITaglibRecord.JAR): {
+ IJarRecord record = (IJarRecord) reference;
+ identifier = record.getLocation();
+ }
+ break;
+ case (ITaglibRecord.TAGDIR): {
+ ITagDirRecord record = (ITagDirRecord) reference;
+ identifier = record.getPath();
+ }
+ break;
+ case (ITaglibRecord.URL): {
+ IURLRecord record = (IURLRecord) reference;
+ identifier = record.getURL();
+ }
+ break;
+ default:
+ identifier = reference;
+ break;
+ }
+ return identifier;
+ }
+
+ private long getModificationStamp(String reference) {
+ ITaglibRecord record = TaglibIndex.resolve(getCurrentParserPath()
+ .toString(), reference, false);
+ long modificationStamp = IResource.NULL_STAMP;
+ if (record != null) {
+ switch (record.getRecordType()) {
+ case (ITaglibRecord.TLD): {
+ IFile tldfile = ResourcesPlugin.getWorkspace().getRoot()
+ .getFile(((ITLDRecord) record).getPath());
+ if (tldfile.isAccessible()) {
+ modificationStamp = tldfile.getModificationStamp();
+ }
+ }
+ break;
+ case (ITaglibRecord.JAR): {
+ File jarfile = new File(((IJarRecord) record).getLocation()
+ .toOSString());
+ if (jarfile.exists()) {
+ try {
+ modificationStamp = jarfile.lastModified();
+ } catch (SecurityException e) {
+ modificationStamp = IResource.NULL_STAMP;
+ }
+ }
+ }
+ break;
+ case (ITaglibRecord.TAGDIR): {
+ IFolder tagFolder = ResourcesPlugin.getWorkspace().getRoot()
+ .getFolder(((ITagDirRecord) record).getPath());
+ if (tagFolder.isAccessible()) {
+ IResource[] members;
+ try {
+ members = tagFolder.members();
+ for (int i = 0; i < members.length; i++) {
+ modificationStamp = Math.max(modificationStamp,
+ members[i].getModificationStamp());
+ }
+ } catch (CoreException e) {
+ modificationStamp = IResource.NULL_STAMP;
+ }
+ }
+ }
+ break;
+ case (ITaglibRecord.URL): {
+ modificationStamp = IResource.NULL_STAMP;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ return modificationStamp;
+ }
+
+ /**
+ * Gets the documents.
+ *
+ * @return Returns a java.util.Hashtable
+ */
+ public Hashtable getDocuments() {
+ if (fDocuments == null)
+ fDocuments = new Hashtable();
+ return fDocuments;
+ }
+
+ /**
+ * Gets all of the known documents.
+ *
+ * @return Returns a Hashtable of either TLDCacheEntrys or WeakReferences to
TLDCMDocuments
+ */
+ public static Hashtable<Object, Object> getSharedDocumentCache() {
+ if (fCache == null) {
+ fCache = new Hashtable<Object, Object>();
+ }
+ return fCache;
+ }
+
+ protected TLDCMDocumentDescriptor loadTaglib(String uri) {
+ TLDCMDocumentDescriptor entry = null;
+ IPath currentPath = getCurrentParserPath();
+
+ IFile ifile = ResourcesPlugin.getWorkspace().getRoot().getFile(currentPath);
+ IProject iProject = ifile.getProject();
+ IModelNature nature = EclipseResourceUtil.getModelNature(iProject);
+ XModel model = nature.getModel();
+
+ XModelObject xmo =
WebProject.getInstance(model).getTaglibMapping().getTaglibObject(uri);
+
+ TaglibMapping taglibMapping = WebProject.getInstance(model).getTaglibMapping();
+
+
+ if (currentPath != null) {
+ CMDocument document = null;
+ ITaglibRecord record = TaglibIndex.resolve(currentPath.toString(),
+ uri, false);
+ if (record != null) {
+ document = getCMDocumentBuilder().createCMDocument(record);
+ if (document != null) {
+ entry = new TLDCMDocumentDescriptor();
+ entry.document = document;
+ entry.cacheKey = getUniqueIdentifier(record);
+ }
+ } else {
+ /* Not a very-often used code path (we hope) */
+ IPath currentBaseLocation = getCurrentBaseLocation();
+ if (currentBaseLocation != null) {
+ String location = URIResolverPlugin.createResolver()
+ .resolve(currentBaseLocation.toString(), null, uri);
+ if (location != null) {
+ if (JspEditorPlugin.DEBIG_TLDCMDOCUMENT_MANAGER) {
+ JspEditorPlugin.getPluginLog().logInfo("Loading tags from " + uri +
" at " + location);
+ }
+ document = getCMDocumentBuilder().createCMDocument( location);
+ entry = new TLDCMDocumentDescriptor();
+ entry.document = document;
+ entry.cacheKey = location;
+ }
+ }
+ }
+ }
+ return entry;
+ }
+
+ /**
+ * Gets the cMDocumentBuilder.
+ *
+ * @return Returns a CMDocumentFactoryTLD, since it has more builder methods
+ */
+ protected CMDocumentFactoryTLD getCMDocumentBuilder() {
+ if (fCMDocumentBuilder == null)
+ fCMDocumentBuilder = new CMDocumentFactoryTLD();
+ return fCMDocumentBuilder;
+ }
+
+ /**
+ * Adds a block tagname (fully namespace qualified) into the list of block
+ * tag names for the parser. The marker IStructuredDocumentRegion along with
+ * position cues during reparses allow the JSPSourceParser to enable/ignore
+ * the tags as blocks.
+ */
+ protected void addBlockTag(String tagnameNS,
+ IStructuredDocumentRegion marker) {
+ if (getSourceParser() == null)
+ return;
+ if (getSourceParser().getBlockMarker(tagnameNS) == null) {
+ getSourceParser().addBlockMarker(
+ new BlockMarker(tagnameNS, marker,
+ DOMRegionContext.BLOCK_TEXT, true, false));
+ if (JspEditorPlugin.DEBIG_TLDCMDOCUMENT_MANAGER) {
+ JspEditorPlugin.getPluginLog().logInfo("TLDEditorDocumentManager added block
marker: " + tagnameNS + "@" + marker.getStartOffset());
//$NON-NLS-2$//$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ *
+ * @param prefix
+ * @param uri
+ * @param anchorStructuredDocumentRegion
+ * @param tldCMDocument
+ */
+ protected void addTaglibTracker(String prefix, String uri, IStructuredDocumentRegion
anchorStructuredDocumentRegion, CMDocument tldCMDocument) {
+ getTaglibTrackers().add( new TaglibTracker(uri, prefix, tldCMDocument,
anchorStructuredDocumentRegion));
+ }
+
+ /**
+ * Enables a TLD owning the given prefix loaded from the given URI at the
+ * anchorStructuredDocumentRegion. The list of additionalCMDocuments will
+ * claim to not know any of its tags at positions earlier than that
+ * IStructuredDocumentRegion's position.
+ *
+ * For taglib directives, the taglib is the anchor while taglibs registered
+ * through include directives use the parent document's include directive as
+ * their anchor.
+ *
+ * @param prefix
+ * @param uri
+ * @param anchorStructuredDocumentRegion
+ */
+ protected void enableTaglibFromURI(String prefix, String uri, IStructuredDocumentRegion
anchorStructuredDocumentRegion) {
+ enableTags(prefix, uri, anchorStructuredDocumentRegion);
+ if (JspEditorPlugin.DEBIG_TLDCMDOCUMENT_MANAGER) {
+ JspEditorPlugin.getPluginLog().logInfo("TLDEditorDocumentManager registered a
tracker for " + uri + " with prefix " + prefix);
//$NON-NLS-2$//$NON-NLS-1$
+ }
+ }
+
+ /**
+ *
+ * @return a list of TaglibTrackers
+ */
+ public List<TaglibTracker> getTaglibTrackers() {
+ if (listTaglibTrackers == null) {
+ listTaglibTrackers = new ArrayList<TaglibTracker>();
+ }
+ return listTaglibTrackers;
+ }
+
+ protected void processTaglib( IStructuredDocumentRegion taglibStructuredDocumentRegion)
{
+ processTaglib(taglibStructuredDocumentRegion, taglibStructuredDocumentRegion,
getSourceParser());
+ }
+
+ protected void processTaglib( IStructuredDocumentRegion taglibStructuredDocumentRegion,
IStructuredDocumentRegion anchorStructuredDocumentRegion, XMLSourceParser textSource) {
+ ITextRegionList regions = taglibStructuredDocumentRegion.getRegions();
+ String uri = null;
+ String prefix = null;
+ String tagdir = null;
+ String attrName = null;
+ try {
+ for (int i = 0; i < regions.size(); i++) {
+ ITextRegion region = regions.get(i);
+ // remember attribute name
+ int startOffset = taglibStructuredDocumentRegion.getStartOffset(region);
+ int textLength = region.getTextLength();
+ if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
+ if (textSource.regionMatches(startOffset, textLength,JSP11TLDNames.PREFIX)) {
+ attrName = JSP11TLDNames.PREFIX;
+ } else if (textSource.regionMatches(startOffset,
+ textLength, JSP12TLDNames.URI)) {
+ attrName = JSP11TLDNames.URI;
+ } else if (textSource.regionMatches(startOffset,
+ textLength, JSP20TLDNames.TAGDIR)) {
+ attrName = JSP20TLDNames.TAGDIR;
+ } else {
+ attrName = null;
+ }
+ }
+ // process value
+ else if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
+ if (JSP11TLDNames.PREFIX.equals(attrName))
+ prefix = StringUtils.strip(textSource.getText(
+ startOffset, textLength));
+ else if (JSP11TLDNames.URI.equals(attrName))
+ uri = StringUtils.strip(textSource.getText(startOffset,
+ textLength));
+ else if (JSP20TLDNames.TAGDIR.equals(attrName))
+ tagdir = StringUtils.strip(textSource.getText(
+ startOffset, textLength));
+ }
+ }
+ } catch (StringIndexOutOfBoundsException sioobExc) {
+ // nothing to be done
+ uri = null;
+ prefix = null;
+ }
+ if (uri != null && prefix != null && uri.length() > 0
+ && prefix.length() > 0) {
+ if (anchorStructuredDocumentRegion == null)
+ enableTaglibFromURI(prefix, StringUtils.strip(uri),
+ taglibStructuredDocumentRegion);
+ else
+ enableTaglibFromURI(prefix, uri, anchorStructuredDocumentRegion);
+ } else if (tagdir != null && prefix != null && tagdir.length() > 0
+ && prefix.length() > 0) {
+ if (anchorStructuredDocumentRegion == null)
+ enableTagsInDir(StringUtils.strip(prefix), StringUtils
+ .strip(tagdir), taglibStructuredDocumentRegion);
+ else
+ enableTagsInDir(StringUtils.strip(prefix), StringUtils
+ .strip(tagdir), anchorStructuredDocumentRegion);
+ }
+ }
+
+ /**
+ * Enables a TLD owning the given prefix loaded from the given URI at the
+ * anchorStructuredDocumentRegion. The list of additionalCMDocuments will
+ * claim to not know any of its tags at positions earlier than that
+ * IStructuredDocumentRegion's position.
+ *
+ * For taglib directives, the taglib is the anchor while taglibs registered
+ * through include directives use the parent document's include directive as
+ * their anchor.
+ *
+ * @param prefix
+ * @param uri
+ * @param taglibStructuredDocumentRegion
+ */
+ protected void enableTagsInDir(String prefix, String tagdir,
+ IStructuredDocumentRegion anchorStructuredDocumentRegion) {
+ enableTags(prefix, tagdir, anchorStructuredDocumentRegion);
+ if (JspEditorPlugin.DEBIG_TLDCMDOCUMENT_MANAGER) {
+ JspEditorPlugin.getPluginLog().logInfo("TLDEditorDocumentManager registered a
tracker for directory" + tagdir + " with prefix " + prefix);
//$NON-NLS-2$//$NON-NLS-1$
+ }
+ }
+
+ /**
+ *
+ * @param prefix
+ * @param uri
+ * @param anchorStructuredDocumentRegion
+ * @param tld
+ */
+ private void registerTaglib(String prefix, String uri,
+ IStructuredDocumentRegion anchorStructuredDocumentRegion,
+ CMDocument tld) {
+ CMNamedNodeMap elements = tld.getElements();
+ /*
+ * Go through the CMDocument for any tags that must be marked as block
+ * tags starting at the anchoring IStructuredDocumentRegion. As the
+ * document is edited and the IStructuredDocumentRegion moved around,
+ * the block tag enablement will automatically follow it.
+ */
+ for (int i = 0; i < elements.getLength(); i++) {
+ TLDElementDeclaration ed = (TLDElementDeclaration) elements.item(i);
+ if (ed.getBodycontent() == JSP12TLDNames.CONTENT_TAGDEPENDENT)
+ addBlockTag(
+ prefix + ":" + ed.getNodeName(), anchorStructuredDocumentRegion);
//$NON-NLS-1$
+ }
+ /*
+ * Since modifications to StructuredDocumentRegions adjacent to a taglib
+ * directive can cause that IStructuredDocumentRegion to be reported,
+ * filter out any duplicated URIs. When the taglib is actually modified,
+ * a full rebuild will occur and no duplicates will/should be found.
+ */
+ boolean doTrack = true;
+ List trackers = getTaglibTrackers();
+ for (int i = 0; i < trackers.size(); i++) {
+ TaglibTracker tracker = (TaglibTracker) trackers.get(i);
+ if (tracker.getPrefix().equals(prefix)
+ && tracker.getURI().equals(uri)) {
+ doTrack = false;
+ }
+ }
+ if (doTrack) {
+ addTaglibTracker(prefix, uri, anchorStructuredDocumentRegion, tld);
+ }
+ }
+
+
+ public void clearCache() {
+ if (JspEditorPlugin.DEBIG_TLDCMDOCUMENT_CACHE) {
+ System.out.println("TLDCMDocumentManager cleared its private CMDocument
cache"); //$NON-NLS-1$
+ }
+ for (Iterator iter = getDocuments().keySet().iterator(); iter.hasNext();) {
+ Object key = iter.next();
+ synchronized (getSharedDocumentCache()) {
+ Object o = getSharedDocumentCache().get(key);
+ if (o instanceof TLDCacheEntry) {
+ TLDCacheEntry entry = (TLDCacheEntry) o;
+ entry.referenceCount--;
+ if (entry.referenceCount <= 0) {
+ getSharedDocumentCache().put(key, new WeakReference(entry));
+ }
+ }
+ }
+ }
+ }
+
+ public List getCMDocumentTrackers(int offset) {
+ List validDocs = new ArrayList();
+ Iterator alldocs = getTaglibTrackers().iterator();
+ while (alldocs.hasNext()) {
+ TaglibTracker aTracker = (TaglibTracker) alldocs.next();
+ if (aTracker.getStructuredDocumentRegion().getStartOffset() < offset || offset <
0) {
+ validDocs.add(aTracker);
+ }
+ }
+ return validDocs;
+ }
+
+ public List getCMDocumentTrackers(String prefix, int offset) {
+ List validDocs = new ArrayList();
+ Iterator alldocs = getTaglibTrackers().iterator();
+ while (alldocs.hasNext()) {
+ TaglibTracker aTracker = (TaglibTracker) alldocs.next();
+ if ((aTracker.getStructuredDocumentRegion().getStartOffset() < offset || offset
< 0) && aTracker.getPrefix().equals(prefix)) {
+ validDocs.add(aTracker);
+ }
+ }
+ return validDocs;
+ }
+
+}
Added:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/XHTMLTaglibController.java
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/XHTMLTaglibController.java
(rev 0)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/XHTMLTaglibController.java 2007-10-02
15:36:48 UTC (rev 3967)
@@ -0,0 +1,253 @@
+package org.jboss.tools.jst.jsp.jspeditor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
+import org.eclipse.core.filebuffers.IFileBuffer;
+import org.eclipse.core.filebuffers.IFileBufferListener;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jst.jsp.core.internal.parser.JSPSourceParser;
+import org.eclipse.jst.jsp.core.taglib.ITaglibIndexDelta;
+import org.eclipse.jst.jsp.core.taglib.ITaglibIndexListener;
+import org.eclipse.jst.jsp.core.taglib.TaglibIndex;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+
+public class XHTMLTaglibController implements IDocumentSetupParticipant{
+ /** isShutdown */
+ static private boolean isShutdown = false;
+
+ /** */
+ private static XHTMLTaglibController INSTANCE = null;
+
+ /** */
+ private FileBufferListener fileBufferListener;
+
+ /** Map IDocument, ITaglibIndexListener */
+ private Map<IDocument, ITaglibIndexListener> documentMap;
+
+ /** List of IDocument */
+ private List<IDocument> documentList;
+
+ class DocumentInfo implements ITaglibIndexListener {
+ IStructuredDocument document;
+ ITextFileBuffer textFileBuffer;
+ TLDEditorDocumentManager tldDocumentManager;
+
+ public void indexChanged(ITaglibIndexDelta delta) {
+ int type = delta.getKind();
+ if (type == ITaglibIndexDelta.CHANGED || type == ITaglibIndexDelta.REMOVED) {
+ ITaglibIndexDelta[] deltas = delta.getAffectedChildren();
+ boolean affected = false;
+ for (int i = 0; i < deltas.length; i++) {
+ Object key =
TLDEditorDocumentManager.getUniqueIdentifier(deltas[i].getTaglibRecord());
+ if (tldDocumentManager.getDocuments().containsKey(key)) {
+ affected = true;
+ }
+ }
+ if (affected) {
+ if (JspEditorPlugin.DEBIG_TLDCMDOCUMENT_CACHE) {
+ JspEditorPlugin.getPluginLog().logInfo("TLDCMDocumentManager cleared its
private CMDocument cache");
+ }
+ tldDocumentManager.getDocuments().clear();
+ tldDocumentManager.getSourceParser().resetHandlers();
+
+ if (document instanceof BasicStructuredDocument) {
+ ((BasicStructuredDocument) document).reparse(this);
+ }
+ }
+ }
+ tldDocumentManager.indexChanged(delta);
+ }
+ }
+
+
+ class FileBufferListener implements IFileBufferListener {
+
+ public void bufferContentAboutToBeReplaced(IFileBuffer buffer) {
+ }
+
+ public void bufferContentReplaced(IFileBuffer buffer) {
+ }
+
+ public void bufferCreated(IFileBuffer buffer) {
+ if (buffer instanceof ITextFileBuffer) {
+ IDocument document = ((ITextFileBuffer) buffer).getDocument();
+
+ synchronized (INSTANCE.documentList) {
+ if (!INSTANCE.documentList.contains(document))
+ return;
+ }
+
+ DocumentInfo info = new DocumentInfo();
+ info.document = (IStructuredDocument) document;
+ info.textFileBuffer = (ITextFileBuffer) buffer;
+ info.tldDocumentManager = new TLDEditorDocumentManager();
+ info.tldDocumentManager.setSourceParser((JSPSourceParser)
info.document.getParser());
+ synchronized (INSTANCE.documentMap) {
+ INSTANCE.documentMap.put(document, info);
+ }
+ TaglibIndex.addTaglibIndexListener(info);
+ if (document instanceof BasicStructuredDocument) {
+ ((BasicStructuredDocument) document).reparse(this);
+ }
+ }
+ }
+
+ public void bufferDisposed(IFileBuffer buffer) {
+ if (buffer instanceof ITextFileBuffer) {
+ IDocument document = ((ITextFileBuffer) buffer).getDocument();
+ synchronized (INSTANCE.documentList) {
+ if (!INSTANCE.documentList.remove(document))
+ return;
+ }
+ }
+ DocumentInfo info = null;
+ synchronized (INSTANCE.documentMap) {
+ Object[] keys = INSTANCE.documentMap.keySet().toArray();
+ for (int i = 0; i < keys.length; i++) {
+ info = (DocumentInfo) INSTANCE.documentMap.get(keys[i]);
+ if (info != null && info.textFileBuffer.equals(buffer)) {
+ INSTANCE.documentMap.remove(keys[i]);
+ break;
+ }
+ }
+ }
+ if (info != null) {
+ info.tldDocumentManager.clearCache();
+ TaglibIndex.removeTaglibIndexListener(info);
+ }
+ }
+
+ public void dirtyStateChanged(IFileBuffer buffer, boolean isDirty) {
+ }
+
+ public void stateChangeFailed(IFileBuffer buffer) {
+ }
+
+ public void stateChanging(IFileBuffer buffer) {
+ }
+
+ public void stateValidationChanged(IFileBuffer buffer, boolean isStateValidated) {
+ }
+
+ public void underlyingFileDeleted(IFileBuffer buffer) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void underlyingFileMoved(IFileBuffer buffer, IPath path) {
+ }
+ }
+
+
+ public XHTMLTaglibController() {
+ super();
+ fileBufferListener = new FileBufferListener();
+ documentMap = new HashMap<IDocument, ITaglibIndexListener>(1);
+ documentList = new ArrayList<IDocument>(1);
+ }
+
+
+
+
+ public synchronized static void startup() {
+ if (INSTANCE == null) {
+ INSTANCE = new XHTMLTaglibController();
+ FileBuffers.getTextFileBufferManager().addFileBufferListener(INSTANCE.fileBufferListener);
+ }
+ setShutdown(false);
+ }
+
+ public synchronized static void shutdown() {
+ setShutdown(true);
+ FileBuffers.getTextFileBufferManager().removeFileBufferListener(INSTANCE.fileBufferListener);
+ INSTANCE = null;
+ }
+
+
+ /**
+ *
+ * @param document
+ * @return
+ */
+ public static ITextFileBuffer getFileBuffer(IDocument document) {
+ synchronized (INSTANCE.documentMap) {
+ DocumentInfo info = (DocumentInfo) INSTANCE.documentMap.get(document);
+ if (info != null)
+ return info.textFileBuffer;
+ return null;
+ }
+ }
+
+
+ /**
+ * @param manager
+ * @return
+ */
+ public static ITextFileBuffer getFileBuffer(TLDEditorDocumentManager manager) {
+ // if _instance is null, we are already shutting donw
+ if (INSTANCE == null)
+ return null;
+
+ ITextFileBuffer buffer = null;
+ synchronized (INSTANCE.documentMap) {
+ Iterator docInfos = INSTANCE.documentMap.values().iterator();
+ while (docInfos.hasNext() && buffer == null) {
+ DocumentInfo info = (DocumentInfo) docInfos.next();
+ if (info.tldDocumentManager.equals(manager))
+ buffer = info.textFileBuffer;
+ }
+ }
+ return buffer;
+ }
+ /**
+ *
+ */
+ public void setup(IDocument document) {
+ if (isShutdown())
+ return;
+ // reference the shared instance's documents directly
+ synchronized (INSTANCE.documentList) {
+ INSTANCE.documentList.add(document);
+ }
+ }
+
+ public static TLDEditorDocumentManager getTLDCMDocumentManager(IDocument document) {
+ // if _instance is null, we are already shutting donw
+ if (INSTANCE == null)
+ return null;
+ synchronized (INSTANCE.documentMap) {
+ DocumentInfo info = (DocumentInfo) INSTANCE.documentMap.get(document);
+ if (info != null)
+ return info.tldDocumentManager;
+ return null;
+
+ }
+ }
+
+
+ /**
+ *
+ * @return
+ */
+ private static synchronized boolean isShutdown() {
+ return isShutdown;
+ }
+
+ /**
+ *
+ * @param isShutdown
+ */
+ private static synchronized void setShutdown(boolean isShutdown) {
+ isShutdown = isShutdown;
+ }
+}
Added:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelhandler/ModelHandlerForXHTML.java
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelhandler/ModelHandlerForXHTML.java
(rev 0)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelhandler/ModelHandlerForXHTML.java 2007-10-02
15:36:48 UTC (rev 3967)
@@ -0,0 +1,46 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.modelhandler;
+
+import org.eclipse.jst.jsp.core.internal.modelhandler.ModelHandlerForJSP;
+import org.eclipse.wst.sse.core.internal.provisional.IModelLoader;
+
+/**
+ * @author A. Yukhovich
+ */
+public class ModelHandlerForXHTML extends ModelHandlerForJSP {
+
+ /**
+ * Needs to match what's in plugin registry. In fact, can be overwritten
+ * at run time with what's in registry! (so should never be 'final')
+ */
+ static String AssociatedContentTypeID =
"org.eclipse.wst.html.core.htmlsource"; //$NON-NLS-1$
+ /**
+ * Needs to match what's in plugin registry. In fact, can be overwritten
+ * at run time with what's in registry! (so should never be 'final')
+ */
+ private static String ModelHandlerID =
"org.jboss.tools.jst.jsp.modelhandler.xhtml";
+
+
+ public ModelHandlerForXHTML() {
+ super();
+ setId(ModelHandlerID);
+ setAssociatedContentTypeId(AssociatedContentTypeID);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler#getModelLoader()
+ */
+ public IModelLoader getModelLoader() {
+ return new XHTMLModelLoader();
+ }
+
+}
Added:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelhandler/XHTMLModelLoader.java
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelhandler/XHTMLModelLoader.java
(rev 0)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelhandler/XHTMLModelLoader.java 2007-10-02
15:36:48 UTC (rev 3967)
@@ -0,0 +1,46 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.modelhandler;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jst.jsp.core.internal.modelhandler.JSPModelLoader;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
+import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
+import org.jboss.tools.jst.jsp.modelquery.ModelQueryAdapterFactoryForXHTML;
+
+/**
+ * @author A. Yukhovich
+ *
+ */
+public class XHTMLModelLoader extends JSPModelLoader {
+
+ public XHTMLModelLoader() {
+ }
+
+ public List getAdapterFactories() {
+ List factories = super.getAdapterFactories();
+ /*
+ * Replace the default JSP model query by using our own factory
+ */
+
+ Iterator i = factories.iterator();
+ while (i.hasNext()) {
+ if (((INodeAdapterFactory) i.next()).isFactoryForType(ModelQueryAdapter.class)) {
+ i.remove();
+ }
+ }
+
+ factories.add(new ModelQueryAdapterFactoryForXHTML());
+ return factories;
+ }
+}
Added:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelquery/ModelQueryAdapterFactoryForXHTML.java
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelquery/ModelQueryAdapterFactoryForXHTML.java
(rev 0)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelquery/ModelQueryAdapterFactoryForXHTML.java 2007-10-02
15:36:48 UTC (rev 3967)
@@ -0,0 +1,98 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.modelquery;
+
+import java.io.File;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.jsp.core.internal.modelquery.JSPModelQueryAdapterImpl;
+import org.eclipse.jst.jsp.core.internal.modelquery.ModelQueryAdapterFactoryForJSP;
+import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.ModelQueryImpl;
+import
org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.SimpleAssociationProvider;
+import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
+import org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+
+/**
+ * @author A. Yukhovich
+ *
+ */
+public class ModelQueryAdapterFactoryForXHTML extends ModelQueryAdapterFactoryForJSP {
+ public ModelQueryAdapterFactoryForXHTML() {
+ }
+
+ public ModelQueryAdapterFactoryForXHTML(Object key, boolean registerAdapters) {
+ super(key, registerAdapters);
+ }
+
+ @SuppressWarnings("restriction")
+ public INodeAdapterFactory copy() {
+ return new ModelQueryAdapterFactoryForXHTML(getAdapterKey(),
isShouldRegisterAdapter());
+ }
+
+ @SuppressWarnings("restriction")
+ ModelQuery createModelQuery(IStructuredModel model, URIResolver resolver) {
+ return new ModelQueryImpl(new SimpleAssociationProvider(new
XHTMLModelQueryCMProvider()));
+ }
+
+ /**
+ * createAdapter method comment.
+ */
+ protected INodeAdapter createAdapter(INodeNotifier target) {
+
+ if (JspEditorPlugin.DEBIG_INFO) {
+ System.out.println("-----------------------ModelQueryAdapterFactoryForXHTML.createAdapter"
+ target); //$NON-NLS-1$
+ }
+
+ if (modelQueryAdapterImpl == null) {
+ if (target instanceof IDOMNode) {
+ IDOMNode xmlNode = (IDOMNode) target;
+ IStructuredModel model = stateNotifier = xmlNode.getModel();
+ String baseLocation = model.getBaseLocation();
+ // continue only if the location is known
+ if (baseLocation != null) {
+ stateNotifier.addModelStateListener(this);
+ File file = new Path(model.getBaseLocation()).toFile();
+ if (file.exists()) {
+ baseLocation = file.getAbsolutePath();
+ }
+ else {
+ IPath basePath = new Path(model.getBaseLocation());
+ IPath derivedPath = null;
+ if (basePath.segmentCount() > 1)
+ derivedPath =
ResourcesPlugin.getWorkspace().getRoot().getFile(basePath).getLocation();
+ else
+ derivedPath =
ResourcesPlugin.getWorkspace().getRoot().getLocation().append(basePath);
+ if (derivedPath != null) {
+ baseLocation = derivedPath.toString();
+ }
+ }
+ URIResolver resolver = new XMLCatalogIdResolver(baseLocation, model.getResolver());
+
+ ModelQuery modelQuery = createModelQuery(model, resolver);
+ modelQuery.setEditMode(ModelQuery.EDIT_MODE_UNCONSTRAINED);
+ modelQueryAdapterImpl = new JSPModelQueryAdapterImpl(new CMDocumentCache(),
modelQuery, resolver);
+ }
+ }
+ }
+ return modelQueryAdapterImpl;
+ }
+
+}
Added:
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelquery/XHTMLModelQueryCMProvider.java
===================================================================
---
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelquery/XHTMLModelQueryCMProvider.java
(rev 0)
+++
branches/jbosstools_ve_codeassistant/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/modelquery/XHTMLModelQueryCMProvider.java 2007-10-02
15:36:48 UTC (rev 3967)
@@ -0,0 +1,85 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.modelquery;
+
+import java.util.List;
+import org.eclipse.jst.jsp.core.internal.contentmodel.JSPCMDocumentFactory;
+import org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryCMProvider;
+import org.w3c.dom.Node;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.core.runtime.Path;
+import org.jboss.tools.jst.jsp.jspeditor.TLDEditorDocumentManager;
+import org.jboss.tools.jst.jsp.jspeditor.XHTMLTaglibController;
+/**
+ * @author A. Yukhovich
+ *
+ */
+public class XHTMLModelQueryCMProvider implements ModelQueryCMProvider {
+
+ protected XHTMLModelQueryCMProvider() {
+ super();
+ }
+ /* (non-Javadoc)
+ * @see
org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryCMProvider#getCorrespondingCMDocument(org.w3c.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;
+ TLDEditorDocumentManager tldmgr =
XHTMLTaglibController.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;
+ }
+
+}