-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathSardine.java
More file actions
632 lines (567 loc) · 26.5 KB
/
Copy pathSardine.java
File metadata and controls
632 lines (567 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
package com.github.sardine;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.namespace.QName;
import com.github.sardine.report.SardineReport;
import org.w3c.dom.Element;
/**
* The main interface for Sardine operations.
*
* @author jonstevens
*/
public interface Sardine
{
/**
* Add credentials to any scope.
*
* @param username Use in authentication header credentials
* @param password Use in authentication header credentials
*/
@Deprecated
void setCredentials(String username, String password);
/**
* Add credentials to any scope.
*
* @param username Use in authentication header credentials
* @param password Use in authentication header credentials
*/
void setCredentials(String username, char[] password);
/**
* @param username Use in authentication header credentials
* @param password Use in authentication header credentials
* @param domain NTLM authentication
* @param workstation NTLM authentication
*/
@Deprecated
void setCredentials(String username, String password, String domain, String workstation);
/**
* @param username Use in authentication header credentials
* @param password Use in authentication header credentials
* @param domain NTLM authentication
* @param workstation NTLM authentication
*/
void setCredentials(String username, char[] password, String domain, String workstation);
/**
* @see #list(String)
*/
@Deprecated
List<DavResource> getResources(String url) throws IOException;
/**
* Gets a directory listing using WebDAV <code>PROPFIND</code>.
*
* @param url Path to the resource including protocol and hostname
* @return List of resources for this URI including the parent resource itself
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> list(String url) throws IOException;
/**
* Gets a directory listing using WebDAV <code>PROPFIND</code>.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single resource, 1 for directory listing,
* -1 for infinite recursion)
* @return List of resources for this URI including the parent resource itself
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> list(String url, int depth) throws IOException;
/**
* Gets a directory listing using WebDAV <code>PROPFIND</code>.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single resource, 1 for directory listing,
* -1 for infinite recursion)
* @param props Additional properties which should be requested.
* @return List of resources for this URI including the parent resource itself
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> list(String url, int depth, Set<QName> props) throws IOException;
/**
* Gets a directory listing using WebDAV <code>PROPFIND</code>.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single resource, 1 for directory listing,
* -1 for infinite recursion)
* @param allProp If allprop should be used, which can be inefficient sometimes;
* warning: no allprop does not retrieve custom props, just the basic ones
* @return List of resources for this URI including the parent resource itself
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> list(String url, int depth, boolean allProp) throws IOException;
/**
* Gets versions listing of resource.
*
* @param url Path to the resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> versionsList(String url) throws IOException;
/**
* Gets versions listing of resource.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single resource, 1 for directory listing,
* -1 for infinite recursion)
* @throws IOException I/O error or HTTP response validation failure
*
*/
List<DavResource> versionsList(String url, int depth) throws IOException;
/**
* Gets versions listing of resource.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single resource, 1 for directory listing,
* -1 for infinite recursion)
* @param props Set of properties to be requested
* @throws IOException I/O error or HTTP response validation failure
*
*/
List<DavResource> versionsList(String url, int depth, Set<QName> props) throws IOException;
/**
* Fetches a resource using WebDAV <code>PROPFIND</code>. Only the specified properties
* are retrieved.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single resource, 1 for directory listing,
* -1 for infinite recursion)
* @param props Set of properties to be requested
* @return List of resources for this URI including the parent resource itself
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> propfind(String url, int depth, Set<QName> props) throws IOException;
/**
* Runs a report on the given resource using WebDAV <code>REPORT</code>.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single resource, 1 for directory listing,
* -1 for infinite recursion)
* @param report The report to run
* @return Result of the report, packaged in a report-specific result object
* @throws IOException I/O error or HTTP response validation failure
*/
<T> T report(String url, int depth, SardineReport<T> report) throws IOException;
/**
* Perform a search of the Webdav repository.
* @param url The base resource to search from.
* @param language The language the query is formed in.
* @param query The query string to be processed by the webdav server.
* @return A list of matching resources.
* @throws IOException I/O error or HTTP response validation failure.
*/
List<DavResource> search(String url, String language, String query) throws IOException;
/**
* @see #patch(String, java.util.Map, java.util.List)
*/
@Deprecated
void setCustomProps(String url, Map<String, String> addProps, List<String> removeProps) throws IOException;
/**
* Add custom properties for a url WebDAV <code>PROPPATCH</code>.
*
* @param url Path to the resource including protocol and hostname
* @param addProps Properties to add to resource. If a property already exists then its value is replaced.
* @return The patched resources from the response
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> patch(String url, Map<QName, String> addProps) throws IOException;
/**
* Add or remove custom properties for a url using WebDAV <code>PROPPATCH</code>.
*
* @param url Path to the resource including protocol and hostname
* @param addProps Properties to add to resource. If a property already exists then its value is replaced.
* @param removeProps Properties to remove from resource. Specifying the removal of a property that does not exist is not an error.
* @return The patched resources from the response
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> patch(String url, Map<QName, String> addProps, List<QName> removeProps) throws IOException;
/**
* Add or remove custom properties for a url using WebDAV <code>PROPPATCH</code>.
*
* @param url Path to the resource including protocol and hostname
* @param addProps Properties to add to resource. If a property already exists then its value is replaced.
* @param removeProps Properties to remove from resource. Specifying the removal of a property that does not exist is not an error.
* @return The patched resources from the response
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> patch(String url, List<Element> addProps, List<QName> removeProps) throws IOException;
/**
* Add or remove custom properties for a url using WebDAV <code>PROPPATCH</code>.
*
* @param url Path to the resource including protocol and hostname
* @param addProps Properties to add to resource. If a property already exists then its value is replaced.
* @param removeProps Properties to remove from resource. Specifying the removal of a property that does not exist is not an error.
* @param headers Additional HTTP headers to add to the request
* @return The patched resources from the response
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> patch(String url, List<Element> addProps, List<QName> removeProps, Map<String, String> headers) throws IOException;
/**
* Uses HTTP <code>GET</code> to download data from a server. The stream must be closed after reading.
*
* @param url Path to the resource including protocol and hostname
* @return Data stream to read from
* @throws IOException I/O error or HTTP response validation failure
*/
InputStream get(String url) throws IOException;
/**
* Uses HTTP <code>GET</code> to download specific version of data from a server.
* The stream must be closed after reading.
*
* @param url Path to the resource including protocol and hostname
* @param version version of resource
* @return Data stream to read from
* @throws IOException I/O error or HTTP response validation failure
*/
InputStream get(String url, String version) throws IOException;
/**
* Uses HTTP <code>GET</code> to download data from a server. The stream must be closed after reading.
*
* @param url Path to the resource including protocol and hostname
* @param headers Additional HTTP headers to add to the request
* @return Data stream to read from
* @throws IOException I/O error or HTTP response validation failure
*/
InputStream get(String url, Map<String, String> headers) throws IOException;
/**
* Uses HTTP <code>PUT</code> to send data to a server. Repeatable on authentication failure.
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param data Input source
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, byte[] data) throws IOException;
/**
* Uses <code>PUT</code> to send data to a server. Not repeatable on authentication failure.
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param dataStream Input source
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, InputStream dataStream) throws IOException;
/**
* Uses <code>PUT</code> to send data to a server with a specific content type
* header. Repeatable on authentication failure.
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param data Input source
* @param contentType MIME type to add to the HTTP request header
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, byte[] data, String contentType) throws IOException;
/**
* Uses <code>PUT</code> to send data to a server with a specific content
* type header. Not repeatable on authentication failure.
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param dataStream Input source
* @param contentType MIME type to add to the HTTP request header
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, InputStream dataStream, String contentType) throws IOException;
/**
* Uses <code>PUT</code> to send data to a server with a specific content
* type header. Not repeatable on authentication failure.
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param dataStream Input source
* @param contentType MIME type to add to the HTTP request header
* @param expectContinue Enable <code>Expect: continue</code> header for <code>PUT</code> requests.
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, InputStream dataStream, String contentType, boolean expectContinue) throws IOException;
/**
* Uses <code>PUT</code> to send data to a server with a specific content
* type header. Not repeatable on authentication failure.
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param dataStream Input source
* @param contentType MIME type to add to the HTTP request header
* @param expectContinue Enable <code>Expect: continue</code> header for <code>PUT</code> requests.
* @param contentLength data size in bytes to set to Content-Length header
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, InputStream dataStream, String contentType, boolean expectContinue, long contentLength) throws IOException;
/**
* Uses <code>PUT</code> to send data to a server with specific headers. Not repeatable
* on authentication failure.
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param dataStream Input source
* @param contentType MIME type to add to the HTTP request header
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, InputStream dataStream, String contentType, Map<String, String> headers) throws IOException;
/**
* Uses <code>PUT</code> to upload file to a server with specific contentType.
* Repeatable on authentication failure.
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param localFile local file to send
* @param contentType MIME type to add to the HTTP request header
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, File localFile, String contentType) throws IOException;
/**
* Uses <code>PUT</code> to upload file to a server with specific contentType.
* Repeatable on authentication failure.
*
* @param url Path to the resource including protocol and hostname (must not point to a directory)
* @param localFile local file to send
* @param contentType MIME type to add to the HTTP request header
* @param expectContinue Enable <code>Expect: continue</code> header for <code>PUT</code> requests.
* @throws IOException I/O error or HTTP response validation failure
*/
void put(String url, File localFile, String contentType, boolean expectContinue) throws IOException;
/**
* Delete a resource using HTTP <code>DELETE</code> at the specified url
*
* @param url Path to the resource including protocol and hostname (trailing slash is mandatory for directories)
* @throws IOException I/O error or HTTP response validation failure
*/
void delete(String url) throws IOException;
/**
* Delete a resource using HTTP <code>DELETE</code> at the specified url
*
* @param url Path to the resource including protocol and hostname
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void delete(String url, Map<String, String> headers) throws IOException;
/**
* Uses WebDAV <code>MKCOL</code> to create a directory at the specified url
*
* @param url Path to the resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
void createDirectory(String url) throws IOException;
/**
* Move a url to from source to destination using WebDAV <code>MOVE</code>. Assumes overwrite.
*
* @param sourceUrl Path to the resource including protocol and hostname (trailing slash is mandatory for directories)
* @param destinationUrl Path to the resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
void move(String sourceUrl, String destinationUrl) throws IOException;
/**
* Move a url to from source to destination using WebDAV <code>MOVE</code>.
*
* @param sourceUrl Path to the resource including protocol and hostname (trailing slash is mandatory for directories)
* @param destinationUrl Path to the resource including protocol and hostname
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
* @throws IOException I/O error or HTTP response validation failure
*/
void move(String sourceUrl, String destinationUrl, boolean overwrite) throws IOException;
/**
* Move a url to from source to destination using WebDAV <code>MOVE</code>.
*
* @param sourceUrl Path to the resource including protocol and hostname
* @param destinationUrl Path to the resource including protocol and hostname
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void move(String sourceUrl, String destinationUrl, boolean overwrite, Map<String, String> headers) throws IOException;
/**
* Copy a url from source to destination using WebDAV <code>COPY</code>. Assumes overwrite.
*
* @param sourceUrl Path to the resource including protocol and hostname (trailing slash is mandatory for directories)
* @param destinationUrl Path to the resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
void copy(String sourceUrl, String destinationUrl) throws IOException;
/**
* Copy a url from source to destination using WebDAV <code>COPY</code>.
*
* @param sourceUrl Path to the resource including protocol and hostname (trailing slash is mandatory for directories)
* @param destinationUrl Path to the resource including protocol and hostname
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
* @throws IOException I/O error or HTTP response validation failure
*/
void copy(String sourceUrl, String destinationUrl, boolean overwrite) throws IOException;
/**
* Copy a url from source to destination using WebDAV <code>COPY</code>.
*
* @param sourceUrl Path to the resource including protocol and hostname
* @param destinationUrl Path to the resource including protocol and hostname
* @param overwrite {@code true} to overwrite if the destination exists, {@code false} otherwise.
* @param headers Additional HTTP headers to add to the request
* @throws IOException I/O error or HTTP response validation failure
*/
void copy(String sourceUrl, String destinationUrl, boolean overwrite, Map<String, String> headers) throws IOException;
/**
* Performs a HTTP <code>HEAD</code> request to see if a resource exists or not.
*
* @param url Path to the resource including protocol and hostname
* @return Anything outside of the 200-299 response code range returns false.
* @throws IOException I/O error or HTTP response validation failure
*/
boolean exists(String url) throws IOException;
/**
* <p>
* Put an exclusive write lock on this resource. A write lock must prevent a principal without
* the lock from successfully executing a PUT, POST, PROPPATCH, LOCK, UNLOCK, MOVE, DELETE, or MKCOL
* on the locked resource. All other current methods, GET in particular, function
* independently of the lock.
* </p>
* A WebDAV compliant server is not required to support locking in any form. If the server does support
* locking it may choose to support any combination of exclusive and shared locks for any access types.
*
* @param url Path to the resource including protocol and hostname
* @return The lock token to unlock this resource. A lock token is a type of state token, represented
* as a URI, which identifies a particular lock. A lock token is returned by every successful
* <code>LOCK</code> operation in the lockdiscovery property in the response body, and can also be found through
* lock discovery on a resource.
* @throws IOException I/O error or HTTP response validation failure
*/
String lock(String url) throws IOException;
/**
* A LOCK request with no request body is a "LOCK refresh" request. It's purpose is to restart all timers
* associated with a lock. The request MUST include an "If" header that contains the lock tokens of the
* locks to be refreshed (note there may be multiple in the case of shared locks).
*
* @param url Path to the resource including protocol and hostname
* @param token The lock token used to lock the resource
* @param file The name of the file at the end of the url
* @return The lock token to unlock this resource. A lock token is a type of state token, represented
* as a URI, which identifies a particular lock. A lock token is returned by every successful
* <code>LOCK</code> operation in the lockdiscovery property in the response body, and can also be found through
* lock discovery on a resource.
* @throws IOException I/O error or HTTP response validation failure
*/
String refreshLock(String url, String token, String file) throws IOException;
/**
* <p>
* Unlock the resource.
* </p>
* A WebDAV compliant server is not required to support locking in any form. If the server does support
* locking it may choose to support any combination of exclusive and shared locks for any access types.
*
* @param url Path to the resource including protocol and hostname
* @param token The lock token to unlock this resource.
* @throws IOException I/O error or HTTP response validation failure
* @see #lock(String)
*/
void unlock(String url, String token) throws IOException;
/**
* Put the resource under version control.
*
* @param url Path to the resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
void addToVersionControl(String url) throws IOException;
/**
* CHECKOUT request can be applied only to a checked-in version-controlled resource
* to allow modifications to the content and properties of that version-controlled resource.
*
* @param url Path to the <b>checked-in, version-controlled</b> resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
void checkout(String url) throws IOException;
/**
* CHECKIN request can be applied to a checked-out version-controlled
* resource to produce a new version whose content and properties
* are copied from the checked-out resource.
*
* @param url Path to the <b>checked-out, version-controlled</b> resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
void checkin(String url) throws IOException;
/**
* Read access control list for resource
*
* @param url Path to the resource including protocol and hostname
* @return Current ACL set on the resource
* @throws IOException I/O error or HTTP response validation failure
*/
DavAcl getAcl(String url) throws IOException;
/**
* Read quota properties for resource
*
* @param url Path to the resource including protocol and hostname
* @return Current Quota and Size Properties for resource
* @throws IOException I/O error or HTTP response validation failure
*/
DavQuota getQuota(String url) throws IOException;
/**
* Write access control list for resource
*
* @param url Path to the resource including protocol and hostname
* @param aces Access control elements
* @throws IOException I/O error or HTTP response validation failure
*/
void setAcl(String url, List<DavAce> aces) throws IOException;
/**
* List the principals that can be used to set ACLs on given url
*
* @param url Path to the resource including protocol and hostname
* @return List of principals (in the form of urls according to spec)
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavPrincipal> getPrincipals(String url) throws IOException;
/**
* The principals that are available on the server that implements this resource.
*
* @param url Path to the resource including protocol and hostname
* @return The URLs in DAV:principal-collection-set
* @throws IOException I/O error or HTTP response validation failure
*/
List<String> getPrincipalCollectionSet(String url) throws IOException;
void enableHttp2();
/**
* <p>
* Enables HTTP GZIP compression. If enabled, requests originating from Sardine
* will include "gzip" as an "Accept-Encoding" header.
* </p>
* If the server also supports gzip compression, it should serve the
* contents in compressed gzip format and include "gzip" as the
* Content-Encoding. If the content encoding is present, Sardine will
* automatically decompress the files upon reception.
*/
void enableCompression();
/**
* Disables support for HTTP compression.
*
* @see Sardine#enableCompression()
*/
void disableCompression();
/**
* Ignores cookies.
*/
void ignoreCookies();
/**
* Send a <code>Basic</code> authentication header with each request even before 401 is returned.
* Uses default ports: 80 for http and 443 for https
*
* @param hostname The hostname to enable preemptive authentication for.
*/
void enablePreemptiveAuthentication(String hostname);
/**
* Send a <code>Basic</code> authentication header with each request even before 401 is returned.
*
* @param url The hostname, protocol and port to enable preemptive authentication for.
*/
void enablePreemptiveAuthentication(URL url);
/**
* Send a <code>Basic</code> authentication header with each request even before 401 is returned.
*
* @param hostname The hostname to enable preemptive authentication for.
* @param httpPort The http port to enable preemptive authentication for. -1 for default value.
* @param httpsPort The https port to enable preemptive authentication for. -1 for default value.
*/
void enablePreemptiveAuthentication(String hostname, int httpPort, int httpsPort);
/**
* Disable preemptive authentication.
*/
void disablePreemptiveAuthentication();
/**
* Releasing any resources that might be held
* open. This is an optional method, and callers are not expected to call
* it, but can if they want to explicitly release any open resources. Once a
* client has been shutdown, it should not be used to make any more
* requests.
*/
void shutdown() throws IOException;
}