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
30 implements DavResourceLocator, RepositoryLocator
32 private String prefix;
34 private String resourcePath;
38 private String repositoryId;
40 private DavLocatorFactory davLocatorFactory;
42 public ArchivaDavResourceLocator( String prefix, String resourcePath, String repositoryId,
43 DavLocatorFactory davLocatorFactory )
46 this.repositoryId = repositoryId;
47 this.davLocatorFactory = davLocatorFactory;
48 this.resourcePath = resourcePath;
50 if (!resourcePath.startsWith("/"))
52 this.resourcePath = "/" + resourcePath;
55 String escapedPath = Text.escapePath( resourcePath );
56 String hrefPrefix = prefix;
58 // Ensure no extra slashes when href is joined
59 if ( hrefPrefix.endsWith( "/" ) && escapedPath.startsWith( "/" ) )
61 hrefPrefix = hrefPrefix.substring( 0, hrefPrefix.length() - 1 );
64 href = hrefPrefix + escapedPath;
67 public String getRepositoryId()
72 public String getPrefix()
77 public String getResourcePath()
82 public String getWorkspacePath()
87 public String getWorkspaceName()
92 public boolean isSameWorkspace( DavResourceLocator locator )
94 return isSameWorkspace( locator.getWorkspaceName() );
97 public boolean isSameWorkspace( String workspaceName )
99 return getWorkspaceName().equals( workspaceName );
102 public String getHref( boolean isCollection )
104 // avoid doubled trailing '/' for the root item
105 String suffix = ( isCollection && !isRootLocation() ) ? "/" : "";
106 return href + suffix;
109 public boolean isRootLocation()
111 return "/".equals( resourcePath );
114 public DavLocatorFactory getFactory()
116 return davLocatorFactory;
119 public String getRepositoryPath()
121 return getResourcePath();
125 * Computes the hash code from the href, which is built using the final fields prefix and resourcePath.
127 * @return the hash code
129 public int hashCode()
131 return href.hashCode();
135 * Equality of path is achieved if the specified object is a <code>DavResourceLocator</code> object with the same
138 * @param obj the object to compare to
139 * @return <code>true</code> if the 2 objects are equal; <code>false</code> otherwise
141 public boolean equals( Object obj )
143 if ( obj instanceof DavResourceLocator )
145 DavResourceLocator other = (DavResourceLocator) obj;
146 return hashCode() == other.hashCode();