incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r125814 - /incubator/graffito/trunk/api /incubator/graffito/trunk/api/src/java/org/apache/portals/graffito/util /incubator/graffito/trunk/api/src/java/org/apache/portals/graffito/util/CmsUtil.java
Date Thu, 20 Jan 2005 21:30:30 GMT
Author: clombart
Date: Thu Jan 20 13:30:28 2005
New Revision: 125814

URL: http://svn.apache.org/viewcvs?view=rev&rev=125814
Log:
Add utility class
Added:
   incubator/graffito/trunk/api/src/java/org/apache/portals/graffito/util/
   incubator/graffito/trunk/api/src/java/org/apache/portals/graffito/util/CmsUtil.java
Modified:
   incubator/graffito/trunk/api/   (props changed)

Added: incubator/graffito/trunk/api/src/java/org/apache/portals/graffito/util/CmsUtil.java
Url: http://svn.apache.org/viewcvs/incubator/graffito/trunk/api/src/java/org/apache/portals/graffito/util/CmsUtil.java?view=auto&rev=125814
==============================================================================
--- (empty file)
+++ incubator/graffito/trunk/api/src/java/org/apache/portals/graffito/util/CmsUtil.java	Thu
Jan 20 13:30:28 2005
@@ -0,0 +1,104 @@
+/* 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.CmsInvalidObjectException;
+import org.apache.portals.graffito.model.CmsObject;
+
+
+
+/**
+ * 
+ * Utility methods used for uri management
+ * 
+ * @author <a href="mailto:christophe.lombart@sword-technologies.com">Lombart Christophe</a>
+ *
+ */
+public class CmsUtil
+{
+     
+     /**
+      * 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(CmsObject.URI_SEPARATOR)) ||
+             (uri.endsWith(CmsObject.URI_SEPARATOR)) ||
+             (! uri.startsWith(CmsObject.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 CmsInvalidObjectException when the uri is not valid
+      */
+     public static String getParentUri(String uri) throws CmsInvalidObjectException
+     {
+         String parentUri = "";
+         
+         if (! isValidUri(uri))
+         {
+             throw new CmsInvalidObjectException("Incorrect uri : " + uri);
+         }
+         
+         String[] path = uri.split(CmsObject.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 += CmsObject.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'
+      * @param uri The uri 
+      * @return the servier scope.
+      * @throws CmsInvalidObjectException
+      */
+     public static String getServerScope(String uri)  throws CmsInvalidObjectException
+     {
+         if (! isValidUri(uri))
+         {
+             throw new CmsInvalidObjectException("Incorrect uri : " + uri);
+         }
+         
+         String[] path = uri.split(CmsObject.URI_SEPARATOR);
+         return CmsObject.URI_SEPARATOR + path[1];
+     }
+
+}

Mime
View raw message