diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-15 18:34:59 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-15 18:34:59 +0000 |
commit | 80f7efa886898658571776162c633bd5399d43e6 (patch) | |
tree | 8d7f8512c152052624b04058dac5d8e7cffa16df /java/sca/modules/node-impl/src | |
parent | 2a4b87ac24f89038777fda750c467515caf7e1fb (diff) |
Update NodeUtil and add a test case
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@775282 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/node-impl/src')
2 files changed, 59 insertions, 20 deletions
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java index c46d2116a3..83f17bc718 100644 --- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.node.impl; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; @@ -47,26 +48,6 @@ public class NodeUtil { } /** - * Escape the space in URL string - * @param uri - * @return - */ - static URI createURI(String uri) { - URI returnURI = null; - - try { - returnURI = URI.create(uri); - } catch( Exception e) { - try { - returnURI = new URI(null, uri, null); - } catch (Exception ee) { - throw new IllegalArgumentException("Invalid URI :" + uri, ee); - } - } - return returnURI; - } - - /** * Open a URL connection without cache * @param url * @return @@ -79,4 +60,25 @@ public class NodeUtil { is = connection.getInputStream(); return is; } + + /** + * Escape the space in URL string + * @param uri + * @return + */ + static URI createURI(String uri) { + int index = uri.indexOf(':'); + String scheme = null; + String ssp = uri; + if (index != -1) { + scheme = uri.substring(0, index); + ssp = uri.substring(index + 1); + } + try { + return new URI(scheme, ssp, null); + } catch (URISyntaxException e) { + throw new IllegalArgumentException(e); + } + } + } diff --git a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java new file mode 100644 index 0000000000..41898b6448 --- /dev/null +++ b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java @@ -0,0 +1,37 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+/**
+ *
+ */
+public class NodeUtilTestCase {
+ @Test
+ public void testCreateURI() {
+ Assert.assertEquals("/a/b", NodeUtil.createURI("/a/b").toString());
+ Assert.assertEquals("/a%20b", NodeUtil.createURI("/a b").toString());
+ Assert.assertEquals("file:/a/b", NodeUtil.createURI("file:/a/b").toString());
+ Assert.assertEquals("file:/a%20b", NodeUtil.createURI("file:/a b").toString());
+ }
+}
|