Author: scabanovich
Date: 2008-04-04 08:33:45 -0400 (Fri, 04 Apr 2008)
New Revision: 7326
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/JSPStylesheetRelLinkHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPRootHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPStylesheetRelLinkHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTagAttributeHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTaglibHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTaglibHyperlinkPartitioner.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/util/Utils.java
Log:
JBIDE-895
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java 2008-04-04
12:31:50 UTC (rev 7325)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/AbstractHyperlink.java 2008-04-04
12:33:45 UTC (rev 7326)
@@ -139,9 +139,10 @@
protected IFile getFileFromProject(String fileName) {
IFile documentFile = getFile();
+ if(documentFile == null || !documentFile.isAccessible()) return null;
+ IProject project = documentFile.getProject();
try {
- IProject project = documentFile.getProject();
String name = Utils.trimFilePath(fileName);
IPath currentPath = documentFile.getLocation()
.removeLastSegments(1);
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/JSPStylesheetRelLinkHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/JSPStylesheetRelLinkHyperlink.java 2008-04-04
12:31:50 UTC (rev 7325)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/JSPStylesheetRelLinkHyperlink.java 2008-04-04
12:33:45 UTC (rev 7326)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink;
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -29,8 +30,8 @@
protected IRegion getRegion (int offset) {
StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(getDocument());
try {
- smw.init(getDocument());
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
@@ -117,7 +118,7 @@
};
return region;
- } catch (Exception x) {
+ } catch (BadLocationException x) {
//ignore
return null;
} finally {
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPRootHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPRootHyperlinkPartitioner.java 2008-04-04
12:31:50 UTC (rev 7325)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPRootHyperlinkPartitioner.java 2008-04-04
12:33:45 UTC (rev 7326)
@@ -62,8 +62,8 @@
public static String computeAxis(IDocument document, int offset) {
String axis = "";
StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
try {
- smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
@@ -89,8 +89,6 @@
parent = parent.getParentNode();
}
}
- } catch (Exception x) {
- //ignore
} finally {
smw.dispose();
}
@@ -148,6 +146,7 @@
return map;
} catch (Exception x) {
//ignore
+ //TODO narrow catch after study
return null;
} finally {
smw.dispose();
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPStylesheetRelLinkHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPStylesheetRelLinkHyperlinkPartitioner.java 2008-04-04
12:31:50 UTC (rev 7325)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPStylesheetRelLinkHyperlinkPartitioner.java 2008-04-04
12:33:45 UTC (rev 7326)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.jsp;
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.w3c.dom.Attr;
@@ -45,9 +46,10 @@
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ if(superRegion == null) return null;
StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
try {
- smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
@@ -64,9 +66,6 @@
IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
return region;
- } catch (Exception x) {
- //ignore
- return null;
} finally {
smw.dispose();
}
@@ -76,9 +75,10 @@
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ if(region == null) return false;
StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
try {
- smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
@@ -104,7 +104,7 @@
if (!LINK_TAGNAME.equalsIgnoreCase(tag.getNodeName()))
return false;
- String linkRel = getAttributeValue(document, tag, REL_ATTRNAME);
+ String linkRel = Utils.getAttributeValue(document, tag, REL_ATTRNAME);
if (!VALID_REL_ATTRVALUE.equalsIgnoreCase(linkRel))
return false;
@@ -143,24 +143,11 @@
return false;
return true;
- } catch (Exception x) {
- //ignore
- return false;
} finally {
smw.dispose();
}
}
- protected String getAttributeValue (IDocument document, Node node, String attrName) {
- try {
- Attr attr = (Attr)node.getAttributes().getNamedItem(attrName);
- return Utils.getTrimmedValue(document, attr);
- } catch (Exception x) {
- //ignore
- return null;
- }
- }
-
protected String getAxis(IDocument document, IHyperlinkRegion superRegion) {
if (superRegion.getAxis() == null || superRegion.getAxis().length() == 0) {
return JSPRootHyperlinkPartitioner.computeAxis(document, superRegion.getOffset()) +
"/";
@@ -170,8 +157,9 @@
protected IRegion getRegion (IDocument document, int offset) {
StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
+ smw.init(document);
try {
- smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
@@ -258,7 +246,7 @@
};
return region;
- } catch (Exception x) {
+ } catch (BadLocationException x) {
//ignore
return null;
} finally {
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTagAttributeHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTagAttributeHyperlinkPartitioner.java 2008-04-04
12:31:50 UTC (rev 7325)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTagAttributeHyperlinkPartitioner.java 2008-04-04
12:33:45 UTC (rev 7326)
@@ -16,7 +16,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
@@ -37,8 +36,8 @@
*/
protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
try {
- smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
@@ -58,9 +57,6 @@
IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
return region;
- } catch (Exception x) {
- ExtensionsPlugin.getPluginLog().logError("Error in parsing region", x);
- return null;
} finally {
smw.dispose();
}
@@ -70,9 +66,10 @@
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ if(region == null) return false;
StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
try {
- smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
@@ -82,9 +79,6 @@
return (JSP_ATTRIBUTE_TAGNAME.equals(n.getNodeName()) &&
!JSP_ELEMENT_TAGNAME.equals(n.getParentNode().getNodeName()) &&
n.getNodeName().indexOf(':') != -1);
- } catch (Exception x) {
- //ignore
- return false;
} finally {
smw.dispose();
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTaglibHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTaglibHyperlink.java 2008-04-04
12:31:50 UTC (rev 7325)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTaglibHyperlink.java 2008-04-04
12:33:45 UTC (rev 7326)
@@ -21,6 +21,8 @@
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.IDOMModel;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.jboss.tools.common.model.XModel;
@@ -28,6 +30,7 @@
import org.jboss.tools.common.model.util.FindObjectHelper;
import org.jboss.tools.common.text.ext.ExtensionsPlugin;
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.jst.web.tld.ITaglibMapping;
import org.jboss.tools.jst.web.tld.IWebProject;
@@ -42,14 +45,8 @@
* @see
com.ibm.sse.editor.AbstractHyperlink#doHyperlink(org.eclipse.jface.text.IRegion)
*/
protected void doHyperlink(IRegion region) {
-
- try {
- XModelObject object = getFilename(region);
- if(object != null) FindObjectHelper.findModelObject(object,
FindObjectHelper.IN_EDITOR_ONLY);
- } catch (Exception x) {
- // could not open editor
- openFileFailed();
- }
+ XModelObject object = getFilename(region);
+ if(object != null) FindObjectHelper.findModelObject(object,
FindObjectHelper.IN_EDITOR_ONLY);
}
protected final String JAR_FILE_PROTOCOL = "jar:file:/";//$NON-NLS-1$
@@ -58,18 +55,14 @@
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlink#openFileInEditor(java.lang.String)
*/
protected void openFileInEditor(String fileString) {
- try {
- if (fileString.startsWith(JAR_FILE_PROTOCOL)) {
- fileString = fileString.substring(JAR_FILE_PROTOCOL.length());
- IEditorInput jarEditorInput = createEditorInput(fileString);
- IEditorPart part = openFileInEditor(jarEditorInput, fileString);
- if (part == null) openFileFailed();
- } else {
- super.openFileInEditor(fileString);
- }
- } catch (Exception x) {
- openFileFailed();
- }
+ if (fileString.startsWith(JAR_FILE_PROTOCOL)) {
+ fileString = fileString.substring(JAR_FILE_PROTOCOL.length());
+ IEditorInput jarEditorInput = createEditorInput(fileString);
+ IEditorPart part = openFileInEditor(jarEditorInput, fileString);
+ if (part == null) openFileFailed();
+ } else {
+ super.openFileInEditor(fileString);
+ }
}
private XModelObject getFilename(IRegion region) {
@@ -98,9 +91,6 @@
ITaglibMapping tm = wp.getTaglibMapping();
if (tm == null) return null;
return tm.getTaglibObject(uri);
- } catch (Exception x) {
- ExtensionsPlugin.getPluginLog().logError("Error in obtaining file name from
region", x);
- return null;
} finally {
if (model != null) model.releaseFromRead();
}
@@ -118,14 +108,14 @@
}
private IRegion getRegion(int offset) {
- IStructuredModel model = null;
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(getDocument());
try {
- model = getModelManager().getExistingModelForRead(getDocument());
- IDOMDocument xmlDocument = (model instanceof IDOMModel) ? ((IDOMModel)
model).getDocument() : null;
+ Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
Node n = Utils.findNodeForOffset(xmlDocument, offset);
- if (n instanceof IDOMAttr) n = ((IDOMAttr)n).getOwnerElement();
+ if (n instanceof Attr) n = ((Attr)n).getOwnerElement();
if (!(n instanceof IDOMElement)) return null;
if (!"jsp:directive.taglib".equals(n.getNodeName())) return null;
@@ -154,11 +144,8 @@
};
return region;
- } catch (Exception x) {
- ExtensionsPlugin.getPluginLog().logError("Error in obtaining region", x);
- return null;
} finally {
- if (model != null) model.releaseFromRead();
+ smw.dispose();
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTaglibHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTaglibHyperlinkPartitioner.java 2008-04-04
12:31:50 UTC (rev 7325)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/jsp/JSPTaglibHyperlinkPartitioner.java 2008-04-04
12:33:45 UTC (rev 7326)
@@ -16,7 +16,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
@@ -33,9 +32,10 @@
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ if(document == null || superRegion == null) return null;
StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
try {
- smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return null;
@@ -56,9 +56,6 @@
IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
return region;
- } catch (Exception x) {
- ExtensionsPlugin.getPluginLog().logError("Error in parsing region", x);
- return null;
} finally {
smw.dispose();
}
@@ -69,9 +66,10 @@
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ if(document == null || region == null) return false;
StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
try {
- smw.init(document);
Document xmlDocument = smw.getDocument();
if (xmlDocument == null) return false;
@@ -79,9 +77,6 @@
if (n instanceof Attr) n = ((Attr)n).getOwnerElement();
if (!(n instanceof Element)) return false;
return ("jsp:directive.taglib".equals(n.getNodeName()));
- } catch (Exception x) {
- //ignore
- return false;
} finally {
smw.dispose();
}
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/util/Utils.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/util/Utils.java 2008-04-04
12:31:50 UTC (rev 7325)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/util/Utils.java 2008-04-04
12:33:45 UTC (rev 7326)
@@ -33,12 +33,13 @@
*/
public class Utils {
public static String trimQuotes(String word) {
+ if(word == null) return null;
+ String attrText = word;
+ int bStart = 0;
+ int bEnd = word.length() - 1;
+ StringBuffer sb = new StringBuffer(attrText);
+
try {
- 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) == '\"' ||
@@ -54,6 +55,7 @@
if (bEnd < bStart) bEnd = bStart;
return sb.substring(bStart, bEnd);
} catch (Exception x) {
+ //TODO remove that catch after study safety of code
return word;
}
}
@@ -63,41 +65,33 @@
}
static public Node findNodeForOffset(IDOMNode node, int offset) {
- Node result = null;
- try {
- if (!node.contains(offset)) return null;
+ if(node == null) return null;
+ if (!node.contains(offset)) return null;
- if (node.hasChildNodes()) {
- // Try to find the node in children
- NodeList children = node.getChildNodes();
- for (int i = 0; children != null && i < children.getLength(); i++) {
- IDOMNode child = (IDOMNode)children.item(i);
- if (child.contains(offset)) {
- result = findNodeForOffset(child, offset);
- return result;
- }
+ if (node.hasChildNodes()) {
+ // Try to find the node in children
+ NodeList children = node.getChildNodes();
+ for (int i = 0; children != null && i < children.getLength(); i++) {
+ IDOMNode child = (IDOMNode)children.item(i);
+ if (child.contains(offset)) {
+ return findNodeForOffset(child, offset);
}
}
+ }
// Not found in children or nave no children
- if (node.hasAttributes()) {
- // Try to find in the node attributes
- NamedNodeMap attributes = node.getAttributes();
-
- for (int i = 0; attributes != null && i < attributes.getLength(); i++) {
- IDOMNode attr = (IDOMNode)attributes.item(i);
- if (attr.contains(offset)) {
- result = attr;
- return attr;
- }
+ if (node.hasAttributes()) {
+ // Try to find in the node attributes
+ NamedNodeMap attributes = node.getAttributes();
+
+ for (int i = 0; attributes != null && i < attributes.getLength(); i++) {
+ IDOMNode attr = (IDOMNode)attributes.item(i);
+ if (attr.contains(offset)) {
+ return attr;
}
}
- // Return the node itself
- result = node;
- return node;
- } catch (Exception x) {
- ExtensionsPlugin.getPluginLog().logError("Error while finding node for
offset", x);
- return null;
}
+ // Return the node itself
+ return node;
}
public static String getParentAxisForNode(Document xmlDocument, Node node) {
@@ -115,22 +109,19 @@
}
public static String trimFilePath(String name) {
- try {
- StringTokenizer st = new StringTokenizer(name.replace('\\', '/'),
"/");
- String result = "";
- while(st.hasMoreTokens()) {
- String token = st.nextToken();
- if (!".".equals(token)){
- result += (result.length() == 0 ? token : "/" + token);
- }
+ if(name == null) return null;
+
+ StringTokenizer st = new StringTokenizer(name.replace('\\', '/'),
"/");
+ String result = "";
+ while(st.hasMoreTokens()) {
+ String token = st.nextToken();
+ if (!".".equals(token)){
+ result += (result.length() == 0 ? token : "/" + token);
}
- if (name.startsWith("/"))
- result = "/" + result;
- return result;
- } catch (Exception x) {
- //ignore
}
- return name;
+ if (name.startsWith("/"))
+ result = "/" + result;
+ return result;
}
public static IPath getRelativePath (final IPath base, final IPath path) {
@@ -156,6 +147,17 @@
domAttr.getEndOffset() - domAttr.getValueRegionStartOffset()));
}
+ public static String getAttributeValue (IDocument document, Node node, String attrName)
{
+ if(node == null || attrName == null || node.getAttributes() == null) return null;
+ Attr attr = (Attr)node.getAttributes().getNamedItem(attrName);
+ try {
+ return Utils.getTrimmedValue(document, attr);
+ } catch (BadLocationException x) {
+ ExtensionsPlugin.getPluginLog().logError(x);
+ return null;
+ }
+ }
+
public static int getValueStart(Node n) {
return (n instanceof IDOMAttr)
? ((IDOMAttr)n).getValueRegionStartOffset()