This project has retired. For details please refer to its
Attic page.
ArchivaDavResourceLocator xref
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 @Override
82 public String getRepositoryId()
83 {
84 return repositoryId;
85 }
86
87 @Override
88 public String getPrefix()
89 {
90 return prefix;
91 }
92
93 @Override
94 public String getResourcePath()
95 {
96 return resourcePath;
97 }
98
99 @Override
100 public String getWorkspacePath()
101 {
102 return "";
103 }
104
105 @Override
106 public String getWorkspaceName()
107 {
108 return "";
109 }
110
111 @Override
112 public boolean isSameWorkspace( DavResourceLocator locator )
113 {
114 return isSameWorkspace( locator.getWorkspaceName() );
115 }
116
117 @Override
118 public boolean isSameWorkspace( String workspaceName )
119 {
120 return getWorkspaceName().equals( workspaceName );
121 }
122
123 @Override
124 public String getHref( boolean isCollection )
125 {
126
127 String suffix = ( isCollection && !isRootLocation() && !href.endsWith( "/" ) ) ? "/" : "";
128 return href + suffix;
129 }
130
131 @Override
132 public boolean isRootLocation()
133 {
134 return "/".equals( resourcePath );
135 }
136
137 @Override
138 public DavLocatorFactory getFactory()
139 {
140 return davLocatorFactory;
141 }
142
143 @Override
144 public String getRepositoryPath()
145 {
146 return getResourcePath();
147 }
148
149
150
151
152
153
154 @Override
155 public int hashCode()
156 {
157 return href.hashCode();
158 }
159
160
161
162
163
164
165
166
167 @Override
168 public boolean equals( Object obj )
169 {
170 if ( obj instanceof DavResourceLocator )
171 {
172 DavResourceLocator other = (DavResourceLocator) obj;
173 return hashCode() == other.hashCode();
174 }
175 return false;
176 }
177
178 public String getOrigResourcePath()
179 {
180 return origResourcePath;
181 }
182 }