Author: scabanovich
Date: 2007-09-17 11:17:51 -0400 (Mon, 17 Sep 2007)
New Revision: 3659
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ConverterHyperlink.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ForIDHyperlink.java
Log:
JBIDE-895
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ConverterHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ConverterHyperlink.java 2007-09-17
15:03:58 UTC (rev 3658)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ConverterHyperlink.java 2007-09-17
15:17:51 UTC (rev 3659)
@@ -13,6 +13,7 @@
import java.util.Properties;
import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -23,6 +24,7 @@
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.text.ext.JSFExtensionsPlugin;
import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
@@ -37,22 +39,23 @@
protected void doHyperlink(IRegion region) {
XModel xModel = getXModel();
if (xModel == null) return;
- try {
- WebPromptingProvider provider = WebPromptingProvider.getInstance();
-
- region = getRegion(region.getOffset());
- String converterID = getDocument().get(region.getOffset(), region.getLength());
- Properties p = new Properties();
- IFile file = getFile();
- if(file != null) p.put(WebPromptingProvider.FILE, file);
- provider.getList(xModel, WebPromptingProvider.JSF_OPEN_CONVERTOR, converterID, p);
- String error = p.getProperty(WebPromptingProvider.ERROR);
- if ( error != null && error.length() > 0) {
- openFileFailed();
- }
- } catch (Exception x) {
- //ignore
+ WebPromptingProvider provider = WebPromptingProvider.getInstance();
+ Properties p = new Properties();
+ region = getRegion(region.getOffset());
+ String converterID = null;
+ String error = null;
+ if(getDocument() != null && region != null) try {
+ converterID = getDocument().get(region.getOffset(), region.getLength());
+ } catch (BadLocationException x) {
+ JSFModelPlugin.getPluginLog().logError("Cannot get convertor id", x);
}
+ IFile file = getFile();
+ if(file != null) p.put(WebPromptingProvider.FILE, file);
+ provider.getList(xModel, WebPromptingProvider.JSF_OPEN_CONVERTOR, converterID, p);
+ error = p.getProperty(WebPromptingProvider.ERROR);
+ if ( error != null && error.length() > 0) {
+ openFileFailed();
+ }
}
/**
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ForIDHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ForIDHyperlink.java 2007-09-17
15:03:58 UTC (rev 3658)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ForIDHyperlink.java 2007-09-17
15:17:51 UTC (rev 3659)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.jsf.text.ext.hyperlink;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
@@ -92,65 +94,60 @@
}
private IDOMElement findElementByID(NodeList list, String id) {
- try {
- for (int i = 0; list != null && i < list.getLength(); i++) {
- try {
- IDOMElement element = (IDOMElement)list.item(i);
- Attr idAttr = element.getAttributeNode("id");
- if (idAttr != null) {
- String val = trimQuotes(idAttr.getNodeValue());
- if (id.equals(val)) {
- return element;
- }
- }
-
- if (element.hasChildNodes()) {
- IDOMElement child = findElementByID(element.getChildNodes(), id);
- if (child != null) return child;
- }
- } catch (Exception x) {
- // Probably not an IDOMElement
+ if(list == null || id == null) return null;
+ for (int i = 0; i < list.getLength(); i++) {
+ Node n = list.item(i);
+ if(!(n instanceof IDOMElement)) continue;
+
+ IDOMElement element = (IDOMElement)n;
+ Attr idAttr = element.getAttributeNode("id");
+ if (idAttr != null) {
+ String val = trimQuotes(idAttr.getNodeValue());
+ if (id.equals(val)) {
+ return element;
}
}
- } catch (Exception x) {
- JSFExtensionsPlugin.log("Error in looking for element by id " + id, x);
+
+ if (element.hasChildNodes()) {
+ IDOMElement child = findElementByID(element.getChildNodes(), id);
+ if (child != null) return child;
+ }
}
return null;
}
String getForId(IRegion region) {
+ if(region == null) return null;
+ IDocument document = getDocument();
+ if(document == null) return null;
try {
- return trimQuotes(getDocument().get(region.getOffset(), region.getLength()));
- } catch (Exception x) {
+ return trimQuotes(document.get(region.getOffset(), region.getLength()));
+ } catch (BadLocationException x) {
JSFExtensionsPlugin.log("", x);
return null;
}
}
private String trimQuotes(String word) {
- try {
- String attrText = word;
- int bStart = 0;
- int bEnd = word.length() - 1;
- StringBuffer sb = new StringBuffer(attrText);
+ if(word == null) return null;
+ String attrText = word;
+ int bStart = 0;
+ int bEnd = word.length() - 1;
+ StringBuffer sb = new StringBuffer(attrText);
- //find start and end of path property
- while (bStart < bEnd &&
- (sb.charAt(bStart) == '\'' || sb.charAt(bStart) == '\"' ||
- Character.isWhitespace(sb.charAt(bStart)))) {
- bStart++;
- }
- while (bEnd > bStart &&
- (sb.charAt(bEnd) == '\'' || sb.charAt(bEnd) == '\"' ||
- Character.isWhitespace(sb.charAt(bEnd)))) {
- bEnd--;
- }
- bEnd++;
- return sb.substring(bStart, bEnd);
- } catch (Exception x) {
- JSFExtensionsPlugin.log("", x);
- return word;
- }
+ //find start and end of path property
+ while (bStart < bEnd &&
+ (sb.charAt(bStart) == '\'' || sb.charAt(bStart) == '\"' ||
+ Character.isWhitespace(sb.charAt(bStart)))) {
+ bStart++;
+ }
+ while (bEnd > bStart &&
+ (sb.charAt(bEnd) == '\'' || sb.charAt(bEnd) == '\"' ||
+ Character.isWhitespace(sb.charAt(bEnd)))) {
+ bEnd--;
+ }
+ bEnd++;
+ return sb.substring(bStart, bEnd);
}
/**
Show replies by date