diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-28 16:12:44 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-28 16:12:44 +0000 |
commit | 5477f3d8a1f06c57fd23def63956600fb50645df (patch) | |
tree | 9e17ee01f5362fb98714a1277010ae6942ede8da /java/sca/modules | |
parent | ee2e094cf6fc70c9a6f2890c3332e58375fe4203 (diff) |
Automatically change : to :// in domain node config uri to make it easier to type
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@808939 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
2 files changed, 37 insertions, 1 deletions
diff --git a/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java b/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java index 91f4ff17d1..39f60c4a1d 100644 --- a/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java +++ b/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java @@ -115,7 +115,7 @@ public class DomainNode { }
protected void parseConfigURI(String configURI) {
- URI uri = URI.create(configURI);
+ URI uri = URI.create(fixScheme(configURI));
String dn = uri.getHost();
if (dn == null || dn.length() < 1) {
dn = DEFAULT_DOMAIN_NAME;
@@ -136,4 +136,19 @@ public class DomainNode { }
}
}
+
+ /**
+ * I keep typing the scheme part with just a colon instead of colon slash slash
+ * which URI doesn't parse properly which irritates me so fix it up here
+ */
+ private String fixScheme(String uri) {
+ int i = uri.indexOf(":");
+ if (i > -1 && uri.charAt(i+1) != '/') {
+ uri = uri.replaceFirst(":", ":/");
+ }
+ if (i > -1 && uri.charAt(i+2) != '/') {
+ uri = uri.replaceFirst(":/", "://");
+ }
+ return uri;
+ }
}
diff --git a/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java b/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java index 6327ae06b2..4ca8f180bb 100644 --- a/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java +++ b/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java @@ -39,4 +39,25 @@ public class ConfigTestCase{ assertEquals("y", domain.getConfigAttributes().getAttributes().get("p2"));
}
+ @Test
+ public void testConfig1() throws Exception {
+ DomainNode domain = new DomainNode("foo:someDomain:1234?p1=x&p2=y");
+ assertEquals(4, domain.getConfigAttributes().getAttributes().size());
+ assertEquals("someDomain", domain.getDomainName());
+ assertEquals("foo", domain.getConfigAttributes().getAttributes().get("domainScheme"));
+ assertEquals("someDomain", domain.getConfigAttributes().getAttributes().get("domainName"));
+ assertEquals("x", domain.getConfigAttributes().getAttributes().get("p1"));
+ assertEquals("y", domain.getConfigAttributes().getAttributes().get("p2"));
+ }
+
+ @Test
+ public void testConfig2() throws Exception {
+ DomainNode domain = new DomainNode("foo:/someDomain:1234?p1=x&p2=y");
+ assertEquals(4, domain.getConfigAttributes().getAttributes().size());
+ assertEquals("someDomain", domain.getDomainName());
+ assertEquals("foo", domain.getConfigAttributes().getAttributes().get("domainScheme"));
+ assertEquals("someDomain", domain.getConfigAttributes().getAttributes().get("domainName"));
+ assertEquals("x", domain.getConfigAttributes().getAttributes().get("p1"));
+ assertEquals("y", domain.getConfigAttributes().getAttributes().get("p2"));
+ }
}
|