Author: mir
Date: Tue Mar  2 17:27:26 2010
New Revision: 918119

URL: http://svn.apache.org/viewvc?rev=918119&view=rev
Log:
CLEREZZA-129: fixed uri-encoding issues in platform.content

Added:
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/
      - copied from r917937, 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/
Modified:
    
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/pom.xml
    
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
    
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
    
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
    
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java
    
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java

Modified: 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/pom.xml?rev=918119&r1=917937&r2=918119&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/pom.xml
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/pom.xml
 Tue Mar  2 17:27:26 2010
@@ -90,5 +90,9 @@
                        <artifactId>junit</artifactId>
                        <scope>test</scope>
                </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>org.apache.clerezza.utils</artifactId>
+               </dependency>
        </dependencies>
 </project>
\ No newline at end of file

Modified: 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java?rev=918119&r1=917937&r2=918119&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
 Tue Mar  2 17:27:26 2010
@@ -84,7 +84,7 @@
                while (membersIter.hasNext()) {
                        UriRef uri = (UriRef) membersIter.next();
                        try {
-                               
nodes.add(hierarchyService.getHierarchyNode(uri));
+                               
nodes.add(hierarchyService.getHierarchyNodeWithEncodedUri(uri));
                        } catch (NodeDoesNotExistException ex) {
                                throw new RuntimeException(ex);
                        }
@@ -179,8 +179,9 @@
        }
 
        private boolean isSubcollectionOf(CollectionNode collection) {
-               return collection.getNode().getUnicodeString().
-                               startsWith(getNode().getUnicodeString());
+               return getNode().getUnicodeString().startsWith(
+                               collection.getNode().getUnicodeString());
+                               
        }
 
 }

Modified: 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java?rev=918119&r1=917937&r2=918119&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
 Tue Mar  2 17:27:26 2010
@@ -84,15 +84,14 @@
                        @FormParam(value = "parentCollectionUri") UriRef 
parentCollectionUri,
                        @FormParam(value = "pos") Integer pos,
                        @FormParam(value = "name") String name) {
-               UriRef resourceUri = 
hierarchyService.createNonCollectionUri(parentCollectionUri, name);
-               try {
-                       HierarchyNode node;
+               HierarchyNode node = null;
+               try {                   
                        if (pos == null) {
                                node = hierarchyService.
-                                               
createNonCollectionNode(resourceUri);
+                                               
createNonCollectionNode(parentCollectionUri, name);
                        } else {
                                node = hierarchyService.
-                                               
createNonCollectionNode(resourceUri, pos);
+                                               
createNonCollectionNode(parentCollectionUri, name, pos);
                        }
                } catch (NodeAlreadyExistsException ex) {
                        return 
Response.status(Response.Status.CONFLICT).entity(ex.toString()).
@@ -101,7 +100,7 @@
                        return 
Response.status(Response.Status.BAD_REQUEST).entity(e.toString()).
                                        type(MediaType.TEXT_PLAIN_TYPE).build();
                }
-               return 
Response.created(URI.create(resourceUri.getUnicodeString())).build();
+               return 
Response.created(URI.create(node.getNode().getUnicodeString())).build();
        }
 
        /**
@@ -123,13 +122,16 @@
                        @FormParam(value = "parentCollectionUri") UriRef 
parentCollectionUri,
                        @FormParam(value = "pos") Integer pos,
                        @FormParam(value = "name") String name) {
-               UriRef collectionUri = 
hierarchyService.createCollectionUri(parentCollectionUri, name);
+               System.out.println("###################################");
+               System.out.println(parentCollectionUri.getUnicodeString());
+               System.out.println(name);
+               CollectionNode node = null;
                try {
-                       CollectionNode node;
+                       
                        if (pos == null) {
-                               node = 
hierarchyService.createCollectionNode(collectionUri);
+                               node = 
hierarchyService.createCollectionNode(parentCollectionUri, name);
                        } else {
-                               node = 
hierarchyService.createCollectionNode(collectionUri, pos);
+                               node = 
hierarchyService.createCollectionNode(parentCollectionUri, name, pos);
                        }
                } catch (NodeAlreadyExistsException e) {
                        return 
Response.status(Response.Status.CONFLICT).entity(e.toString()).
@@ -138,7 +140,7 @@
                        return 
Response.status(Response.Status.BAD_REQUEST).entity(e.toString()).
                                        type(MediaType.TEXT_PLAIN_TYPE).build();
                }
-               return 
Response.created(URI.create(collectionUri.getUnicodeString())).build();
+               return 
Response.created(URI.create(node.getNode().getUnicodeString())).build();
        }
 
        /**

Modified: 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java?rev=918119&r1=917937&r2=918119&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
 Tue Mar  2 17:27:26 2010
@@ -72,7 +72,7 @@
                try {
                        UriRef parentCollectionUri = HierarchyUtils
                                        .extractParentCollectionUri(getNode());
-                       return 
hierarchyService.getCollectionNode(parentCollectionUri);
+                       return 
hierarchyService.getCollectionNodeWithEncodedUri(parentCollectionUri);
                } catch (NodeDoesNotExistException ex) {
                        throw new RuntimeException(ex);
                }
@@ -115,7 +115,7 @@
                if (newParentCollection.getMembersRdf().contains(newUri)) {
                        HierarchyNode existingNode = null;
                        try {
-                               existingNode = 
hierarchyService.getHierarchyNode(newUri);
+                               existingNode = 
hierarchyService.getHierarchyNodeWithEncodedUri(newUri);
                        } catch (NodeDoesNotExistException ex) {
                                throw new RuntimeException(ex);
                        }

Modified: 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java?rev=918119&r1=917937&r2=918119&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java
 Tue Mar  2 17:27:26 2010
@@ -18,10 +18,8 @@
  */
 package org.apache.clerezza.platform.content.hierarchy;
 
-import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.net.URLEncoder;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -47,6 +45,8 @@
 import org.apache.clerezza.rdf.ontologies.PLATFORM;
 import org.apache.clerezza.rdf.ontologies.RDF;
 import org.apache.clerezza.rdf.utils.GraphNode;
+import org.apache.clerezza.utils.UriException;
+import org.apache.clerezza.utils.UriUtil;
 
 /**
  * The hierarchy service is an OSGi service that provides methods for managing
@@ -87,13 +87,23 @@
         * @param uri
         */
        public HierarchyNode getHierarchyNode(UriRef uri)
+                       throws NodeDoesNotExistException{               
+               try {
+                       uri = new 
UriRef(UriUtil.encodePartlyEncodedPath(uri.getUnicodeString(), "UTF-8"));
+               } catch (UriException ex) {
+                       throw new RuntimeException(ex);
+               }
+               return getHierarchyNodeWithEncodedUri(uri);
+       }
+
+       HierarchyNode getHierarchyNodeWithEncodedUri(UriRef uri)
                        throws NodeDoesNotExistException{
                HierarchyNode hierarchyNode;
                try {
-                       hierarchyNode = 
+                       hierarchyNode =
                                        new CollectionNode(uri, 
cgProvider.getContentGraph(), this);
                } catch(IllegalArgumentException e) {
-                       hierarchyNode = 
+                       hierarchyNode =
                                        new HierarchyNode(uri, 
cgProvider.getContentGraph(), this);
                }
                checkExistence(hierarchyNode);
@@ -125,7 +135,16 @@
         */
        public CollectionNode getCollectionNode(UriRef uri)
                        throws NodeDoesNotExistException{
+               try {
+                       uri = new 
UriRef(UriUtil.encodePartlyEncodedPath(uri.getUnicodeString(), "UTF-8"));
+               } catch (UriException ex) {
+                       throw new RuntimeException(ex);
+               }
+               return getCollectionNodeWithEncodedUri(uri);
+       }
 
+       CollectionNode getCollectionNodeWithEncodedUri(UriRef uri)
+                       throws NodeDoesNotExistException{
                CollectionNode collectionNode =
                                new CollectionNode(uri, 
cgProvider.getContentGraph(), this);
                checkExistence(collectionNode);
@@ -149,6 +168,11 @@
         */
        public HierarchyNode createNonCollectionNode(UriRef uri, int 
posInParent)
                        throws NodeAlreadyExistsException {
+               try {
+                       uri = new 
UriRef(UriUtil.encodePath(uri.getUnicodeString(), "UTF-8"));
+               } catch (UriException ex) {
+                       throw new RuntimeException(ex);
+               }
                HierarchyUtils.ensureNonCollectionUri(uri);
                handleRootOfUri(uri);
                HierarchyNode hierarchyNode = new HierarchyNode(uri,
@@ -296,6 +320,11 @@
         */
        public CollectionNode createCollectionNode(UriRef uri, int posInParent)
                        throws NodeAlreadyExistsException {
+               try {
+                       uri = new 
UriRef(UriUtil.encodePartlyEncodedPath(uri.getUnicodeString(), "UTF-8"));
+               } catch (UriException ex) {
+                       throw new RuntimeException(ex);
+               }
                HierarchyUtils.ensureCollectionUri(uri);
                handleRootOfUri(uri);
                addCollectionTypeTriple(uri);
@@ -324,7 +353,7 @@
         * @throws IllegalArgumentException Thrown if uri ends not with a '/'
         * @return the created collection node.
         */
-       public HierarchyNode createCollectionNode(UriRef parentCollection, 
String name, int posInParent)
+       public CollectionNode createCollectionNode(UriRef parentCollection, 
String name, int posInParent)
                        throws NodeAlreadyExistsException {
                UriRef uri = createCollectionUri(parentCollection, name);
                return createCollectionNode(uri, posInParent);
@@ -346,7 +375,7 @@
         * @throws IllegalArgumentException Thrown if uri ends not with a '/'
         * @return the created collection node.
         */
-       public HierarchyNode createCollectionNode(UriRef parentCollection, 
String name)
+       public CollectionNode createCollectionNode(UriRef parentCollection, 
String name)
                        throws NodeAlreadyExistsException {
                UriRef uri = createCollectionUri(parentCollection, name);
                return createCollectionNode(uri);
@@ -438,16 +467,11 @@
         * @return
         */
        UriRef createCollectionUri(UriRef parrentCollectionUri, String name) {
-               return new UriRef(
-                               createNonCollectionUri(parrentCollectionUri, 
name).getUnicodeString() + "/");
+               return new UriRef(parrentCollectionUri.getUnicodeString() + 
name + "/");
        }
 
        UriRef createNonCollectionUri(UriRef parentCollectionUri, String name) {
-               try {
-                       return new 
UriRef(parentCollectionUri.getUnicodeString() +
-                                       URLEncoder.encode(name, "UTF-8"));
-               } catch (UnsupportedEncodingException ex) {
-                       throw new RuntimeException(ex);
-               }
+               return new UriRef(parentCollectionUri.getUnicodeString() + 
name);
        }
+
 }

Modified: 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java?rev=918119&r1=917937&r2=918119&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
 Tue Mar  2 17:27:26 2010
@@ -37,6 +37,7 @@
 import org.apache.clerezza.rdf.ontologies.HIERARCHY;
 import org.apache.clerezza.rdf.ontologies.PLATFORM;
 import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.utils.UriUtil;
 
 
 /**
@@ -51,7 +52,7 @@
        private UriRef fooResource3 = new 
UriRef("http://localhost:8282/foo/resource3";);
        private UriRef fooTest = new UriRef("http://localhost:8282/foo/test/";);
        private UriRef fooTestResource4 = new 
UriRef("http://localhost:8282/foo/test/resource4";);
-       private UriRef fooFolder1 = new 
UriRef("http://localhost:8282/foo/folder1/";);   
+       private UriRef fooFolder1 = new 
UriRef("http://localhost:8282/foo/folder1/";);
        private UriRef bar = new UriRef("http://localhost:8282/bar/";);
        private UriRef barResource = new 
UriRef("http://localhost:8282/bar/resource";);
        private UriRef barResource2 = new 
UriRef("http://localhost:8282/bar/resource2";);
@@ -62,6 +63,9 @@
        private UriRef newRootTest = new UriRef("http://newRoot/test/";);
        private UriRef newRoot2Resource = new 
UriRef("http://newRoot2/resource";);
        private UriRef newRoot2 = new UriRef("http://newRoot2/";);
+       private UriRef encodedResource = new UriRef("http://localhost:8282/t 
+");
+       private UriRef encodedCollection = new UriRef("http://localhost:8282/t 
+/");
+
         
 
        @Test
@@ -117,15 +121,33 @@
                Assert.assertTrue(exceptionThrown);
        }
 
-        @Test
+    @Test
        public void nonCollectionNodeCreation() throws Exception{
                HierarchyService hierarchyService = getHierarchyService();
                HierarchyNode fooTestResource4Node = hierarchyService.
-                        createNonCollectionNode(fooTestResource4, 0);
-                CollectionNode fooTestNode = fooTestResource4Node.getParent();
-                Assert.assertEquals(fooTest, fooTestNode.getNode());
-                CollectionNode fooNode = fooTestNode.getParent();
-                Assert.assertEquals(foo, fooNode.getNode());
+               createNonCollectionNode(fooTestResource4, 0);
+               CollectionNode fooTestNode = fooTestResource4Node.getParent();
+               Assert.assertEquals(fooTest, fooTestNode.getNode());
+               CollectionNode fooNode = fooTestNode.getParent();
+               Assert.assertEquals(foo, fooNode.getNode());
+       }
+
+       @Test
+       public void nonCollectionNodeCreationWithEncodedCharacters() throws 
Exception{
+               HierarchyService hierarchyService = getHierarchyService();
+               hierarchyService.createNonCollectionNode(encodedResource, 0);
+        HierarchyNode encodedNode = 
hierarchyService.getHierarchyNode(encodedResource);
+               
Assert.assertEquals(UriUtil.encodePath(encodedResource.getUnicodeString(), 
"UTF-8"),
+                               encodedNode.getNode().getUnicodeString());
+       }
+
+       @Test
+       public void collectionNodeCreationWithEncodedCharacters() throws 
Exception{
+               HierarchyService hierarchyService = getHierarchyService();
+               hierarchyService.createCollectionNode(encodedCollection, 0);
+        CollectionNode encodedNode = 
hierarchyService.getCollectionNode(encodedCollection);
+               
Assert.assertEquals(UriUtil.encodePath(encodedCollection.getUnicodeString(), 
"UTF-8"),
+                               encodedNode.getNode().getUnicodeString());
        }
 
        @Test


Reply via email to