1 | |
package org.apache.maven.archiva.webdav.util; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.commons.lang.StringUtils; |
23 | |
import org.apache.commons.lang.ArrayUtils; |
24 | |
|
25 | |
|
26 | |
|
27 | 0 | public class RepositoryPathUtil |
28 | |
{ |
29 | |
public static String getLogicalResource(final String href) |
30 | |
{ |
31 | 0 | String logicalResource = null; |
32 | 0 | String requestPathInfo = StringUtils.defaultString( href ); |
33 | |
|
34 | |
|
35 | 0 | requestPathInfo = removePrefix(requestPathInfo); |
36 | |
|
37 | |
|
38 | 0 | if ( requestPathInfo.startsWith( "/" ) ) |
39 | |
{ |
40 | 0 | requestPathInfo = requestPathInfo.substring( 1 ); |
41 | |
} |
42 | |
|
43 | 0 | int slash = requestPathInfo.indexOf( '/' ); |
44 | 0 | if ( slash > 0 ) |
45 | |
{ |
46 | 0 | logicalResource = requestPathInfo.substring( slash ); |
47 | |
|
48 | 0 | if (logicalResource.endsWith( "/.." ) ) |
49 | |
{ |
50 | 0 | logicalResource += "/"; |
51 | |
} |
52 | |
|
53 | 0 | if ( logicalResource != null && logicalResource.startsWith( "//" ) ) |
54 | |
{ |
55 | 0 | logicalResource = logicalResource.substring( 1 ); |
56 | |
} |
57 | |
|
58 | 0 | if ( logicalResource == null ) |
59 | |
{ |
60 | 0 | logicalResource = "/"; |
61 | |
} |
62 | |
} |
63 | |
else |
64 | |
{ |
65 | 0 | logicalResource = "/"; |
66 | |
} |
67 | 0 | return logicalResource; |
68 | |
} |
69 | |
|
70 | |
public static String getRepositoryName(final String href) |
71 | |
{ |
72 | 0 | String requestPathInfo = StringUtils.defaultString( href ); |
73 | |
|
74 | |
|
75 | 0 | requestPathInfo = removePrefix(requestPathInfo); |
76 | |
|
77 | |
|
78 | 0 | if ( requestPathInfo.startsWith( "/" ) ) |
79 | |
{ |
80 | 0 | requestPathInfo = requestPathInfo.substring( 1 ); |
81 | |
} |
82 | |
|
83 | |
|
84 | 0 | int slash = requestPathInfo.indexOf( '/' ); |
85 | 0 | if ( slash > 0 ) |
86 | |
{ |
87 | |
|
88 | 0 | return requestPathInfo.substring( 0, slash ); |
89 | |
} |
90 | 0 | return requestPathInfo; |
91 | |
} |
92 | |
|
93 | |
private static String removePrefix(final String href) |
94 | |
{ |
95 | 0 | String[] parts = StringUtils.split(href, '/'); |
96 | 0 | parts = (String[]) ArrayUtils.subarray(parts, 1, parts.length); |
97 | 0 | if (parts == null || parts.length == 0) |
98 | |
{ |
99 | 0 | return "/"; |
100 | |
} |
101 | |
|
102 | 0 | String joinedString = StringUtils.join(parts, '/'); |
103 | 0 | if( href.endsWith( "/" ) ) |
104 | |
{ |
105 | 0 | joinedString = joinedString + "/"; |
106 | |
} |
107 | |
|
108 | 0 | return joinedString; |
109 | |
} |
110 | |
} |