Coverage Report - org.apache.maven.archiva.webdav.ArchivaVirtualDavResource
 
Classes in this File Line Coverage Branch Coverage Complexity
ArchivaVirtualDavResource
0%
0/78
0%
0/22
0
 
 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 java.io.File;
 23  
 import java.io.IOException;
 24  
 import java.util.ArrayList;
 25  
 import java.util.Collections;
 26  
 import java.util.List;
 27  
 
 28  
 import org.apache.jackrabbit.util.Text;
 29  
 import org.apache.jackrabbit.webdav.DavException;
 30  
 import org.apache.jackrabbit.webdav.DavResource;
 31  
 import org.apache.jackrabbit.webdav.DavResourceFactory;
 32  
 import org.apache.jackrabbit.webdav.DavResourceIterator;
 33  
 import org.apache.jackrabbit.webdav.DavResourceLocator;
 34  
 import org.apache.jackrabbit.webdav.DavSession;
 35  
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
 36  
 import org.apache.jackrabbit.webdav.io.InputContext;
 37  
 import org.apache.jackrabbit.webdav.io.OutputContext;
 38  
 import org.apache.jackrabbit.webdav.lock.ActiveLock;
 39  
 import org.apache.jackrabbit.webdav.lock.LockInfo;
 40  
 import org.apache.jackrabbit.webdav.lock.LockManager;
 41  
 import org.apache.jackrabbit.webdav.lock.Scope;
 42  
 import org.apache.jackrabbit.webdav.lock.Type;
 43  
 import org.apache.jackrabbit.webdav.property.DavProperty;
 44  
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
 45  
 import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
 46  
 import org.apache.jackrabbit.webdav.property.DavPropertySet;
 47  
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 48  
 import org.apache.jackrabbit.webdav.property.ResourceType;
 49  
 import org.apache.maven.archiva.webdav.util.IndexWriter;
 50  
 import org.apache.maven.archiva.webdav.util.MimeTypes;
 51  
 import org.joda.time.DateTime;
 52  
 import org.joda.time.format.DateTimeFormatter;
 53  
 import org.joda.time.format.ISODateTimeFormat;
 54  
 
 55  
 /**
 56  
  * DavResource for virtual repositories
 57  
  * 
 58  
  */
 59  
 public class ArchivaVirtualDavResource
 60  
     implements DavResource
 61  
 {
 62  
     private static final String COMPLIANCE_CLASS = "1";
 63  
 
 64  
     private ArchivaDavResourceLocator locator;
 65  
 
 66  
     private DavResourceFactory factory;
 67  
 
 68  
     private String logicalResource;
 69  
 
 70  
     private DavPropertySet properties;
 71  
 
 72  0
     private boolean propsInitialized = false;  
 73  
 
 74  
     private static final String METHODS = "OPTIONS, GET, HEAD, POST, TRACE, PROPFIND, PROPPATCH, MKCOL";
 75  
     
 76  
     private final List<File> localResources;
 77  
     
 78  
     public ArchivaVirtualDavResource( List<File> localResources, String logicalResource, MimeTypes mimeTypes,
 79  
                                       ArchivaDavResourceLocator locator, DavResourceFactory factory )
 80  0
     {
 81  0
         this.localResources = localResources;
 82  0
         this.logicalResource = logicalResource;
 83  0
         this.locator = locator;
 84  0
         this.factory = factory;
 85  0
         this.properties = new DavPropertySet();
 86  0
     }
 87  
 
 88  
     public void spool( OutputContext outputContext )
 89  
         throws IOException
 90  
     {
 91  0
         if (outputContext.hasStream())
 92  
         {
 93  0
             Collections.sort( localResources );
 94  0
             List<File> localResourceFiles = new ArrayList<File>();
 95  
 
 96  0
             for ( File resourceFile : localResources )
 97  
             {
 98  0
                 if ( resourceFile.exists() )
 99  
                 {
 100  0
                     localResourceFiles.add( resourceFile );
 101  
                 }
 102  
             }
 103  
 
 104  0
             IndexWriter writer = new IndexWriter( this, localResourceFiles, logicalResource );
 105  0
             writer.write( outputContext );
 106  
         }
 107  0
     }
 108  
 
 109  
     public void addLockManager( LockManager arg0 )
 110  
     {
 111  
         
 112  0
     }
 113  
 
 114  
     public void addMember( DavResource arg0, InputContext arg1 )
 115  
         throws DavException
 116  
     {
 117  
         
 118  0
     }
 119  
 
 120  
     @SuppressWarnings("unchecked")
 121  
     public MultiStatusResponse alterProperties( List arg0 )
 122  
         throws DavException
 123  
     {       
 124  0
         return null;
 125  
     }
 126  
 
 127  
     public MultiStatusResponse alterProperties( DavPropertySet arg0, DavPropertyNameSet arg1 )
 128  
         throws DavException
 129  
     {        
 130  0
         return null;
 131  
     }
 132  
 
 133  
     public void copy( DavResource arg0, boolean arg1 )
 134  
         throws DavException
 135  
     {        
 136  
 
 137  0
     }
 138  
 
 139  
     public boolean exists()
 140  
     {
 141  
         // localResources are already filtered (all files in the list are already existing)
 142  0
         return true;
 143  
     }
 144  
 
 145  
     public ActiveLock getLock( Type arg0, Scope arg1 )
 146  
     {       
 147  0
         return null;
 148  
     }
 149  
 
 150  
     public ActiveLock[] getLocks()
 151  
     {        
 152  0
         return null;
 153  
     }
 154  
 
 155  
     public DavResourceIterator getMembers()
 156  
     {
 157  0
         return null;
 158  
     }
 159  
     
 160  
     public String getSupportedMethods()
 161  
     {
 162  0
         return METHODS;
 163  
     }
 164  
 
 165  
     public long getModificationTime()
 166  
     {
 167  0
         return 0;
 168  
     }
 169  
 
 170  
     public boolean hasLock( Type arg0, Scope arg1 )
 171  
     {       
 172  0
         return false;
 173  
     }
 174  
 
 175  
     public boolean isCollection()
 176  
     {
 177  0
         return true;
 178  
     }
 179  
 
 180  
     public boolean isLockable( Type arg0, Scope arg1 )
 181  
     {        
 182  0
         return false;
 183  
     }
 184  
 
 185  
     public ActiveLock lock( LockInfo arg0 )
 186  
         throws DavException
 187  
     {
 188  0
         return null;
 189  
     }
 190  
 
 191  
     public void move( DavResource arg0 )
 192  
         throws DavException
 193  
     {
 194  
      
 195  0
     }
 196  
 
 197  
     public ActiveLock refreshLock( LockInfo arg0, String arg1 )
 198  
         throws DavException
 199  
     {        
 200  0
         return null;
 201  
     }
 202  
 
 203  
     public void removeMember( DavResource arg0 )
 204  
         throws DavException
 205  
     {
 206  
         
 207  0
     }
 208  
 
 209  
     public void unlock( String arg0 )
 210  
         throws DavException
 211  
     {
 212  
         
 213  0
     }
 214  
 
 215  
     public String getComplianceClass()
 216  
     {
 217  0
         return COMPLIANCE_CLASS;
 218  
     }   
 219  
 
 220  
     public DavResourceLocator getLocator()
 221  
     {
 222  0
         return locator;
 223  
     }
 224  
 
 225  
     public String getResourcePath()
 226  
     {
 227  0
         return locator.getResourcePath();
 228  
     }
 229  
 
 230  
     public String getHref()
 231  
     {
 232  0
         return locator.getHref( isCollection() );
 233  
     }
 234  
     
 235  
     public DavResourceFactory getFactory()
 236  
     {
 237  0
         return factory;
 238  
     }
 239  
 
 240  
     public String getDisplayName()
 241  
     {
 242  0
         String resPath = getResourcePath();
 243  
         
 244  0
         return ( resPath != null ) ? Text.getName( resPath ) : resPath;
 245  
     }
 246  
     
 247  
     public DavSession getSession()
 248  
     {        
 249  0
         return null;
 250  
     }
 251  
 
 252  
     public DavPropertyName[] getPropertyNames()
 253  
     {
 254  0
         return getProperties().getPropertyNames();
 255  
     }
 256  
 
 257  
     public DavProperty getProperty( DavPropertyName name )
 258  
     {
 259  0
         initProperties();
 260  0
         return properties.get( name );
 261  
     }
 262  
 
 263  
     public DavPropertySet getProperties()
 264  
     {
 265  0
         initProperties();
 266  0
         return properties;
 267  
     }
 268  
 
 269  
     public void setProperty( DavProperty property )
 270  
         throws DavException
 271  
     {
 272  0
     }
 273  
 
 274  
     public void removeProperty( DavPropertyName propertyName )
 275  
         throws DavException
 276  
     {
 277  0
     }
 278  
 
 279  
     public DavResource getCollection()
 280  
     {   
 281  0
         DavResource parent = null;
 282  0
         if ( getResourcePath() != null && !getResourcePath().equals( "/" ) )
 283  
         {
 284  0
             String parentPath = Text.getRelativeParent( getResourcePath(), 1 );
 285  0
             if ( parentPath.equals( "" ) )
 286  
             {
 287  0
                 parentPath = "/";
 288  
             }
 289  0
             DavResourceLocator parentloc = locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath );
 290  
             try
 291  
             {
 292  
                 // go back to ArchivaDavResourceFactory!
 293  0
                 parent = factory.createResource( parentloc, null );
 294  
             }
 295  0
             catch ( DavException e )
 296  
             {
 297  
                 // should not occur
 298  0
             }
 299  
         }
 300  0
         return parent;
 301  
     }
 302  
     
 303  
     /**
 304  
      * Fill the set of properties
 305  
      */
 306  
     protected void initProperties()
 307  
     {
 308  0
         if ( !exists() || propsInitialized )
 309  
         {
 310  0
             return;
 311  
         }
 312  
 
 313  
         // set (or reset) fundamental properties
 314  0
         if ( getDisplayName() != null )
 315  
         {
 316  0
             properties.add( new DefaultDavProperty( DavPropertyName.DISPLAYNAME, getDisplayName() ) );
 317  
         }
 318  0
         if ( isCollection() )
 319  
         {
 320  0
             properties.add( new ResourceType( ResourceType.COLLECTION ) );
 321  
             // Windows XP support
 322  0
             properties.add( new DefaultDavProperty( DavPropertyName.ISCOLLECTION, "1" ) );
 323  
         }
 324  
         else
 325  
         {
 326  0
             properties.add( new ResourceType( ResourceType.DEFAULT_RESOURCE ) );
 327  
 
 328  
             // Windows XP support
 329  0
             properties.add( new DefaultDavProperty( DavPropertyName.ISCOLLECTION, "0" ) );
 330  
         }
 331  
        
 332  
         // Need to get the ISO8601 date for properties
 333  0
         DateTime dt = new DateTime( 0 );
 334  0
         DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
 335  0
         String modifiedDate = fmt.print( dt );
 336  
 
 337  0
         properties.add( new DefaultDavProperty( DavPropertyName.GETLASTMODIFIED, modifiedDate ) );
 338  
 
 339  0
         properties.add( new DefaultDavProperty( DavPropertyName.CREATIONDATE, modifiedDate ) );
 340  
 
 341  0
         properties.add( new DefaultDavProperty( DavPropertyName.GETCONTENTLENGTH, 0 ) );
 342  
 
 343  0
         propsInitialized = true;
 344  0
     }
 345  
 
 346  
 }