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;
28 public class ArchivaDavResourceLocator
29 implements DavResourceLocator, RepositoryLocator
31 private final String prefix;
33 private final String resourcePath;
35 private final String href;
37 private final String repositoryId;
39 private final DavLocatorFactory davLocatorFactory;
41 public ArchivaDavResourceLocator( String prefix, String resourcePath, String repositoryId,
42 DavLocatorFactory davLocatorFactory )
45 this.repositoryId = repositoryId;
46 this.davLocatorFactory = davLocatorFactory;
48 String path = resourcePath;
50 if (!resourcePath.startsWith("/"))
52 path = "/" + 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;
66 //Remove trailing slashes otherwise Text.getRelativeParent fails
67 if (resourcePath.endsWith("/") && resourcePath.length() > 1)
69 path = resourcePath.substring( 0, resourcePath.length() - 1 );
72 this.resourcePath = path;
75 public String getRepositoryId()
80 public String getPrefix()
85 public String getResourcePath()
90 public String getWorkspacePath()
95 public String getWorkspaceName()
100 public boolean isSameWorkspace( DavResourceLocator locator )
102 return isSameWorkspace( locator.getWorkspaceName() );
105 public boolean isSameWorkspace( String workspaceName )
107 return getWorkspaceName().equals( workspaceName );
110 public String getHref( boolean isCollection )
112 // avoid doubled trailing '/' for the root item
113 String suffix = ( isCollection && !isRootLocation() && !href.endsWith("/") ) ? "/" : "";
114 return href + suffix;
117 public boolean isRootLocation()
119 return "/".equals( resourcePath );
122 public DavLocatorFactory getFactory()
124 return davLocatorFactory;
127 public String getRepositoryPath()
129 return getResourcePath();
133 * Computes the hash code from the href, which is built using the final fields prefix and resourcePath.
135 * @return the hash code
137 public int hashCode()
139 return href.hashCode();
143 * Equality of path is achieved if the specified object is a <code>DavResourceLocator</code> object with the same
146 * @param obj the object to compare to
147 * @return <code>true</code> if the 2 objects are equal; <code>false</code> otherwise
149 public boolean equals( Object obj )
151 if ( obj instanceof DavResourceLocator )
153 DavResourceLocator other = (DavResourceLocator) obj;
154 return hashCode() == other.hashCode();