Author: vrubezhny
Date: 2009-04-14 14:25:10 -0400 (Tue, 14 Apr 2009)
New Revision: 14743
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/BundleHyperlink.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPBundleHyperlinkPartitioner.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlinkPartitioner.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPLoadBundleHyperlinkPartitioner.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/LoadBundleHyperlink.java
Log:
JBIDE-4147 A hyperlink doesn't work for <a4j:loadBundle> RichFaces tag
Bundle & Load Bundle hyperlinks and their partitioners are modified to allow them to
be overriden
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/BundleHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/BundleHyperlink.java 2009-04-14
17:15:42 UTC (rev 14742)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/BundleHyperlink.java 2009-04-14
18:25:10 UTC (rev 14743)
@@ -17,6 +17,7 @@
import java.util.Properties;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.ui.IEditorPart;
import org.jboss.tools.common.model.XModel;
@@ -91,20 +92,21 @@
String bundleProp = getDocument().get(region.getOffset(), region.getLength());
- String prefix = getPrefix(region);
- if(prefix == null) return null;
+ String[] prefixes = getLoadBundleTagPrefixes(region);
+ if(prefixes == null) return null;
// Find loadBundle tag
List<Element> lbTags = new ArrayList<Element>();
- NodeList list = xmlDocument.getElementsByTagName(prefix + ":loadBundle");
- for (int i = 0; list != null && i < list.getLength(); i++) {
- Element el = (Element)list.item(i);
- int end = Utils.getValueEnd(el);
- if (end >= 0 && end < region.getOffset()) {
- lbTags.add(el);
+ for (String prefix : prefixes) {
+ NodeList list = xmlDocument.getElementsByTagName(prefix + ":loadBundle");
+ for (int i = 0; list != null && i < list.getLength(); i++) {
+ Element el = (Element)list.item(i);
+ int end = Utils.getValueEnd(el);
+ if (end >= 0 && end < region.getOffset()) {
+ lbTags.add(el);
+ }
}
}
-
for (int i = 0; i < lbTags.size(); i++) {
Element el = (Element)lbTags.get(i);
Attr var = el.getAttributeNode("var");
@@ -129,18 +131,20 @@
smw.dispose();
}
}
-
- private String getPrefix(IRegion region) {
+
+ protected String[] getLoadBundleTagPrefixes(IRegion region) {
TaglibManagerWrapper tmw = new TaglibManagerWrapper();
tmw.init(getDocument(), region.getOffset());
if(tmw.exists()) {
- return tmw.getCorePrefix();
+ return new String[] { tmw.getCorePrefix() };
} else {
VpeTaglibManager taglibManager = getTaglibManager();
if(taglibManager == null) return null;
TaglibData[] data = (TaglibData[])taglibManager.getTagLibs().toArray(new
TaglibData[0]);
+ ArrayList<String> prefixes = new ArrayList<String>();
for (int i = 0; i < data.length; i++) {
-
if("http://java.sun.com/jsf/core".equals(data[i].getUri())) return
data[i].getPrefix();
+
if("http://java.sun.com/jsf/core".equals(data[i].getUri()))
+ prefixes.add(data[i].getPrefix());
}
}
return null;
@@ -159,34 +163,34 @@
private static final String PREFIX_SEPARATOR = ":";
private String getPageLocale(IRegion region) {
+ if(getDocument() == null || region == null) return null;
+
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
smw.init(getDocument());
-
- TaglibManagerWrapper tmw = new TaglibManagerWrapper();
- tmw.init(getDocument(), region.getOffset());
- if(!tmw.exists()) return null;
- String prefix = tmw.getCorePrefix();
-
- if (prefix == null || prefix.length() == 0) return null;
-
- String nodeToFind = prefix + PREFIX_SEPARATOR + VIEW_TAGNAME;
-
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
+ String[] prefixes = getLoadBundleTagPrefixes(region);
+ if(prefixes == null) return null;
+
Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
if (!(n instanceof Attr) ) return null;
Element el = ((Attr)n).getOwnerElement();
Element jsfCoreViewTag = null;
- while (el != null) {
- if (nodeToFind.equals(el.getNodeName())) {
- jsfCoreViewTag = el;
- break;
+ for (String prefix : prefixes) {
+ String nodeToFind = prefix + PREFIX_SEPARATOR + VIEW_TAGNAME;
+
+ while (el != null) {
+ if (nodeToFind.equals(el.getNodeName())) {
+ jsfCoreViewTag = el;
+ break;
+ }
+ Node parent = el.getParentNode();
+ el = (parent instanceof Element ? (Element)parent : null);
}
- el = (Element)el.getParentNode();
}
if (jsfCoreViewTag == null || !jsfCoreViewTag.hasAttribute(LOCALE_ATTRNAME)) return
null;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPBundleHyperlinkPartitioner.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPBundleHyperlinkPartitioner.java 2009-04-14
17:15:42 UTC (rev 14742)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPBundleHyperlinkPartitioner.java 2009-04-14
18:25:10 UTC (rev 14743)
@@ -37,6 +37,10 @@
*/
public class JSPBundleHyperlinkPartitioner extends AbstractHyperlinkPartitioner
implements IHyperlinkPartitionRecognizer {
public static final String JSP_BUNDLE_PARTITION =
"org.jboss.tools.common.text.ext.jsp.JSP_BUNDLE";
+
+ protected String getPartitionType() {
+ return JSP_BUNDLE_PARTITION;
+ }
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
@@ -55,7 +59,7 @@
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
- String type = JSP_BUNDLE_PARTITION;
+ String type = getPartitionType();
int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
int offset = superRegion.getOffset();
@@ -178,46 +182,52 @@
}
- if (sVar != null && sProp != null) return true;
+ if (sVar == null || sProp == null) return false;
- TaglibManagerWrapper tmw = new TaglibManagerWrapper();
- tmw.init(document, region.getOffset());
- if(!tmw.exists()) return false;
-
- String prefix = tmw.getCorePrefix();
-
- if (prefix == null) return false;
-
- // Find loadBundle tag
- List<Element> lbTags = new ArrayList<Element>();
- NodeList list = xmlDocument.getElementsByTagName(prefix + ":loadBundle");
- for (int i = 0; list != null && i < list.getLength(); i++) {
- Element el = (Element)list.item(i);
- int end = Utils.getValueEnd(el);
- if (end >= 0 && end < region.getOffset()) {
- lbTags.add(el);
- }
- }
+ String[] prefixes = getLoadBundleTagPrefixes(document, region.getOffset());
+ if (prefixes == null) return false;
- Element lbTag = null;
- for (int i = 0; i < lbTags.size(); i++) {
- Element el = lbTags.get(i);
- Attr var = el.getAttributeNode("var");
-
- if (bundleProp.startsWith(var.getValue())) {
- lbTag = el;
- break;
+ for (String prefix : prefixes) {
+ // Find loadBundle tag
+ List<Element> lbTags = new ArrayList<Element>();
+ NodeList list = xmlDocument.getElementsByTagName(prefix + ":loadBundle");
+ for (int i = 0; list != null && i < list.getLength(); i++) {
+ Element el = (Element)list.item(i);
+ int end = Utils.getValueEnd(el);
+ if (end >= 0 && end < region.getOffset()) {
+ lbTags.add(el);
+ }
}
+
+ Element lbTag = null;
+ for (int i = 0; i < lbTags.size(); i++) {
+ Element el = lbTags.get(i);
+ Attr var = el.getAttributeNode("var");
+
+ if (sVar.equals(var.getValue())) {
+ lbTag = el;
+ break;
+ }
+ }
+ if (lbTag != null) return true;
}
- if (lbTag == null) return false;
-
- return true;
+ return false;
} catch (BadLocationException x) {
JSFExtensionsPlugin.log("", x);
return false;
+ } catch (Exception x) {
+ JSFExtensionsPlugin.log("", x);
+ return false;
} finally {
smw.dispose();
}
}
+ protected String[] getLoadBundleTagPrefixes(IDocument document, int offset) {
+ TaglibManagerWrapper tmw = new TaglibManagerWrapper();
+ tmw.init(document, offset);
+ if(!tmw.exists()) return null;
+
+ return new String[] {tmw.getCorePrefix()};
+ }
}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlinkPartitioner.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlinkPartitioner.java 2009-04-14
17:15:42 UTC (rev 14742)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlinkPartitioner.java 2009-04-14
18:25:10 UTC (rev 14743)
@@ -46,8 +46,7 @@
if (xmlDocument == null) return null;
Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
- if (!recognize(document, superRegion)) return null;
-
+
IHyperlinkRegion r = getRegion(document, superRegion.getOffset());
if (r == null) return null;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPLoadBundleHyperlinkPartitioner.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPLoadBundleHyperlinkPartitioner.java 2009-04-14
17:15:42 UTC (rev 14742)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPLoadBundleHyperlinkPartitioner.java 2009-04-14
18:25:10 UTC (rev 14743)
@@ -32,6 +32,10 @@
*/
public class JSPLoadBundleHyperlinkPartitioner extends AbstractHyperlinkPartitioner
implements IHyperlinkPartitionRecognizer {
public static final String JSP_LOADBUNDLE_PARTITION =
"org.jboss.tools.common.text.ext.jsp.JSP_LOADBUNDLE";
+
+ protected String getPartitionType() {
+ return JSP_LOADBUNDLE_PARTITION;
+ }
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
@@ -51,7 +55,7 @@
String axis = getAxis(document, superRegion);
String contentType = superRegion.getContentType();
- String type = JSP_LOADBUNDLE_PARTITION;
+ String type = getPartitionType();
int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
int offset = superRegion.getOffset();
@@ -147,15 +151,22 @@
String name = lbTag.getTagName();
int column = name.indexOf(":");
if (column == -1) return false;
- String prefix = name.substring(0, column);
- if (prefix == null || prefix.trim().length() == 0) return false;
+ String usedPrefix = name.substring(0, column);
+ if (usedPrefix == null || usedPrefix.trim().length() == 0) return false;
- TaglibManagerWrapper tmw = new TaglibManagerWrapper();
- tmw.init(document, region.getOffset());
- if(!tmw.exists()) return true; //xhtml
-
- if (!prefix.equals(tmw.getCorePrefix())) return false;
+ String[] prefixes = getLoadBundleTagPrefixes(document, region.getOffset());
+ if (prefixes == null) return true; //xhtml
+ boolean prefixIsAbleToBeUsed = false;
+ for (String prefix : prefixes) {
+ if (usedPrefix.equals(prefix)) {
+ prefixIsAbleToBeUsed = true;
+ break;
+ }
+ }
+ if (!prefixIsAbleToBeUsed)
+ return false;
+
Attr lbTagVar = lbTag.getAttributeNode("var");
Attr lbTagBasename = lbTag.getAttributeNode("basename");
@@ -170,4 +181,12 @@
}
}
+ protected String[] getLoadBundleTagPrefixes(IDocument document, int offset) {
+ TaglibManagerWrapper tmw = new TaglibManagerWrapper();
+ tmw.init(document, offset);
+ if(!tmw.exists()) return null;
+
+ return new String[] {tmw.getCorePrefix()};
+ }
+
}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/LoadBundleHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/LoadBundleHyperlink.java 2009-04-14
17:15:42 UTC (rev 14742)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/LoadBundleHyperlink.java 2009-04-14
18:25:10 UTC (rev 14743)
@@ -11,15 +11,21 @@
package org.jboss.tools.jsf.text.ext.hyperlink;
import java.text.MessageFormat;
+import java.util.ArrayList;
import java.util.Properties;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.ui.IEditorPart;
import org.jboss.tools.common.text.ext.hyperlink.XModelBasedHyperlink;
import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.TaglibManagerWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.jsf.text.ext.JSFExtensionsPlugin;
import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
+import org.jboss.tools.jst.web.tld.TaglibData;
+import org.jboss.tools.jst.web.tld.VpeTaglibManager;
+import org.jboss.tools.jst.web.tld.VpeTaglibManagerProvider;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -81,39 +87,35 @@
StructuredModelWrapper smw = new StructuredModelWrapper();
try {
- TaglibManagerWrapper tmw = new TaglibManagerWrapper();
- tmw.init(getDocument(), region.getOffset());
-
- if (!tmw.exists()) return null;
- String prefix = tmw.getCorePrefix();
- if (prefix == null || prefix.length() == 0) return null;
-
- String nodeToFind = prefix + PREFIX_SEPARATOR + VIEW_TAGNAME;
-
smw.init(getDocument());
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
+ String[] prefixes = getLoadBundleTagPrefixes(region);
+ if(prefixes == null) return null;
+
Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
if (!(n instanceof Attr) ) return null;
Element el = ((Attr)n).getOwnerElement();
Element jsfCoreViewTag = null;
- while (el != null) {
- if (nodeToFind.equals(el.getNodeName())) {
- jsfCoreViewTag = el;
- break;
+ for (String prefix : prefixes) {
+ String nodeToFind = prefix + PREFIX_SEPARATOR + VIEW_TAGNAME;
+
+ while (el != null) {
+ if (nodeToFind.equals(el.getNodeName())) {
+ jsfCoreViewTag = el;
+ break;
+ }
+ Node parent = el.getParentNode();
+ el = (parent instanceof Element ? (Element)parent : null);
}
- if(!(el.getParentNode() instanceof Element)) {
- break;
- }
- el = (Element)el.getParentNode();
}
if (jsfCoreViewTag == null || !jsfCoreViewTag.hasAttribute(LOCALE_ATTRNAME)) return
null;
- String locale =
Utils.trimQuotes(((Attr)jsfCoreViewTag.getAttributeNode(LOCALE_ATTRNAME)).getValue());
+ String locale =
Utils.trimQuotes((jsfCoreViewTag.getAttributeNode(LOCALE_ATTRNAME)).getValue());
if (locale == null || locale.length() == 0) return null;
return locale;
} finally {
@@ -134,4 +136,30 @@
return MessageFormat.format(Messages.OpenBundle, baseName);
}
+ protected String[] getLoadBundleTagPrefixes(IRegion region) {
+ TaglibManagerWrapper tmw = new TaglibManagerWrapper();
+ tmw.init(getDocument(), region.getOffset());
+ if(tmw.exists()) {
+ return new String[] { tmw.getCorePrefix() };
+ } else {
+ VpeTaglibManager taglibManager = getTaglibManager();
+ if(taglibManager == null) return null;
+ TaglibData[] data = (TaglibData[])taglibManager.getTagLibs().toArray(new
TaglibData[0]);
+ ArrayList<String> prefixes = new ArrayList<String>();
+ for (int i = 0; i < data.length; i++) {
+
if("http://java.sun.com/jsf/core".equals(data[i].getUri()))
+ prefixes.add(data[i].getPrefix());
+ }
+ }
+ return null;
+ }
+
+ private VpeTaglibManager getTaglibManager() {
+ IEditorPart editor =
JSFExtensionsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if(editor instanceof VpeTaglibManagerProvider) {
+ return ((VpeTaglibManagerProvider)editor).getTaglibManager();
+ }
+ return null;
+ }
+
}