Author: rfeng
Date: Fri May 15 18:34:59 2009
New Revision: 775282

URL: http://svn.apache.org/viewvc?rev=775282&view=rev
Log:
Update NodeUtil and add a test case

Added:
    
tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java
Modified:
    
tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java

Modified: 
tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java?rev=775282&r1=775281&r2=775282&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
 (original)
+++ 
tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
 Fri May 15 18:34:59 2009
@@ -22,6 +22,7 @@
 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 @@
     }
 
     /**
-     * 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 @@
         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);
+        }
+    }
+
 }

Added: 
tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java?rev=775282&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java
 (added)
+++ 
tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeUtilTestCase.java
 Fri May 15 18:34:59 2009
@@ -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());
+    }
+}


Reply via email to