Author: adietish
Date: 2011-09-30 05:14:58 -0400 (Fri, 30 Sep 2011)
New Revision: 35202
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringChecker.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringValidator.java
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/CommonUIMessages.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/UrlString2BooleanConverter.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties
Log:
[JBIDE-9793] implemented simplified url validation
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/CommonUIMessages.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/CommonUIMessages.java 2011-09-30
08:53:08 UTC (rev 35201)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/CommonUIMessages.java 2011-09-30
09:14:58 UTC (rev 35202)
@@ -70,6 +70,8 @@
public static String BROWSER_COULD_NOT_DISPLAY_MALFORMED_URL;
+ public static String URLSTRINGVALIDATOR_NOT_A_VALID_URL;
+
static {
NLS.initializeMessages(BUNDLE_NAME, CommonUIMessages.class);
}
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringChecker.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringChecker.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringChecker.java 2011-09-30
09:14:58 UTC (rev 35202)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.ui.databinding;
+
+import java.util.regex.Pattern;
+
+/**
+ * @author André Dietisheim
+ */
+public class SimpleUrlStringChecker {
+
+ private static final Pattern simpleUrlPattern =
Pattern.compile(".+://[^\\.]+\\.[^\\.]+(\\.[^\\.]+){0,1}");
+ private String url;
+
+ public SimpleUrlStringChecker(String url) {
+ this.url = url;
+ }
+
+ public boolean isValid() {
+ return simpleUrlPattern.matcher(url).matches();
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringChecker.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringValidator.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringValidator.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringValidator.java 2011-09-30
09:14:58 UTC (rev 35202)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.ui.databinding;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.ui.CommonUIMessages;
+
+/**
+ * A {@link IValidator} that validates ok if the string it shall validate is not
+ * empty.
+ */
+public class SimpleUrlStringValidator implements IValidator {
+
+ /**
+ *
+ * validates the given url string. Validation passes only if the given value
+ * is not <tt>null</tt> and is a valid url. The url check is done on a
+ * simplified regex.
+ *
+ * @see SimpleUrlStringChecker#isValid()
+ *
+ */
+ public IStatus validate(Object value) {
+ if (!(value instanceof String
+ && new SimpleUrlStringChecker((String) value).isValid())) {
+ return ValidationStatus
+ .error(NLS.bind(CommonUIMessages.URLSTRINGVALIDATOR_NOT_A_VALID_URL, (String)
value));
+ }
+ return ValidationStatus.ok();
+ }
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/SimpleUrlStringValidator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/UrlString2BooleanConverter.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/UrlString2BooleanConverter.java 2011-09-30
08:53:08 UTC (rev 35201)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/UrlString2BooleanConverter.java 2011-09-30
09:14:58 UTC (rev 35202)
@@ -12,7 +12,6 @@
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.regex.Pattern;
import org.eclipse.core.databinding.conversion.Converter;
@@ -25,7 +24,6 @@
*/
public class UrlString2BooleanConverter extends Converter {
- private static final Pattern simpleUrlPattern =
Pattern.compile(".+://[^\\.]+\\.[^\\.]+(\\.[^\\.]+){0,1}");
public UrlString2BooleanConverter() {
super(String.class, Boolean.class);
@@ -42,7 +40,7 @@
private URL toUrl(String url) {
try {
- if (!simpleUrlPattern.matcher(url).matches()) {
+ if (!new SimpleUrlStringChecker(url).isValid()) {
return null;
}
return new URL(url);
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties 2011-09-30
08:53:08 UTC (rev 35201)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties 2011-09-30
09:14:58 UTC (rev 35202)
@@ -28,4 +28,6 @@
BUTTON_REMOVE=Remove
BROWSER_COULD_NOT_OPEN_BROWSER=Could not open browser for url \"{0}\".
-BROWSER_COULD_NOT_DISPLAY_MALFORMED_URL=Could not display malformed url
\"{0}\".
\ No newline at end of file
+BROWSER_COULD_NOT_DISPLAY_MALFORMED_URL=Could not display malformed url
\"{0}\".
+
+URLSTRINGVALIDATOR_NOT_A_VALID_URL=\"{0}\" is not a valid url.
\ No newline at end of file