Author: vyemialyanchyk
Date: 2007-12-19 10:27:33 -0500 (Wed, 19 Dec 2007)
New Revision: 5370
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditorPageContext.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1457 http://jira.jboss.com/jira/browse/JBIDE-788
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditorPageContext.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditorPageContext.java 2007-12-19
13:52:51 UTC (rev 5369)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/JSPTextEditorPageContext.java 2007-12-19
15:27:33 UTC (rev 5370)
@@ -13,9 +13,11 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.eclipse.jface.text.IDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
@@ -39,6 +41,9 @@
public class JSPTextEditorPageContext implements IVisualContext {
protected ArrayList<TaglibData> taglibs = new ArrayList<TaglibData>();
+ protected Map<String, String> taglibMap = new HashMap<String, String>();
+ // this is just reference to VpeTemplateManager.templateTaglibs
+ private Map<String,String> templateTaglibs = null;
protected WtpKbConnector connector = null;
//protected IDocument document = null;
protected IDOMDocument document = null;
@@ -47,12 +52,27 @@
protected ArrayList<VpeTaglibListener> taglibListeners = new
ArrayList<VpeTaglibListener>();
public JSPTextEditorPageContext() {
+ // simple tests
//addTaglib(123, "vitaliNewUri", "vitaliNewPrefix", true);
//addTaglib(123, "http://java.sun.com/jsf/facelets", "1xmlns:ui11",
true);
//addTaglib(234, "http://java.sun.com/jsf/html", "2xmlns:ui22",
true);
//addTaglib(345, "http://richfaces.org/rich", "3xmlns:ui33",
true);
}
+ public void clearAll() {
+ taglibs.clear();
+ taglibMap.clear();
+ templateTaglibs = null;
+ }
+
+ public void dispose() {
+ clearAll();
+ connector = null;
+ document = null;
+ referenceNode = null;
+ taglibListeners = null;
+ }
+
public void setReferenceNode(Node refNode) {
if (referenceNode == refNode) {
return;
@@ -162,8 +182,48 @@
for (Iterator<VpeTaglibListener> it = taglibListeners.iterator(); it.hasNext(); )
{
it.next().taglibPrefixChanged(null);
}
+ rebuildTaglibMap();
}
+ private boolean rebuildTaglibMap() {
+ taglibMap.clear();
+ if (null == templateTaglibs) {
+ return false;
+ }
+ Set<String> prefixSet = new HashSet<String>();
+ for (int i = 0; i < taglibs.size(); i++) {
+ TaglibData taglib = (TaglibData)taglibs.get(i);
+ String prefix = taglib.getPrefix();
+ if (!prefixSet.contains(prefix)) {
+ String templatePrefix = templateTaglibs.get(taglib.getUri());
+ if (templatePrefix != null) {
+ taglibMap.put(prefix, templatePrefix);
+ }
+ prefixSet.add(prefix);
+ }
+ }
+ return true;
+ }
+
+ /**
+ * This is a way to use templateTaglibs from
+ * org.jboss.tools.vpe.editor.template.VpeTemplateManager;
+ * this is just reference to VpeTemplateManager.templateTaglibs
+ * getter is prohibited here
+ **/
+ public void setTemplateTaglibs(Map<String,String> templateTaglibs) {
+ this.templateTaglibs = templateTaglibs;
+ rebuildTaglibMap();
+ }
+
+ /**
+ * Return template taglib prefix using prefix as a key.
+ * @return
+ */
+ public String getTemplateTaglibPrefix(String sourceTaglibPrefix) {
+ return taglibMap.get(sourceTaglibPrefix);
+ }
+
// adds new tag library
// removes tag library with id - if newUri or newPrefix is null
public void addTaglib(int id, String newUri, String newPrefix, boolean ns, boolean
bScopePrefix) {