1 package org.apache.maven.archiva.webdav;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.jackrabbit.webdav.DavResourceLocator;
23 import org.apache.jackrabbit.webdav.DavLocatorFactory;
24 import org.apache.jackrabbit.util.Text;
27 * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
29 public class ArchivaDavResourceLocator implements DavResourceLocator, RepositoryLocator
31 private String prefix;
33 private String resourcePath;
37 private String repositoryId;
39 private DavLocatorFactory davLocatorFactory;
41 public ArchivaDavResourceLocator(String prefix, String resourcePath, String repositoryId, DavLocatorFactory davLocatorFactory)
44 this.repositoryId = repositoryId;
45 this.davLocatorFactory = davLocatorFactory;
46 this.resourcePath = resourcePath;
48 String escapedPath = Text.escapePath(resourcePath);
49 String hrefPrefix = prefix;
51 //Ensure no extra slashes when href is joined
52 if (hrefPrefix.endsWith("/") && escapedPath.startsWith("/"))
54 hrefPrefix = hrefPrefix.substring(0, hrefPrefix.length()-1);
57 href = hrefPrefix + escapedPath;
60 public String getRepositoryId()
65 public String getPrefix()
70 public String getResourcePath()
75 public String getWorkspacePath()
80 public String getWorkspaceName()
85 public boolean isSameWorkspace(DavResourceLocator locator)
87 return isSameWorkspace(locator.getWorkspaceName());
90 public boolean isSameWorkspace(String workspaceName)
92 return getWorkspaceName().equals(workspaceName);
95 public String getHref(boolean isCollection)
97 // avoid doubled trailing '/' for the root item
98 String suffix = (isCollection && !isRootLocation()) ? "/" : "";
102 public boolean isRootLocation()
104 return "/".equals(resourcePath);
107 public DavLocatorFactory getFactory()
109 return davLocatorFactory;
112 public String getRepositoryPath()
114 return getResourcePath();
118 * Computes the hash code from the href, which is built using the final
119 * fields prefix and resourcePath.
121 * @return the hash code
123 public int hashCode()
125 return href.hashCode();
129 * Equality of path is achieved if the specified object is a <code>DavResourceLocator</code>
130 * object with the same hash code.
132 * @param obj the object to compare to
133 * @return <code>true</code> if the 2 objects are equal;
134 * <code>false</code> otherwise
136 public boolean equals(Object obj)
138 if (obj instanceof DavResourceLocator)
140 DavResourceLocator other = (DavResourceLocator) obj;
141 return hashCode() == other.hashCode();