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;
47 // remove trailing '/' that is not part of the resourcePath except for the root item.
48 if (resourcePath.endsWith("/") && !"/".equals(resourcePath)) {
49 resourcePath = resourcePath.substring(0, resourcePath.length()-1);
51 this.resourcePath = resourcePath;
53 href = prefix + Text.escapePath(resourcePath);
56 public String getRepositoryId()
61 public String getPrefix()
66 public String getResourcePath()
71 public String getWorkspacePath()
76 public String getWorkspaceName()
81 public boolean isSameWorkspace(DavResourceLocator locator)
83 return isSameWorkspace(locator.getWorkspaceName());
86 public boolean isSameWorkspace(String workspaceName)
88 return getWorkspaceName().equals(workspaceName);
91 public String getHref(boolean isCollection)
93 // avoid doubled trailing '/' for the root item
94 String suffix = (isCollection && !isRootLocation()) ? "/" : "";
98 public boolean isRootLocation()
100 return "/".equals(resourcePath);
103 public DavLocatorFactory getFactory()
105 return davLocatorFactory;
108 public String getRepositoryPath()
110 return getResourcePath();
114 * Computes the hash code from the href, which is built using the final
115 * fields prefix and resourcePath.
117 * @return the hash code
119 public int hashCode()
121 return href.hashCode();
125 * Equality of path is achieved if the specified object is a <code>DavResourceLocator</code>
126 * object with the same hash code.
128 * @param obj the object to compare to
129 * @return <code>true</code> if the 2 objects are equal;
130 * <code>false</code> otherwise
132 public boolean equals(Object obj)
134 if (obj instanceof DavResourceLocator)
136 DavResourceLocator other = (DavResourceLocator) obj;
137 return hashCode() == other.hashCode();