Author: adietish
Date: 2011-05-25 10:22:13 -0400 (Wed, 25 May 2011)
New Revision: 31473
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/databinding/validator/CompositeConverter.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/URIUtils.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/ui/utils/
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/ui/utils/URIUtilsTest.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java
Log:
[JBIDE-8599] moved check for URI schema presence to util class, created test for it
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF 2011-05-25
14:21:48 UTC (rev 31472)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF 2011-05-25
14:22:13 UTC (rev 31473)
@@ -29,4 +29,4 @@
Export-Package: org.jboss.tools.deltacloud.ui,
org.jboss.tools.deltacloud.ui.preferences,
org.jboss.tools.deltacloud.ui.wizard,
- org.jboss.tools.internal.deltacloud.ui.utils
+
org.jboss.tools.internal.deltacloud.ui.utils;x-friends:="org.jboss.tools.deltacloud.test"
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/databinding/validator/CompositeConverter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/databinding/validator/CompositeConverter.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/databinding/validator/CompositeConverter.java 2011-05-25
14:22:13 UTC (rev 31473)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.internal.deltacloud.ui.common.databinding.validator;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.runtime.Assert;
+
+/**
+ * A converter that applies a chain of converters.
+ *
+ * @author André Dietisheim
+ */
+public class CompositeConverter implements IConverter {
+
+ private final IConverter[] converters;
+
+ public CompositeConverter(final IConverter... converters) {
+ Assert.isLegal(converters != null);
+ Assert.isLegal(converters.length >= 1);
+
+ this.converters = converters;
+ }
+
+ @Override
+ public Object getFromType() {
+ return converters[0].getFromType();
+ }
+
+ @Override
+ public Object getToType() {
+ return converters[converters.length - 1].getToType();
+ }
+
+ @Override
+ public Object convert(Object fromValue) {
+ Object toValue = fromValue;
+ for (IConverter converter : converters) {
+ toValue = converter.convert(toValue);
+ }
+ return toValue;
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/databinding/validator/CompositeConverter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/URIUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/URIUtils.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/URIUtils.java 2011-05-25
14:22:13 UTC (rev 31473)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.internal.deltacloud.ui.utils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author André Dietisheim
+ *
+ */
+public class URIUtils {
+
+ private URIUtils() {
+ // inhibit instantiation
+ }
+
+ private static final String HTTP_PREFIX = "http://"; //$NON-NLS-1$
+ private static final Pattern URI_REGEXP =
Pattern.compile("(.+://)*(.+)(:[0-9]){0,1}"); //$NON-NLS-1$
+
+ public static String prependHttp(String url) {
+ if (!startsWithScheme(url)) {
+ return HTTP_PREFIX + url;
+ } else {
+ return url;
+ }
+ }
+
+ public static boolean startsWithScheme(String url) {
+ if (url == null || url.length() == 0) {
+ return false;
+ } else {
+ try {
+ Matcher matcher = URI_REGEXP.matcher(url);
+ if (matcher.matches()) {
+ return matcher.group(1) != null;
+ }
+ } catch (Exception e ) {
+ // ignore
+ }
+ return false;
+ }
+ }
+
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/URIUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java 2011-05-25
14:21:48 UTC (rev 31472)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java 2011-05-25
14:22:13 UTC (rev 31473)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.tools.internal.deltacloud.ui.wizards;
-import java.net.URI;
import java.text.MessageFormat;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -21,6 +20,7 @@
import org.jboss.tools.deltacloud.core.DeltaCloudDriver;
import org.jboss.tools.deltacloud.core.DeltaCloudException;
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.ObservableUIPojo;
+import org.jboss.tools.internal.deltacloud.ui.utils.URIUtils;
/**
* @author Andre Dietisheim
@@ -37,8 +37,6 @@
public static final String INVALID_URL = "ErrorInvalidURL.text";
//$NON-NLS-1$
public static final String NONCLOUD_URL = "ErrorNonCloudURL.text";
//$NON-NLS-1$
- private static final String HTTP_PREFIX = "http://"; //$NON-NLS-1$
-
private String name;
private String url;
private String username;
@@ -54,33 +52,12 @@
public CloudConnectionPageModel(String name, String url, String username, String
password, DeltaCloudDriver driver) {
this.name = name;
this.initialName = name;
- setUrl(prependHttp(url));
+ setUrl(URIUtils.prependHttp(url));
this.username = username;
this.password = password;
setDriverByUrl(url);
}
-
- private String prependHttp(String url) {
- if (!startsWithScheme(url)) {
- return HTTP_PREFIX + url;
- } else {
- return url;
- }
- }
- private boolean startsWithScheme(String url) {
- if (url == null || url.length() == 0) {
- return false;
- } else {
- try {
- String scheme = URI.create(url).getScheme();
- return scheme != null && scheme.length() > 0;
- } catch (IllegalArgumentException e ) {
- return false;
- }
- }
- }
-
public String getUsername() {
return username;
}
Added:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/ui/utils/URIUtilsTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/ui/utils/URIUtilsTest.java
(rev 0)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/ui/utils/URIUtilsTest.java 2011-05-25
14:22:13 UTC (rev 31473)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.internal.deltacloud.test.ui.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.jboss.tools.internal.deltacloud.ui.utils.URIUtils;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ *
+ */
+public class URIUtilsTest {
+
+ @Test
+ public void uriWithPortDoesNotStartWithScheme() {
+ assertFalse(URIUtils.startsWithScheme("localhost:3001"));
+ }
+
+ @Test
+ public void uriWithoutPortDoesNotStartWithScheme() {
+ assertFalse(URIUtils.startsWithScheme("localhost"));
+ }
+
+ @Test
+ public void uriWithPortStartsWithScheme() {
+ assertTrue(URIUtils.startsWithScheme("http://localhost:3001"));
+ }
+
+ @Test
+ public void uriWithoutPortStartsWithScheme() {
+ assertTrue(URIUtils.startsWithScheme("http://localhost"));
+ }
+}
Property changes on:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/ui/utils/URIUtilsTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain