cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r501135 - in /incubator/cxf/trunk/rt/bindings/http/src: main/java/org/apache/cxf/binding/http/IriDecoderHelper.java test/java/org/apache/cxf/binding/http/IriDecoderTest.java
Date Mon, 29 Jan 2007 18:10:55 GMT
Author: dandiep
Date: Mon Jan 29 10:10:55 2007
New Revision: 501135

URL: http://svn.apache.org/viewvc?view=rev&rev=501135
Log:
Improve IRI decoding so that templates (i.e. {id}) don't need to be bounded by '/' or '?'.
CXF-394

Added:
    incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/IriDecoderTest.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java

Modified: incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java?view=diff&rev=501135&r1=501134&r2=501135
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java
(original)
+++ incubator/cxf/trunk/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/IriDecoderHelper.java
Mon Jan 29 10:10:55 2007
@@ -63,7 +63,9 @@
                     int locEnd = locPath.indexOf('}', idx1);
                     String name = locPath.substring(idx1 + 1, locEnd);
                     idx1 = locEnd;
-                    int end = findPartEnd(path, idx2);
+                    String endFragment = getEndFragment(locEnd + 1, locPath);
+
+                    int end = findPartEnd(path, idx2, endFragment);
                     String value = path.substring(idx2, end);
                     idx2 = end;
                     values.add(new Param(name, value));
@@ -85,6 +87,18 @@
         return values;
     }
 
+    private static String getEndFragment(int i, String locPath) {
+        int end = locPath.indexOf('{', i);
+        
+        if (end == -1) {
+            end = locPath.length();
+        } else if (locPath.charAt(end + 1) == '{') {
+            return getEndFragment(end + 1, locPath);
+        }
+        
+        return locPath.substring(i, end);
+    }
+
     public static void addParams(String input, int start, int stop, List<Param> params)
{
         while (start < stop) {
             int eq = input.indexOf('=', start);
@@ -98,18 +112,25 @@
     }
 
     /**
+     * @param endFragment 
      * 
      */
-    public static int findPartEnd(String path, int c) {
+    public static int findPartEnd(String path, int c, String endFragment) {
         int end = path.length();
-        int i = path.indexOf('/', c);
-        if (i >= c && i < end) {
-            end = i;
+        int i = end;
+        
+        if (!"".equals(endFragment)) {
+            i = path.indexOf(endFragment, c);
+            if (i >= c && i < end) {
+                end = i;
+            }
         }
-        i = path.indexOf('?', c);
+        
+        i =  path.indexOf('?', c);
         if (i >= c && i < end) {
             end = i;
         }
+        
         return end;
     }
 

Added: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/IriDecoderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/IriDecoderTest.java?view=auto&rev=501135
==============================================================================
--- incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/IriDecoderTest.java
(added)
+++ incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/IriDecoderTest.java
Mon Jan 29 10:10:55 2007
@@ -0,0 +1,42 @@
+/**
+ * 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.cxf.binding.http;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.binding.http.IriDecoderHelper.Param;
+
+public class IriDecoderTest extends TestCase {
+    public void testPaths() {
+        List<Param> params = IriDecoderHelper.decodeIri("test/123.xml", "test/{id}.xml");
+        assertEquals(1, params.size());
+        assertEquals("id", params.get(0).getName());
+        assertEquals("123", params.get(0).getValue());
+        
+        List<Param> p = IriDecoderHelper.decodeIri("http://host:8192/service/392/4?name=nodet",

+                "http://host:8192/service/{id}/{nb}");
+        assertNotNull(p);
+        //assertEquals(3, p.size());
+        assertEquals(new Param("id", "392"), p.get(0));
+        assertEquals(new Param("nb", "4"), p.get(1));
+        assertEquals(new Param("name", "nodet"), p.get(2));
+    }
+}

Propchange: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/IriDecoderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/IriDecoderTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/cxf/trunk/rt/bindings/http/src/test/java/org/apache/cxf/binding/http/IriDecoderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message