1 package org.apache.maven.wagon.providers.webdav;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.codehaus.plexus.util.StringUtils;
23
24 import java.util.List;
25 import java.util.Arrays;
26
27 /**
28 * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
29 */
30 public class PathNavigator
31 {
32 private final List<String> list;
33
34 private int currentPosition;
35
36 public PathNavigator( String path )
37 {
38 list = Arrays.asList( StringUtils.split( path, "/" ) );
39 currentPosition = list.size();
40 }
41
42 public String getPath()
43 {
44 List<String> currentPathList = list.subList( 0, currentPosition );
45 StringBuilder sb = new StringBuilder();
46 for ( String path : currentPathList )
47 {
48 sb.append( path );
49 sb.append( '/' );
50 }
51 return sb.toString();
52 }
53
54 public boolean backward()
55 {
56 if ( currentPosition == 0 )
57 {
58 return false;
59 }
60 currentPosition--;
61 return true;
62 }
63
64 public boolean forward()
65 {
66 if ( currentPosition + 1 > list.size() )
67 {
68 return false;
69 }
70 currentPosition++;
71 return true;
72 }
73 }