Coverage Report - org.apache.maven.archiva.webdav.ArchivaDavResourceLocator
 
Classes in this File Line Coverage Branch Coverage Complexity
ArchivaDavResourceLocator
0%
0/35
0%
0/20
1.333
 
 1  
 package org.apache.maven.archiva.webdav;
 2  
 
 3  
 /*
 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
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 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
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.jackrabbit.webdav.DavResourceLocator;
 23  
 import org.apache.jackrabbit.webdav.DavLocatorFactory;
 24  
 import org.apache.jackrabbit.util.Text;
 25  
 
 26  
 /**
 27  
  */
 28  
 public class ArchivaDavResourceLocator
 29  
     implements DavResourceLocator, RepositoryLocator
 30  
 {
 31  
     private final String prefix;
 32  
 
 33  
     private final String resourcePath;
 34  
 
 35  
     private final String href;
 36  
 
 37  
     private final String repositoryId;
 38  
 
 39  
     private final DavLocatorFactory davLocatorFactory;
 40  
     
 41  
     // retains the trailing '/' at the end of the path, which is used to determine if it is a
 42  
     //      virtual repo browse request
 43  
     private final String origResourcePath;
 44  
 
 45  
     public ArchivaDavResourceLocator( String prefix, String resourcePath, String repositoryId,
 46  
                                       DavLocatorFactory davLocatorFactory )
 47  0
     {
 48  0
         this.prefix = prefix;
 49  0
         this.repositoryId = repositoryId;
 50  0
         this.davLocatorFactory = davLocatorFactory;
 51  
         
 52  0
         String path = resourcePath;
 53  
         
 54  0
         if (!resourcePath.startsWith("/"))
 55  
         {
 56  0
             path = "/" + resourcePath;
 57  
         }
 58  
 
 59  0
         String escapedPath = Text.escapePath( resourcePath );
 60  0
         String hrefPrefix = prefix;
 61  
 
 62  
         // Ensure no extra slashes when href is joined
 63  0
         if ( hrefPrefix.endsWith( "/" ) && escapedPath.startsWith( "/" ) )
 64  
         {
 65  0
             hrefPrefix = hrefPrefix.substring( 0, hrefPrefix.length() - 1 );
 66  
         }
 67  
 
 68  0
         href = hrefPrefix + escapedPath;
 69  
         
 70  0
         this.origResourcePath = path;
 71  
         
 72  
         //Remove trailing slashes otherwise Text.getRelativeParent fails
 73  0
         if ( resourcePath.endsWith( "/" ) && resourcePath.length() > 1 )
 74  
         {
 75  0
             path = resourcePath.substring( 0, resourcePath.length() - 1 );
 76  
         }
 77  
         
 78  0
         this.resourcePath = path;
 79  0
     }
 80  
 
 81  
     public String getRepositoryId()
 82  
     {
 83  0
         return repositoryId;
 84  
     }
 85  
 
 86  
     public String getPrefix()
 87  
     {
 88  0
         return prefix;
 89  
     }
 90  
 
 91  
     public String getResourcePath()
 92  
     {
 93  0
         return resourcePath;
 94  
     }
 95  
 
 96  
     public String getWorkspacePath()
 97  
     {
 98  0
         return "";
 99  
     }
 100  
 
 101  
     public String getWorkspaceName()
 102  
     {
 103  0
         return "";
 104  
     }
 105  
 
 106  
     public boolean isSameWorkspace( DavResourceLocator locator )
 107  
     {
 108  0
         return isSameWorkspace( locator.getWorkspaceName() );
 109  
     }
 110  
 
 111  
     public boolean isSameWorkspace( String workspaceName )
 112  
     {
 113  0
         return getWorkspaceName().equals( workspaceName );
 114  
     }
 115  
 
 116  
     public String getHref( boolean isCollection )
 117  
     {
 118  
         // avoid doubled trailing '/' for the root item
 119  0
         String suffix = ( isCollection && !isRootLocation() && !href.endsWith("/") ) ? "/" : "";
 120  0
         return href + suffix;
 121  
     }
 122  
 
 123  
     public boolean isRootLocation()
 124  
     {
 125  0
         return "/".equals( resourcePath );
 126  
     }
 127  
 
 128  
     public DavLocatorFactory getFactory()
 129  
     {
 130  0
         return davLocatorFactory;
 131  
     }
 132  
 
 133  
     public String getRepositoryPath()
 134  
     {
 135  0
         return getResourcePath();
 136  
     }
 137  
 
 138  
     /**
 139  
      * Computes the hash code from the href, which is built using the final fields prefix and resourcePath.
 140  
      * 
 141  
      * @return the hash code
 142  
      */
 143  
     public int hashCode()
 144  
     {
 145  0
         return href.hashCode();
 146  
     }
 147  
 
 148  
     /**
 149  
      * Equality of path is achieved if the specified object is a <code>DavResourceLocator</code> object with the same
 150  
      * hash code.
 151  
      * 
 152  
      * @param obj the object to compare to
 153  
      * @return <code>true</code> if the 2 objects are equal; <code>false</code> otherwise
 154  
      */
 155  
     public boolean equals( Object obj )
 156  
     {
 157  0
         if ( obj instanceof DavResourceLocator )
 158  
         {
 159  0
             DavResourceLocator other = (DavResourceLocator) obj;
 160  0
             return hashCode() == other.hashCode();
 161  
         }
 162  0
         return false;
 163  
     }
 164  
 
 165  
     public String getOrigResourcePath()
 166  
     {
 167  0
         return origResourcePath;
 168  
     }
 169  
 }