1 package org.apache.continuum.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 public class ContinuumBuildAgentDavResourceLocator
27 implements DavResourceLocator
28 {
29 private final String prefix;
30
31 private final String resourcePath;
32
33 private final String href;
34
35 private final DavLocatorFactory davLocatorFactory;
36
37 private final int projectId;
38
39 public ContinuumBuildAgentDavResourceLocator( String prefix, String resourcePath,
40 DavLocatorFactory davLocatorFactory, int projectId )
41 {
42 this.prefix = prefix;
43 this.davLocatorFactory = davLocatorFactory;
44 this.projectId = projectId;
45
46 String escapedPath = Text.escapePath( resourcePath );
47 String hrefPrefix = prefix;
48
49
50 if ( hrefPrefix.endsWith( "/" ) && escapedPath.startsWith( "/" ) )
51 {
52 hrefPrefix = hrefPrefix.substring( 0, hrefPrefix.length() - 1 );
53 }
54
55 href = hrefPrefix + escapedPath;
56
57 String path = resourcePath;
58
59 if ( !resourcePath.startsWith( "/" ) )
60 {
61 path = "/" + resourcePath;
62 }
63
64
65 if ( resourcePath.endsWith( "/" ) && resourcePath.length() > 1 )
66 {
67 path = resourcePath.substring( 0, resourcePath.length() - 1 );
68 }
69
70 this.resourcePath = path;
71 }
72
73 public DavLocatorFactory getFactory()
74 {
75 return davLocatorFactory;
76 }
77
78 public String getHref( boolean isCollection )
79 {
80
81 String suffix = ( isCollection && !isRootLocation() && !href.endsWith( "/" ) ) ? "/" : "";
82 return href + suffix;
83 }
84
85 public String getPrefix()
86 {
87 return prefix;
88 }
89
90 public int getProjectId()
91 {
92 return projectId;
93 }
94
95 public String getRepositoryPath()
96 {
97 return getResourcePath();
98 }
99
100 public String getResourcePath()
101 {
102 return resourcePath;
103 }
104
105 public String getWorkspaceName()
106 {
107 return "";
108 }
109
110 public String getWorkspacePath()
111 {
112 return "";
113 }
114
115
116
117
118
119
120 public int hashCode()
121 {
122 return href.hashCode();
123 }
124
125 public boolean isRootLocation()
126 {
127 return "/".equals( resourcePath );
128 }
129
130 public boolean isSameWorkspace( DavResourceLocator locator )
131 {
132 return isSameWorkspace( locator.getWorkspaceName() );
133 }
134
135 public boolean isSameWorkspace( String workspaceName )
136 {
137 return getWorkspaceName().equals( workspaceName );
138 }
139
140
141
142
143
144
145
146
147 public boolean equals( Object obj )
148 {
149 if ( obj instanceof DavResourceLocator )
150 {
151 DavResourceLocator other = (DavResourceLocator) obj;
152 return hashCode() == other.hashCode();
153 }
154 return false;
155 }
156 }