You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2011/03/24 16:16:18 UTC
svn commit: r1084990 -
/uima/sandbox/trunk/BSFAnnotator/src/main/java/org/apache/uima/annotator/bsf/BSFAnnotator.java
Author: schor
Date: Thu Mar 24 15:16:18 2011
New Revision: 1084990
URL: http://svn.apache.org/viewvc?rev=1084990&view=rev
Log:
[UIMA-2097] fix URI handling with quoted otherwise illegal chars
Modified:
uima/sandbox/trunk/BSFAnnotator/src/main/java/org/apache/uima/annotator/bsf/BSFAnnotator.java
Modified: uima/sandbox/trunk/BSFAnnotator/src/main/java/org/apache/uima/annotator/bsf/BSFAnnotator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/BSFAnnotator/src/main/java/org/apache/uima/annotator/bsf/BSFAnnotator.java?rev=1084990&r1=1084989&r2=1084990&view=diff
==============================================================================
--- uima/sandbox/trunk/BSFAnnotator/src/main/java/org/apache/uima/annotator/bsf/BSFAnnotator.java (original)
+++ uima/sandbox/trunk/BSFAnnotator/src/main/java/org/apache/uima/annotator/bsf/BSFAnnotator.java Thu Mar 24 15:16:18 2011
@@ -193,7 +193,8 @@ public class BSFAnnotator extends JCasAn
try {
// handle urls with embedded blanks, coded as %20
// https://issues.apache.org/jira/browse/UIMA-1748
- uri = url.toURI();
+ // https://issues.apache.org/jira/browse/UIMA-2097
+ uri = quote(url);
} catch (URISyntaxException e) {
uri = null;
}
@@ -229,4 +230,42 @@ public class BSFAnnotator extends JCasAn
return classpath;
}
+ // Maintainer note: remove these methods once base sdk 2.3.2 is released, and switch
+ // to using these methods from there
+ /**
+ * Create a URI from a string, with proper quoting.
+ * Already quoted things in the input string are not re-quoted.
+ * There are several cases:
+ * String has no characters needing quoting
+ * String has chars needing quoting, but no chars are currently quoted (e.g. %20)
+ * String has quoted (e.g. %20) characters but no other chars needing quoting
+ * String has quoted (e.g. %20) characters and chars needing quoting, not currently quoted
+ * -- this case will throw an exception
+ * @param s
+ * @return URI with proper quoting
+ * @throws URISyntaxException
+ */
+ private static URI quote (String s) throws URISyntaxException {
+ if (-1 == s.indexOf('%')) {
+ // 3 argument constructor does any needed quoting of otherwise illegal chars
+ // https://issues.apache.org/jira/browse/UIMA-2097
+ return new URI(null, s, null);
+ }
+
+ // assume s already has all otherwise illegal chars properly quoted
+ return new URI(s);
+ }
+
+ /**
+ * Create a URI from a URL, with proper quoting.
+ * Already quoted things in the input string are not re-quoted.
+ * @param u
+ * @return URI with proper quoting
+ * @throws URISyntaxException
+ */
+
+ private static URI quote(URL u) throws URISyntaxException {
+ return quote(u.toString());
+ }
+
}