Coverage Report - org.apache.maven.archiva.webdav.ArchivaDavLocatorFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ArchivaDavLocatorFactory
0%
0/15
0%
0/12
2.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.util.Text;
 23  
 import org.apache.jackrabbit.webdav.DavLocatorFactory;
 24  
 import org.apache.jackrabbit.webdav.DavResourceLocator;
 25  
 import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
 26  
 
 27  
 /**
 28  
  */
 29  0
 public class ArchivaDavLocatorFactory
 30  
     implements DavLocatorFactory
 31  
 {
 32  
     public DavResourceLocator createResourceLocator( String prefix, String href )
 33  
     {
 34  
         // build prefix string and remove all prefixes from the given href.
 35  0
         StringBuilder b = new StringBuilder();
 36  0
         if ( prefix != null && prefix.length() > 0 )
 37  
         {
 38  0
             b.append( prefix );
 39  0
             if ( !prefix.endsWith( "/" ) )
 40  
             {
 41  0
                 b.append( '/' );
 42  
             }
 43  0
             if ( href.startsWith( prefix ) )
 44  
             {
 45  0
                 href = href.substring( prefix.length() );
 46  
             }
 47  
         }
 48  
 
 49  
         // special treatment for root item, that has no name but '/' path.
 50  0
         if ( href == null || "".equals( href ) )
 51  
         {
 52  0
             href = "/";
 53  
         }
 54  
 
 55  0
         final String repository = RepositoryPathUtil.getRepositoryName( href );
 56  0
         return new ArchivaDavResourceLocator( b.toString(), Text.unescape( href ), repository, this );
 57  
     }
 58  
 
 59  
     public DavResourceLocator createResourceLocator( String prefix, String workspacePath, String resourcePath )
 60  
     {
 61  0
         return createResourceLocator( prefix, workspacePath, resourcePath, true );
 62  
     }
 63  
 
 64  
     public DavResourceLocator createResourceLocator( String prefix, String workspacePath, String path,
 65  
                                                      boolean isResourcePath )
 66  
     {
 67  0
         final String repository = RepositoryPathUtil.getRepositoryName( path );
 68  0
         return new ArchivaDavResourceLocator( prefix, path, repository, this );
 69  
     }
 70  
 }