Author: adietish
Date: 2011-12-07 10:12:02 -0500 (Wed, 07 Dec 2011)
New Revision: 37060
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/utils/UrlUtils.java
Log:
[JBIDE-10171] fixed regexp to look for URLs when you click the link in the creation log
dialog
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/utils/UrlUtils.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/utils/UrlUtils.java 2011-12-07
14:26:51 UTC (rev 37059)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/utils/UrlUtils.java 2011-12-07
15:12:02 UTC (rev 37060)
@@ -20,8 +20,19 @@
private static final int HTTP_SCHEME_MAX_LENGTH = 8;
private static final char HTTP_SCHEME_START_CHAR = 'h';
- private static final Pattern HTTP_SCHEME_REGEX = Pattern.compile("http?://");
-
+ private static final Pattern HTTP_SCHEME_REGEX =
Pattern.compile("http[s]{0,1}://");
+
+ /**
+ * Returns an url that was found in the given text. It starts looking
+ * backwards from the given offset within the given string. Returns
+ * <code>null</code> if none was found.
+ *
+ * @param offset
+ * starting point to look back in the given text.
+ * @param text
+ * the text to search for an url
+ * @return the url that was found in the text
+ */
public static String getUrl(int offset, String text) {
int start = getUrlStart(offset, text);
if (start == -1) {
@@ -34,11 +45,19 @@
return text.substring(start, stop);
}
-
+
+ /**
+ * Steps back in the given text until the beginning of the text or an
+ * occurrence of http(s):// is found.
+ *
+ * @param offset the offset to start with stepping backwards
+ * @param text the text to search
+ * @return the index at which http(s):// was found
+ */
private static int getUrlStart(int offset, String text) {
for (int i = offset; i > 0; --i) {
- if (text.charAt(i) == HTTP_SCHEME_START_CHAR
- && (i + HTTP_SCHEME_MAX_LENGTH < text.length())) {
+ if (text.charAt(i) == HTTP_SCHEME_START_CHAR
+ && (i + HTTP_SCHEME_MAX_LENGTH < text.length())) {
Matcher matcher = HTTP_SCHEME_REGEX.matcher(text.substring(i, i +
HTTP_SCHEME_MAX_LENGTH));
if (matcher.find()) {
return i;
Show replies by date