View Javadoc

1   package org.codehaus.classworlds;
2   
3   /***
4    * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
5    * @version $Id: UrlUtils.java,v 1.1.1.1 2004/07/01 13:59:19 jvanzyl Exp $
6    */
7   public class UrlUtils
8   {
9       public static String normalizeUrlPath( String name )
10      {
11          if ( name.startsWith( "/" ) )
12          {
13              name = name.substring( 1 );
14          }
15  
16          // Looking for org/codehaus/werkflow/personality/basic/../common/core-idioms.xml
17          //                                               |    i  |
18          //                                               +-------+ remove
19          //
20          int i = name.indexOf( "/.." );
21  
22          // Can't be at the beginning because we have no root to refer to so
23          // we start at 1.
24          if ( i > 0 )
25          {
26              int j = name.lastIndexOf( "/", i - 1 );
27  
28              name = name.substring( 0, j ) + name.substring( i + 3 );
29          }
30  
31          return name;
32      }
33  }