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 //Remove trailing slashes otherwise Text.getRelativeParent fails
65 if (resourcePath.endsWith("/") && resourcePath.length() > 1)
67 this.resourcePath = resourcePath.substring( 0, resourcePath.length() - 1 );
70 href = hrefPrefix + escapedPath;
73 public String getRepositoryId()
78 public String getPrefix()
83 public String getResourcePath()
88 public String getWorkspacePath()
93 public String getWorkspaceName()
98 public boolean isSameWorkspace( DavResourceLocator locator )
100 return isSameWorkspace( locator.getWorkspaceName() );
103 public boolean isSameWorkspace( String workspaceName )
105 return getWorkspaceName().equals( workspaceName );
108 public String getHref( boolean isCollection )
110 // avoid doubled trailing '/' for the root item
111 String suffix = ( isCollection && !isRootLocation() ) ? "/" : "";
112 return href + suffix;
115 public boolean isRootLocation()
117 return "/".equals( resourcePath );
120 public DavLocatorFactory getFactory()
122 return davLocatorFactory;
125 public String getRepositoryPath()
127 return getResourcePath();
131 * Computes the hash code from the href, which is built using the final fields prefix and resourcePath.
133 * @return the hash code
135 public int hashCode()
137 return href.hashCode();
141 * Equality of path is achieved if the specified object is a <code>DavResourceLocator</code> object with the same
144 * @param obj the object to compare to
145 * @return <code>true</code> if the 2 objects are equal; <code>false</code> otherwise
147 public boolean equals( Object obj )
149 if ( obj instanceof DavResourceLocator )
151 DavResourceLocator other = (DavResourceLocator) obj;
152 return hashCode() == other.hashCode();