Author: mir
Date: Wed Mar  3 16:51:37 2010
New Revision: 918567

URL: http://svn.apache.org/viewvc?rev=918567&view=rev
Log:
CLEREZZA-129: merged with trunk

Modified:
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/
   (props changed)
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/pom.xml
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java

Propchange: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar  3 16:51:37 2010
@@ -1,5 +1,6 @@
 
/incubator/clerezza/issues/CLEREZZA-103/org.apache.clerezza.platform.content:907223-909027
 
/incubator/clerezza/issues/CLEREZZA-113/org.apache.clerezza.platform.content:908544-911013
+/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.platform.content:917938-918563
 
/incubator/clerezza/issues/CLEREZZA-25/org.apache.clerezza.platform.content:891178-892849
 
/incubator/clerezza/issues/CLEREZZA-65/org.apache.clerezza.platform.content:897875-897920
 
/incubator/clerezza/issues/CLEREZZA-70/org.apache.clerezza.platform.content:897917-903631

Modified: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/pom.xml?rev=918567&r1=918566&r2=918567&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/pom.xml
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/pom.xml
 Wed Mar  3 16:51:37 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/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java?rev=918567&r1=918566&r2=918567&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
 Wed Mar  3 16:51:37 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/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java?rev=918567&r1=918566&r2=918567&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
 Wed Mar  3 16:51:37 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,13 @@
                        @FormParam(value = "parentCollectionUri") UriRef 
parentCollectionUri,
                        @FormParam(value = "pos") Integer pos,
                        @FormParam(value = "name") String name) {
-               UriRef collectionUri = 
hierarchyService.createCollectionUri(parentCollectionUri, 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 +137,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/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java?rev=918567&r1=918566&r2=918567&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
 Wed Mar  3 16:51:37 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/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java?rev=918567&r1=918566&r2=918567&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyService.java
 Wed Mar  3 16:51:37 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;
@@ -51,6 +49,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
@@ -91,13 +91,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);
@@ -129,7 +139,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);
@@ -153,6 +172,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,
@@ -300,6 +324,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);
@@ -328,7 +357,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);
@@ -350,7 +379,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);
@@ -455,16 +484,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/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java?rev=918567&r1=918566&r2=918567&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
 Wed Mar  3 16:51:37 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