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
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
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;
56 * DavResource for virtual repositories
59 public class ArchivaVirtualDavResource
60 implements DavResource
62 public static final String HIDDEN_PATH_PREFIX = ".";
64 private static final String COMPLIANCE_CLASS = "1";
66 private ArchivaDavResourceLocator locator;
68 private DavResourceFactory factory;
70 private String logicalResource;
72 private DavPropertySet properties;
74 private boolean propsInitialized = false;
76 private static final String METHODS = "OPTIONS, GET, HEAD, POST, TRACE, PROPFIND, PROPPATCH, MKCOL";
78 private final List<File> localResources;
80 public ArchivaVirtualDavResource( List<File> localResources, String logicalResource, MimeTypes mimeTypes,
81 ArchivaDavResourceLocator locator, DavResourceFactory factory )
83 this.localResources = localResources;
84 this.logicalResource = logicalResource;
85 this.locator = locator;
86 this.factory = factory;
87 this.properties = new DavPropertySet();
90 public void spool( OutputContext outputContext )
93 if (outputContext.hasStream())
95 Collections.sort( localResources );
96 List<File> localResourceFiles = new ArrayList<File>();
98 for ( File resourceFile : localResources )
100 if ( resourceFile.exists() )
102 localResourceFiles.add( resourceFile );
106 IndexWriter writer = new IndexWriter( this, localResourceFiles, logicalResource );
107 writer.write( outputContext );
111 public void addLockManager( LockManager arg0 )
116 public void addMember( DavResource arg0, InputContext arg1 )
122 @SuppressWarnings("unchecked")
123 public MultiStatusResponse alterProperties( List arg0 )
129 public MultiStatusResponse alterProperties( DavPropertySet arg0, DavPropertyNameSet arg1 )
135 public void copy( DavResource arg0, boolean arg1 )
141 public boolean exists()
143 // localResources are already filtered (all files in the list are already existing)
147 public ActiveLock getLock( Type arg0, Scope arg1 )
152 public ActiveLock[] getLocks()
157 public DavResourceIterator getMembers()
162 public String getSupportedMethods()
167 public long getModificationTime()
172 public boolean hasLock( Type arg0, Scope arg1 )
177 public boolean isCollection()
182 public boolean isLockable( Type arg0, Scope arg1 )
187 public ActiveLock lock( LockInfo arg0 )
193 public void move( DavResource arg0 )
199 public ActiveLock refreshLock( LockInfo arg0, String arg1 )
205 public void removeMember( DavResource arg0 )
211 public void unlock( String arg0 )
217 public String getComplianceClass()
219 return COMPLIANCE_CLASS;
222 public DavResourceLocator getLocator()
227 public String getResourcePath()
229 return locator.getResourcePath();
232 public String getHref()
234 return locator.getHref( isCollection() );
237 public DavResourceFactory getFactory()
242 public String getDisplayName()
244 String resPath = getResourcePath();
246 return ( resPath != null ) ? Text.getName( resPath ) : resPath;
249 public DavSession getSession()
254 public DavPropertyName[] getPropertyNames()
256 return getProperties().getPropertyNames();
259 public DavProperty getProperty( DavPropertyName name )
262 return properties.get( name );
265 public DavPropertySet getProperties()
271 public void setProperty( DavProperty property )
276 public void removeProperty( DavPropertyName propertyName )
281 public DavResource getCollection()
283 DavResource parent = null;
284 if ( getResourcePath() != null && !getResourcePath().equals( "/" ) )
286 String parentPath = Text.getRelativeParent( getResourcePath(), 1 );
287 if ( parentPath.equals( "" ) )
291 DavResourceLocator parentloc = locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath );
294 // go back to ArchivaDavResourceFactory!
295 parent = factory.createResource( parentloc, null );
297 catch ( DavException e )
306 * Fill the set of properties
308 protected void initProperties()
310 if ( !exists() || propsInitialized )
315 // set (or reset) fundamental properties
316 if ( getDisplayName() != null )
318 properties.add( new DefaultDavProperty( DavPropertyName.DISPLAYNAME, getDisplayName() ) );
320 if ( isCollection() )
322 properties.add( new ResourceType( ResourceType.COLLECTION ) );
323 // Windows XP support
324 properties.add( new DefaultDavProperty( DavPropertyName.ISCOLLECTION, "1" ) );
328 properties.add( new ResourceType( ResourceType.DEFAULT_RESOURCE ) );
330 // Windows XP support
331 properties.add( new DefaultDavProperty( DavPropertyName.ISCOLLECTION, "0" ) );
334 // Need to get the ISO8601 date for properties
335 DateTime dt = new DateTime( 0 );
336 DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
337 String modifiedDate = fmt.print( dt );
339 properties.add( new DefaultDavProperty( DavPropertyName.GETLASTMODIFIED, modifiedDate ) );
341 properties.add( new DefaultDavProperty( DavPropertyName.CREATIONDATE, modifiedDate ) );
343 properties.add( new DefaultDavProperty( DavPropertyName.GETCONTENTLENGTH, 0 ) );
345 propsInitialized = true;