1 package org.apache.archiva.webdav;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.jackrabbit.util.Text;
23 import org.apache.jackrabbit.webdav.DavLocatorFactory;
24 import org.apache.jackrabbit.webdav.DavResourceLocator;
25
26
27
28 public class ArchivaDavResourceLocator
29 implements DavResourceLocator, RepositoryLocator
30 {
31 private final String prefix;
32
33 private final String resourcePath;
34
35 private final String href;
36
37 private final String repositoryId;
38
39 private final DavLocatorFactory davLocatorFactory;
40
41
42
43 private final String origResourcePath;
44
45 public ArchivaDavResourceLocator( String prefix, String resourcePath, String repositoryId,
46 DavLocatorFactory davLocatorFactory )
47 {
48 this.prefix = prefix;
49 this.repositoryId = repositoryId;
50 this.davLocatorFactory = davLocatorFactory;
51
52 String path = resourcePath;
53
54 if ( !resourcePath.startsWith( "/" ) )
55 {
56 path = "/" + resourcePath;
57 }
58
59 String escapedPath = Text.escapePath( resourcePath );
60 String hrefPrefix = prefix;
61
62
63 if ( hrefPrefix.endsWith( "/" ) && escapedPath.startsWith( "/" ) )
64 {
65 hrefPrefix = hrefPrefix.substring( 0, hrefPrefix.length() - 1 );
66 }
67
68 href = hrefPrefix + escapedPath;
69
70 this.origResourcePath = path;
71
72
73 if ( resourcePath.endsWith( "/" ) && resourcePath.length() > 1 )
74 {
75 path = resourcePath.substring( 0, resourcePath.length() - 1 );
76 }
77
78 this.resourcePath = path;
79 }
80
81 public String getRepositoryId()
82 {
83 return repositoryId;
84 }
85
86 public String getPrefix()
87 {
88 return prefix;
89 }
90
91 public String getResourcePath()
92 {
93 return resourcePath;
94 }
95
96 public String getWorkspacePath()
97 {
98 return "";
99 }
100
101 public String getWorkspaceName()
102 {
103 return "";
104 }
105
106 public boolean isSameWorkspace( DavResourceLocator locator )
107 {
108 return isSameWorkspace( locator.getWorkspaceName() );
109 }
110
111 public boolean isSameWorkspace( String workspaceName )
112 {
113 return getWorkspaceName().equals( workspaceName );
114 }
115
116 public String getHref( boolean isCollection )
117 {
118
119 String suffix = ( isCollection && !isRootLocation() && !href.endsWith( "/" ) ) ? "/" : "";
120 return href + suffix;
121 }
122
123 public boolean isRootLocation()
124 {
125 return "/".equals( resourcePath );
126 }
127
128 public DavLocatorFactory getFactory()
129 {
130 return davLocatorFactory;
131 }
132
133 public String getRepositoryPath()
134 {
135 return getResourcePath();
136 }
137
138
139
140
141
142
143 public int hashCode()
144 {
145 return href.hashCode();
146 }
147
148
149
150
151
152
153
154
155 public boolean equals( Object obj )
156 {
157 if ( obj instanceof DavResourceLocator )
158 {
159 DavResourceLocator other = (DavResourceLocator) obj;
160 return hashCode() == other.hashCode();
161 }
162 return false;
163 }
164
165 public String getOrigResourcePath()
166 {
167 return origResourcePath;
168 }
169 }