This project has retired. For details please refer to its
Attic page.
ArchivaVirtualDavResource xref
1 package org.apache.archiva.webdav;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.archiva.repository.storage.StorageAsset;
23 import org.apache.archiva.webdav.util.IndexWriter;
24 import org.apache.archiva.webdav.util.MimeTypes;
25 import org.apache.jackrabbit.util.Text;
26 import org.apache.jackrabbit.webdav.DavException;
27 import org.apache.jackrabbit.webdav.DavResource;
28 import org.apache.jackrabbit.webdav.DavResourceFactory;
29 import org.apache.jackrabbit.webdav.DavResourceIterator;
30 import org.apache.jackrabbit.webdav.DavResourceLocator;
31 import org.apache.jackrabbit.webdav.DavSession;
32 import org.apache.jackrabbit.webdav.MultiStatusResponse;
33 import org.apache.jackrabbit.webdav.io.InputContext;
34 import org.apache.jackrabbit.webdav.io.OutputContext;
35 import org.apache.jackrabbit.webdav.lock.ActiveLock;
36 import org.apache.jackrabbit.webdav.lock.LockInfo;
37 import org.apache.jackrabbit.webdav.lock.LockManager;
38 import org.apache.jackrabbit.webdav.lock.Scope;
39 import org.apache.jackrabbit.webdav.lock.Type;
40 import org.apache.jackrabbit.webdav.property.DavProperty;
41 import org.apache.jackrabbit.webdav.property.DavPropertyName;
42 import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
43 import org.apache.jackrabbit.webdav.property.DavPropertySet;
44 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
45 import org.apache.jackrabbit.webdav.property.ResourceType;
46 import org.joda.time.DateTime;
47 import org.joda.time.format.DateTimeFormatter;
48 import org.joda.time.format.ISODateTimeFormat;
49
50 import java.util.*;
51 import java.util.stream.Collectors;
52
53
54
55
56 public class ArchivaVirtualDavResource
57 implements DavResource
58 {
59 private static final String COMPLIANCE_CLASS = "1";
60
61 private ArchivaDavResourceLocator locator;
62
63 private DavResourceFactory factory;
64
65 private String logicalResource;
66
67 private DavPropertySet properties;
68
69 private boolean propsInitialized = false;
70
71 private static final String METHODS = "OPTIONS, GET, HEAD, POST, TRACE, PROPFIND, PROPPATCH, MKCOL";
72
73 private final List<StorageAsset> localResources;
74
75 public ArchivaVirtualDavResource(List<StorageAsset> localResources, String logicalResource, MimeTypes mimeTypes,
76 ArchivaDavResourceLocator locator, DavResourceFactory factory )
77 {
78 this.localResources = localResources;
79 this.logicalResource = logicalResource;
80 this.locator = locator;
81 this.factory = factory;
82 this.properties = new DavPropertySet();
83 }
84
85 @Override
86 public void spool( OutputContext outputContext ) {
87 if ( outputContext.hasStream() )
88 {
89 List<StorageAsset> localResourceFiles = localResources.stream().filter(Objects::nonNull)
90 .filter(repoAsset -> repoAsset.exists())
91 .sorted(Comparator.comparing(o -> o.getName())).collect(Collectors.toList());
92
93 IndexWriterdexWriter.html#IndexWriter">IndexWriter writer = new IndexWriter(localResourceFiles, logicalResource );
94 writer.write( outputContext );
95 }
96 }
97
98 @Override
99 public void addLockManager( LockManager arg0 )
100 {
101
102 }
103
104 @Override
105 public void addMember( DavResource arg0, InputContext arg1 )
106 throws DavException
107 {
108
109 }
110
111 @SuppressWarnings( "unchecked" )
112 @Override
113 public MultiStatusResponse alterProperties( List arg0 )
114 throws DavException
115 {
116 return null;
117 }
118
119 public MultiStatusResponse alterProperties( DavPropertySet arg0, DavPropertyNameSet arg1 )
120 throws DavException
121 {
122 return null;
123 }
124
125 @Override
126 public void copy( DavResource arg0, boolean arg1 )
127 throws DavException
128 {
129
130 }
131
132 @Override
133 public boolean exists()
134 {
135
136 return true;
137 }
138
139 @Override
140 public ActiveLock getLock( Type arg0, Scope arg1 )
141 {
142 return null;
143 }
144
145 @Override
146 public ActiveLock[] getLocks()
147 {
148 return null;
149 }
150
151 @Override
152 public DavResourceIterator getMembers()
153 {
154 return null;
155 }
156
157 @Override
158 public String getSupportedMethods()
159 {
160 return METHODS;
161 }
162
163 @Override
164 public long getModificationTime()
165 {
166 return 0;
167 }
168
169 @Override
170 public boolean hasLock( Type arg0, Scope arg1 )
171 {
172 return false;
173 }
174
175 @Override
176 public boolean isCollection()
177 {
178 return true;
179 }
180
181 @Override
182 public boolean isLockable( Type arg0, Scope arg1 )
183 {
184 return false;
185 }
186
187 @Override
188 public ActiveLock lock( LockInfo arg0 )
189 throws DavException
190 {
191 return null;
192 }
193
194 @Override
195 public void move( DavResource arg0 )
196 throws DavException
197 {
198
199 }
200
201 @Override
202 public ActiveLock refreshLock( LockInfo arg0, String arg1 )
203 throws DavException
204 {
205 return null;
206 }
207
208 @Override
209 public void removeMember( DavResource arg0 )
210 throws DavException
211 {
212
213 }
214
215 @Override
216 public void unlock( String arg0 )
217 throws DavException
218 {
219
220 }
221
222 @Override
223 public String getComplianceClass()
224 {
225 return COMPLIANCE_CLASS;
226 }
227
228 @Override
229 public DavResourceLocator getLocator()
230 {
231 return locator;
232 }
233
234 @Override
235 public String getResourcePath()
236 {
237 return locator.getResourcePath();
238 }
239
240 @Override
241 public String getHref()
242 {
243 return locator.getHref( isCollection() );
244 }
245
246 @Override
247 public DavResourceFactory getFactory()
248 {
249 return factory;
250 }
251
252 @Override
253 public String getDisplayName()
254 {
255 String resPath = getResourcePath();
256
257 return ( resPath != null ) ? Text.getName( resPath ) : resPath;
258 }
259
260 @Override
261 public DavSession getSession()
262 {
263 return null;
264 }
265
266 @Override
267 public DavPropertyName[] getPropertyNames()
268 {
269 return getProperties().getPropertyNames();
270 }
271
272 @Override
273 public DavProperty getProperty( DavPropertyName name )
274 {
275 initProperties();
276 return properties.get( name );
277 }
278
279 @Override
280 public DavPropertySet getProperties()
281 {
282 initProperties();
283 return properties;
284 }
285
286 @Override
287 public void setProperty( DavProperty property )
288 throws DavException
289 {
290 }
291
292 @Override
293 public void removeProperty( DavPropertyName propertyName )
294 throws DavException
295 {
296 }
297
298 @Override
299 public DavResource getCollection()
300 {
301 DavResource parent = null;
302 if ( getResourcePath() != null && !getResourcePath().equals( "/" ) )
303 {
304 String parentPath = Text.getRelativeParent( getResourcePath(), 1 );
305 if ( parentPath.equals( "" ) )
306 {
307 parentPath = "/";
308 }
309 DavResourceLocator parentloc =
310 locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath );
311 try
312 {
313
314 parent = factory.createResource( parentloc, null );
315 }
316 catch ( DavException e )
317 {
318
319 }
320 }
321 return parent;
322 }
323
324
325
326
327 protected void initProperties()
328 {
329 if ( !exists() || propsInitialized )
330 {
331 return;
332 }
333
334
335 if ( getDisplayName() != null )
336 {
337 properties.add( new DefaultDavProperty<>( DavPropertyName.DISPLAYNAME, getDisplayName() ) );
338 }
339 if ( isCollection() )
340 {
341 properties.add( new ResourceType( ResourceType.COLLECTION ) );
342
343 properties.add( new DefaultDavProperty<>( DavPropertyName.ISCOLLECTION, "1" ) );
344 }
345 else
346 {
347 properties.add( new ResourceType( ResourceType.DEFAULT_RESOURCE ) );
348
349
350 properties.add( new DefaultDavProperty<>( DavPropertyName.ISCOLLECTION, "0" ) );
351 }
352
353
354 DateTime dt = new DateTime( 0 );
355 DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
356 String modifiedDate = fmt.print( dt );
357
358 properties.add( new DefaultDavProperty<>( DavPropertyName.GETLASTMODIFIED, modifiedDate ) );
359
360 properties.add( new DefaultDavProperty<>( DavPropertyName.CREATIONDATE, modifiedDate ) );
361
362 properties.add( new DefaultDavProperty<>( DavPropertyName.GETCONTENTLENGTH, 0 ) );
363
364 propsInitialized = true;
365 }
366
367 public String getLogicalResource()
368 {
369 return logicalResource;
370 }
371
372 public void setLogicalResource( String logicalResource )
373 {
374 this.logicalResource = logicalResource;
375 }
376 }