incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r159732 - in incubator/graffito/trunk/commons: ./ src/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/portals/ src/java/org/apache/portals/graffito/ src/java/org/apache/portals/graffito/exception/ src/java/org/apache/portals/graffito/util/ src/test/ src/test/org/ src/test/org/apache/ src/test/org/apache/portals/ src/test/org/apache/portals/graffito/ src/test/org/apache/portals/graffito/util/
Date Fri, 01 Apr 2005 21:33:51 GMT
Author: clombart
Date: Fri Apr  1 13:33:49 2005
New Revision: 159732

URL: http://svn.apache.org/viewcvs?view=rev&rev=159732
Log:
* Create a new subproject : graffito commons which contains common classes used in other Graffito
projects :
- Common exception
- Common util classes

Added:
    incubator/graffito/trunk/commons/
    incubator/graffito/trunk/commons/.classpath
    incubator/graffito/trunk/commons/.project
    incubator/graffito/trunk/commons/maven.xml
    incubator/graffito/trunk/commons/project.properties
    incubator/graffito/trunk/commons/project.xml
    incubator/graffito/trunk/commons/src/
    incubator/graffito/trunk/commons/src/java/
    incubator/graffito/trunk/commons/src/java/org/
    incubator/graffito/trunk/commons/src/java/org/apache/
    incubator/graffito/trunk/commons/src/java/org/apache/portals/
    incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/
    incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/
    incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/CmsInvalidUriException.java
    incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/ContentManagementException.java
    incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/
    incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/StreamUtil.java
    incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/UriUtil.java
    incubator/graffito/trunk/commons/src/test/
    incubator/graffito/trunk/commons/src/test/org/
    incubator/graffito/trunk/commons/src/test/org/apache/
    incubator/graffito/trunk/commons/src/test/org/apache/portals/
    incubator/graffito/trunk/commons/src/test/org/apache/portals/graffito/
    incubator/graffito/trunk/commons/src/test/org/apache/portals/graffito/util/
    incubator/graffito/trunk/commons/src/test/org/apache/portals/graffito/util/TestUriUtil.java

Added: incubator/graffito/trunk/commons/.classpath
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/.classpath?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/.classpath (added)
+++ incubator/graffito/trunk/commons/.classpath Fri Apr  1 13:33:49 2005
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<classpath>
+  <classpathentry excluding="" kind="src" path="src/java">
+  </classpathentry>
+  <classpathentry output="target/test-classes" kind="src" path="src/test">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.1.jar">
+  </classpathentry>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
+  </classpathentry>
+  <classpathentry kind="output" path="target/classes">
+  </classpathentry>
+</classpath>
\ No newline at end of file

Added: incubator/graffito/trunk/commons/.project
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/.project?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/.project (added)
+++ incubator/graffito/trunk/commons/.project Fri Apr  1 13:33:49 2005
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<projectDescription>
+  <name>graffito-commons</name>
+  <comment>Tools, utility classes and exceptions used in the different Graffito subproject</comment>
+  <projects>
+  </projects>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+      <arguments>
+      </arguments>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Added: incubator/graffito/trunk/commons/maven.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/maven.xml?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/maven.xml (added)
+++ incubator/graffito/trunk/commons/maven.xml Fri Apr  1 13:33:49 2005
@@ -0,0 +1,27 @@
+<!--
+Copyright 2004 The Apache Software Foundation
+
+Licensed 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.
+-->
+<project default="java:jar"
+         xmlns:j="jelly:core" 
+         xmlns:define="jelly:define"
+         xmlns:reactor="reactor">
+
+   
+   <goal name="deploy">
+  	<attainGoal name="jar:install"/>
+  	<copy file="${basedir}/target/${maven.final.name}.jar" todir="${org.apache.jetspeed.server.shared}"
overwrite="true"/>
+  </goal>
+
+</project>

Added: incubator/graffito/trunk/commons/project.properties
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/project.properties?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/project.properties (added)
+++ incubator/graffito/trunk/commons/project.properties Fri Apr  1 13:33:49 2005
@@ -0,0 +1,40 @@
+# Copyright 2004 The Apache Software Foundation
+#
+# Licensed 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.
+
+#-----------------------------------------------------------------------------------------------------
+# MAVEN REPORISTORIES
+#-----------------------------------------------------------------------------------------------------
+maven.repo.remote = http://www.bluesunrise.com/maven/, http://www.ibiblio.org/maven/, http://dist.codehaus.org/,
http://cvs.apache.org/repository
+
+#-----------------------------------------------------------------------------------------------------
+# MULTIPROJECTS
+#-----------------------------------------------------------------------------------------------------
+maven.multiproject.type=jar
+
+#-----------------------------------------------------------------------------------------------------
+# DOC : SITE & PDF DOC
+#-----------------------------------------------------------------------------------------------------
+maven.docs.dest=${basedir}/../../site/commons
+
+# Display the date on the Maven web site
+maven.xdoc.date = left
+
+maven.xdoc.version = ${pom.currentVersion}
+
+
+#-----------------------------------------------------------------------------------------------------
+# COMPILE 
+#-----------------------------------------------------------------------------------------------------
+maven.compile.deprecation=on
+

Added: incubator/graffito/trunk/commons/project.xml
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/project.xml?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/project.xml (added)
+++ incubator/graffito/trunk/commons/project.xml Fri Apr  1 13:33:49 2005
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed
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.
-->
+<project>
+<extend>${basedir}/../project.xml</extend>
  <pomVersion>3</pomVersion>
 <id>graffito-commons</id>
  <groupId>graffito</groupId>
  <name>Graffito
Commons</name>
  <currentVersion>1.0-a1-dev</currentVersion>
  <package>org.apache.portals.graffito</package>
 <description>
	  Tools, utility classes and exceptions used in the different Graffito
subproject
  </description>
  <shortDescription>Graffito Commons </shortDescription>

<repository>
+    <connection>scm:subversion:https://svn.apache.org/repos/asf/incubator/graffito/trunk/commons</connection>
+    <developerConnection>scm:subversion:https://svn.apache.org/repos/asf/incubator/graffito/trunk/commons</developerConnection>
+    <url>http://svn.apache.org/viewcvs</url>
+  </repository>
  
  <dependencies>
  </dependencies>
  <build>
   <sourceDirectory>src/java</sourceDirectory>
     <resources>
      <resource>
       <directory>${basedir}/src/java</directory>
        <excludes>
  
       <exclude>**/*.java</exclude>
        </excludes>
      </resource>
   </resources>
    <unitTestSourceDirectory>src/test</unitTestSourceDirectory>
   <unitTest>
       <includes>
        <include>**/Test*.java</include>
     </includes>
      <excludes>
      </excludes>
      <resources>
       <resource>
          <directory>${basedir}/src/test</directory>
         <excludes>
          <exclude>**/*.java</exclude>
          </excludes>
       </resource>
      </resources>
    </unitTest>
    
  </build>
 <reports>
+       <report>maven-javadoc-plugin</report>
+  </reports>
+    
+</project>

Added: incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/CmsInvalidUriException.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/CmsInvalidUriException.java?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/CmsInvalidUriException.java
(added)
+++ incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/CmsInvalidUriException.java
Fri Apr  1 13:33:49 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.portals.graffito.exception;
+
+
+
+/**
+ * <p>Exception occurs when a CmsObject is not valid</p>
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ *
+ * @version $Id: CmsInvalidUriException.java,v 1.1 2004/12/22 21:16:12 christophe Exp $ 
+ */
+
+public class CmsInvalidUriException extends ContentManagementException 
+{
+    /**
+     * Default Constructor without information.
+     */
+    public CmsInvalidUriException() 
+    {
+        super();
+    }
+    
+    /**
+     * Constructor with message.
+     * 
+     * @param message the message associated to the exception
+     */    
+    public CmsInvalidUriException(String message) 
+    {
+        super(message);
+    }
+    
+    /**
+     * Constructor with throwable object.
+     * 
+     * @param nested the associated throwable object
+     */    
+    public CmsInvalidUriException(Throwable nested)
+    {
+        super(nested);
+    }
+    
+    /**
+     * Constructor with message and throwable object.
+     * 
+     * @param message the message associated to the exception
+     * @param nested the associated throwable object
+     */    
+    public CmsInvalidUriException(String message, Throwable nested)
+    {
+        super(message, nested);
+    }
+
+}
+

Added: incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/ContentManagementException.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/ContentManagementException.java?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/ContentManagementException.java
(added)
+++ incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/exception/ContentManagementException.java
Fri Apr  1 13:33:49 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.portals.graffito.exception;
+
+
+/**
+ * <p>Occurs when anything unexpected happens within a CMS Service or tools.</p>
+ * 
+ * This is the ancester class for all specific CMS exception.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * 
+ * @version $Id: ContentManagementException.java,v 1.1 2004/12/22 21:16:12 christophe Exp
$
+ */
+
+public class ContentManagementException extends Exception
+{
+
+    /**
+     * Default Constructor without information.
+     */
+    public ContentManagementException() 
+    {
+        super();
+    }
+    
+    /**
+     * Constructor with message.
+     * 
+     * @param message the message associated to the exception
+     */
+    public ContentManagementException(String message) 
+    {
+        super(message);
+    }
+    
+    /**
+     * Constructor with throwable object.
+     * 
+     * @param nested the associated throwable object
+     */    
+    public ContentManagementException(Throwable nested)
+    {
+        super(nested);
+    }
+    
+    /**
+     * Constructor with message and throwable object.
+     * 
+     * @param message the message associated to the exception
+     * @param nested the associated throwable object
+     */    
+    public ContentManagementException(String message, Throwable nested)
+    {
+        super(message, nested);
+    }
+
+}

Added: incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/StreamUtil.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/StreamUtil.java?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/StreamUtil.java
(added)
+++ incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/StreamUtil.java
Fri Apr  1 13:33:49 2005
@@ -0,0 +1,74 @@
+/* Copyright 2002-2004 The Apache Software Foundation
+*
+* Licensed 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.portals.graffito.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+
+/**
+ * Utility class use for input stream management
+ * 
+ * @author Christope Lombart
+ *
+ */
+public class StreamUtil
+{
+	
+	private static int BUFFER_SIZE = 2048;
+	
+	/**
+	 * Get an array of byte from an inputstream
+	 * @param inputStream The input stream
+	 * @return The converted array of byte
+	 */
+	public static byte[] getContentByte(InputStream inputStream)
+	{
+
+		int byteCount = 0;
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		try
+		{
+			byte indata[] = new byte[BUFFER_SIZE];
+			
+			while ((byteCount = inputStream.read(indata,0,BUFFER_SIZE)) != -1 ) 
+			{
+					out.write(indata,0,byteCount);
+			
+			}
+			out.flush();
+			out.close();
+		}
+		catch (IOException e)
+		{
+			e.printStackTrace();
+			return null;
+		}
+		return out.toByteArray();
+						
+	}	
+
+	/**
+	 * Get the lenght of the inputstream
+	 * @param inputStream
+	 * @return the length
+	 */
+	public static int getSize(InputStream inputStream)
+	{
+	    return getContentByte(inputStream).length;
+	}
+
+}

Added: incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/UriUtil.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/UriUtil.java?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/UriUtil.java
(added)
+++ incubator/graffito/trunk/commons/src/java/org/apache/portals/graffito/util/UriUtil.java
Fri Apr  1 13:33:49 2005
@@ -0,0 +1,105 @@
+/* Copyright 2002-2004 The Apache Software Foundation
+*
+* Licensed 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.portals.graffito.util;
+
+import org.apache.portals.graffito.exception.CmsInvalidUriException;
+
+/**
+ * 
+ * Utility methods used for uri management
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe</a>
+ *
+ */
+public class UriUtil
+{
+     /** Uri path separator */
+     public static String  URI_SEPARATOR = "/";
+    
+     /**
+      * Check if the the cms object uri is valid
+      * @param uri The uri to validate
+      * @return true if the uri is valid, else false
+      */
+     public static boolean isValidUri(String uri)
+     {
+         if ((uri == null) ||
+             (uri.equals(URI_SEPARATOR)) ||
+             (uri.endsWith(URI_SEPARATOR)) ||
+             (! uri.startsWith(URI_SEPARATOR)) || 
+             uri.equals("") )
+         {
+             return false; 
+         }
+         return true;
+     }
+     
+     /**
+      * Get the parent uri
+      * @param uri The uri for wich the parent uri has to be returned
+      * @return The parent uri
+      * @throws CmsInvalidUriException when the uri is not valid
+      */
+     public static String getParentUri(String uri) throws CmsInvalidUriException
+     {
+         String parentUri = "";
+         
+         if (! isValidUri(uri))
+         {
+             throw new CmsInvalidUriException("Incorrect uri : " + uri);
+         }
+         
+         String[] path = uri.split(URI_SEPARATOR);         
+         
+         // Firts path element should be = empty string because a uri always start with '/'
+         // So, if len=2, means it is a root folder like '/foo'. 
+         // In this case the uri has not parent folder => return null
+         if (path.length == 2)
+         {
+             return null;
+         }
+         
+         for(int i=0; i < path.length -1; i++)
+         {   
+             if (! path[i].equals(""))
+             {    
+                parentUri += URI_SEPARATOR + path[i];
+             }
+         }                  
+         return parentUri;
+     }
+     
+     
+     /**
+      * Get the associated server scope from an uri. The server scope is always the uri prefix.
+      * For example, the server scope for the uri '/test/myfolder/mydoc.xml' is '/test'
+      * 
+      * TODO : review server scope like namespace (eg : "serverName:myfolder/mydoc.pdf")
+      * @param uri The uri 
+      * @return the servier scope.
+      * @throws CmsInvalidUriException
+      */
+     public static String getServerScope(String uri)  throws CmsInvalidUriException
+     {
+         if (! isValidUri(uri))
+         {
+             throw new CmsInvalidUriException("Incorrect uri : " + uri);
+         }
+         
+         String[] path = uri.split(URI_SEPARATOR);
+         return URI_SEPARATOR + path[1];
+     }
+
+}

Added: incubator/graffito/trunk/commons/src/test/org/apache/portals/graffito/util/TestUriUtil.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/commons/src/test/org/apache/portals/graffito/util/TestUriUtil.java?view=auto&rev=159732
==============================================================================
--- incubator/graffito/trunk/commons/src/test/org/apache/portals/graffito/util/TestUriUtil.java
(added)
+++ incubator/graffito/trunk/commons/src/test/org/apache/portals/graffito/util/TestUriUtil.java
Fri Apr  1 13:33:49 2005
@@ -0,0 +1,157 @@
+/* ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.portals.graffito.util;
+
+import org.apache.portals.graffito.exception.CmsInvalidUriException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test UriUtil
+ *
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
+ */
+public class TestUriUtil extends TestCase
+{
+
+
+    /**
+     * <p>Defines the test case name for junit.</p>
+     * @param testName The test case name.
+     */
+    public TestUriUtil(String testName)
+    {
+        super(testName);
+    }
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+    }
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+        super.tearDown();
+
+    }
+
+    /**
+     * Run the test suite
+     * @return the test
+     */
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(TestUriUtil.class);
+    }
+
+    /**
+     * Test isValidUri
+     *
+     */
+    public void testisValidUri()
+    {        
+        assertFalse("Uri '/' is not a correct uri", UriUtil.isValidUri("/"));
+        assertFalse("Uri '/folder1/' is not a correct uri", UriUtil.isValidUri("/folder1/"));
+        assertFalse("Uri '' is not a correct uri", UriUtil.isValidUri(""));
+        assertFalse("Null value is not a correct uri", UriUtil.isValidUri(null));
+        assertFalse("Uri 'foo' is not a correct uri", UriUtil.isValidUri("foo"));
+        assertTrue("Uri '/folder1' should be a correct uri", UriUtil.isValidUri("/folder1"));
+        assertTrue("Uri '/folder1/test.doc' should be a correct uri", UriUtil.isValidUri("/folder1/test.doc"));
+        assertTrue("Uri '/folder1/folder2/test.doc' should be a correct uri", UriUtil.isValidUri("/folder1/folder2/test.doc"));
+    }
+
+    /**
+     * Test getParentUri
+     *
+     */
+    public void testGetParentUri()
+    {
+        
+        try
+        {
+            String parentUri = UriUtil.getParentUri("/folder1");
+            assertNull("ParentUri for '/folder1' should be null", parentUri);
+        }
+        catch (CmsInvalidUriException e)
+        {
+            fail("/folder1 should be a correct uri");
+        }
+
+        try
+        {
+            String parentUri = UriUtil.getParentUri("/folder1/folder2");
+            assertTrue("ParentUri for '/folder1/folder2' should be /folder1", parentUri.equals("/folder1"));
+        }
+        catch (CmsInvalidUriException e)
+        {
+            fail("/folder1/folder2 should be a correct uri");
+        }
+
+        try
+        {
+            String parentUri = UriUtil.getParentUri("/folder1/test.doc");
+            assertTrue("ParentUri for '/folder1/test.doc' should be /folder1", parentUri.equals("/folder1"));
+        }
+        catch (CmsInvalidUriException e)
+        {
+            fail("/folder1 should be a correct uri");
+        }
+
+        try
+        {
+            String parentUri = UriUtil.getParentUri("/folder1/folder2/test.doc");
+            assertTrue("ParentUri for '/folder1/folder2/test.doc' should be /folder1/folder2",
parentUri
+                    .equals("/folder1/folder2"));
+        }
+        catch (CmsInvalidUriException e)
+        {
+            fail("/folder1 should be a correct uri");
+        }
+    }
+    
+    /** 
+     * Test getServerScope
+     *
+     */
+    public void testServerScope()
+    {
+        try
+        {
+            String scope = UriUtil.getServerScope("/graffitoserver/test/test.xml");
+            assertTrue("Incorrect scope for /graffitoserver/test/test.xml", scope.equals("/graffitoserver"));
+            
+            scope = UriUtil.getServerScope("/graffitoserver");
+            assertTrue("Incorrect scope for /graffitoserver", scope.equals("/graffitoserver"));
+            
+        }
+        catch (CmsInvalidUriException e)
+        {
+            fail("/graffitoserver/test/test.xml should be a correct uri");
+        }
+
+    }
+}
\ No newline at end of file



Mime
View raw message