KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > lib > WebdavResource


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java,v 1.29.2.3 2004/11/30 07:05:54 masonjm Exp $
3  * $Revision: 1.29.2.3 $
4  * $Date: 2004/11/30 07:05:54 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.webdav.lib;
25
26 import java.io.ByteArrayInputStream JavaDoc;
27 import java.io.File JavaDoc;
28 import java.io.FileInputStream JavaDoc;
29 import java.io.FileOutputStream JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.net.URL JavaDoc;
33 import java.text.DateFormat JavaDoc;
34 import java.text.ParseException JavaDoc;
35 import java.text.SimpleDateFormat JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.Date JavaDoc;
38 import java.util.Enumeration JavaDoc;
39 import java.util.Hashtable JavaDoc;
40 import java.util.Locale JavaDoc;
41 import java.util.TimeZone JavaDoc;
42 import java.util.Vector JavaDoc;
43
44 import org.apache.commons.httpclient.Credentials;
45 import org.apache.commons.httpclient.HostConfiguration;
46 import org.apache.commons.httpclient.HttpClient;
47 import org.apache.commons.httpclient.HttpException;
48 import org.apache.commons.httpclient.HttpMethod;
49 import org.apache.commons.httpclient.HttpStatus;
50 import org.apache.commons.httpclient.HttpURL;
51 import org.apache.commons.httpclient.HttpsURL;
52 import org.apache.commons.httpclient.URIException;
53 import org.apache.commons.httpclient.UsernamePasswordCredentials;
54 import org.apache.commons.httpclient.methods.GetMethod;
55 import org.apache.commons.httpclient.methods.HeadMethod;
56 import org.apache.commons.httpclient.methods.PutMethod;
57 import org.apache.commons.httpclient.util.URIUtil;
58
59 import org.apache.webdav.lib.methods.*;
60 import org.apache.webdav.lib.properties.AclProperty;
61 import org.apache.webdav.lib.properties.LockDiscoveryProperty;
62 import org.apache.webdav.lib.properties.PrincipalCollectionSetProperty;
63 import org.apache.webdav.lib.properties.ResourceTypeProperty;
64 import org.apache.webdav.lib.util.DOMUtils;
65 import org.apache.webdav.lib.util.WebdavStatus;
66
67 /**
68  * The class <code>WebdavResource</code> is an abstract representation
69  * for WebDAV resource.<p>
70  *
71  * <pre>
72  * A functional comparison of WebdavResource and JDK(It's different a lot).
73  * ----------------------------------+-------------------------------------
74  * File class (JDK 1.3.x) | WebdavResource class
75  * ----------------------------------+-------------------------------------
76  * File(String) | WebdavResource(HttpURL)
77  * File(String, String) | X (need to escape)
78  * File(File, String) | WebdavResource(HttpURL, String)
79  * getName() | getName()
80  * getParent() | *see getHttpURL() and HttpURL
81  * getParentFile() | X (not yet)
82  * getPath() | getPath()
83  * isAbsolute() | X
84  * getAbsolutePath() |
85  * getAbsoluteFile() | X
86  * getCanonicalPath() |
87  * getCanonicalFile() | X
88  * toURL() | *see HttpURL
89  * canRead() |
90  * !canWrite() | !isLocked()
91  * exists() | exists()
92  * isDirectory() | isCollection()
93  * isFile() | !isCollection()
94  * isHidden() | getIsHidden()
95  * lastModified() | getGetLastModified()
96  * length() | getGetContentLength()
97  * createNewFile() | putMethod(String)
98  * delete() | deleteMethod()
99  * deleteOnExit() | X
100  * list() | list()
101  * list(FilenameFilter) | X
102  * listFiles() | listWebdavResources()
103  * listFiles(FilenameFilter) | X
104  * listFiles(FileFilter) | X
105  * mkdir() | mkcolMethod()
106  * mkdirs() | mkcolMethod()
107  * renameTo(File) | moveMethod(String)
108  * setLastModified() | X
109  * setReadOnly() | setOverwrite(boolean)
110  * listRoots() | *see WebdavSession
111  * generateFile() |
112  * createTempFile(...) | setGetTempDir(String)
113  * compareTo(Object) | compareTo(Object)
114  * equals(Object) | equals(Object)
115  * hashCode() | X
116  * ----------------------------------+-------------------------------------
117  * URL class (JDK 1.3.x) | Webdavresource and HttpURL classes
118  * ----------------------------------+-------------------------------------
119  * getQuery() | getQuery()
120  * getPath() | getPath()
121  * getUserInfo() | getUserInfo()
122  * getAuthority() | getAuthority()
123  * getPort() | getPort()
124  * getProtocol() | getScheme()
125  * getHost() | getHost()
126  * getFile() | getPath()
127  * getRef() | getFragmenet()
128  * hashCode() | X
129  * sameFile() |
130  * toExternalForm() | toExternalForm()
131  * openConnection() |
132  * openStream() |
133  * getContent() | getMethodDataAsString()
134  * ----------------------------------+-------------------------------------
135  * URLConnection class (JDK 1.3.x) | HttpClient Library and more
136  * ----------------------------------+-------------------------------------
137  * getFileNameMap() | X
138  * setFileNameMap() | X
139  * connect() |
140  * getURL() | HttpURL#getURL()
141  * getContenetLength()() |
142  * getContentType() |
143  * getContentEncoding() |
144  * getExpiration() |
145  * getDate() |
146  * getLastModified() |
147  * getHeaderField() |
148  * getHeaderFieldInt() | X
149  * getHeaderFielDate() | X
150  * getHeaderFieldKey() | X
151  * getHeaderFiled(int) | X
152  * getContenet() |
153  * getInputStream() | WebdavResource#getMethodData()
154  * getOutputStream() | WebdavResource#putMethod(...)
155  * setDoInput() | X
156  * getDoInput() | X
157  * setAllowUserInteraction() | *see WebdavException and WebdavStatus
158  * getAllowUserInteraction() | *see WebdavException and WebdavStatus
159  * setUseCaches() |
160  * getUseCaches() |
161  * getIfModifiedSince() | X
162  * setIfModifiedSince(boolean) | X
163  * setRequestProperty(...) | X
164  * getRequestProperty(...) | X
165  * guessContentTypeFromStream(...) | X
166  * ----------------------------------+-------------------------------------
167  * </pre>
168  *
169  */

170 public class WebdavResource extends WebdavSession {
171
172
173     // ------------------------------------------------------- Constructors
174

175     /**
176      * The default constructor.
177      */

178     protected WebdavResource() {
179     }
180
181
182     /**
183      * The constructor.
184      */

185     protected WebdavResource(HttpClient client) {
186         super();
187         this.client = client;
188     }
189
190     /**
191      * The constructor.
192      *
193      * @param httpURL The specified http URL.
194      * @param credentials The credentials to use for authentication.
195      * @param action The action to set properties of this resource.
196      * @param depth The depth to find properties.
197      * @exception HttpException
198      * @exception IOException
199      * @see #setDefaultAction(int)
200      */

201     public WebdavResource(HttpURL httpURL, Credentials credentials, int action,
202                           int depth)
203         throws HttpException, IOException JavaDoc {
204
205         setCredentials(credentials);
206         setHttpURL(httpURL, action, depth);
207     }
208
209
210     /**
211      * The constructor.
212      *
213      * @param httpURL The specified http URL.
214      * @param action The action to set properties of this resource.
215      * @param depth The depth to find properties.
216      * @exception HttpException
217      * @exception IOException
218      * @see #setDefaultAction(int)
219      */

220     public WebdavResource(HttpURL httpURL, int action, int depth)
221         throws HttpException, IOException JavaDoc {
222
223         setHttpURL(httpURL, action, depth);
224     }
225
226     /**
227      * The constructor.
228      *
229      * @param httpURL The specified http URL.
230      * @param action The action to set properties of this resource.
231      * @param depth The depth to find properties.
232      * @param followRedirects shall redirects from the server be accepted
233      * @exception HttpException
234      * @exception IOException
235      * @see #setDefaultAction(int)
236      */

237     public WebdavResource(HttpURL httpURL, int action, int depth,
238              boolean followRedirects)
239        throws HttpException, IOException JavaDoc {
240        
241        setFollowRedirects(this.followRedirects);
242        setHttpURL(httpURL, action, depth);
243     }
244
245
246     /**
247      * The constructor.
248      *
249      * @param httpURL The specified http URL.
250      * @param depth The depth to find properties.
251      * @exception HttpException
252      * @exception IOException
253      * @see #setDefaultAction(int)
254      */

255     public WebdavResource(HttpURL httpURL, int depth)
256         throws HttpException, IOException JavaDoc {
257
258         setHttpURL(httpURL, defaultAction, depth);
259
260     }
261     /**
262      * The constructor.
263      *
264      * @param httpURL The specified http URL.
265      * @param depth The depth to find properties.
266      * @param followRedirects Shall redirects be followed automatically.
267      * @exception HttpException
268      * @exception IOException
269      * @see #setDefaultAction(int)
270      */

271     public WebdavResource(HttpURL httpURL, int depth, boolean followRedirects)
272        throws HttpException, IOException JavaDoc {
273        
274        setFollowRedirects(followRedirects);
275        setHttpURL(httpURL, defaultAction, depth);
276     }
277
278
279     /**
280      * The constructor.
281      *
282      * @param httpURL The specified http URL.
283      * @exception HttpException
284      * @exception IOException
285      * @see #setDefaultAction(int)
286      */

287     public WebdavResource(HttpURL httpURL)
288         throws HttpException, IOException JavaDoc {
289
290         setHttpURL(httpURL);
291     }
292     /**
293      * The constructor.
294      *
295      * @param httpURL The specified http URL.
296      * @param followRedirects shall redirects from the server be accepted
297      */

298     public WebdavResource(HttpURL httpURL, boolean followRedirects)
299         throws HttpException, IOException JavaDoc {
300         
301         setFollowRedirects(followRedirects);
302         setHttpURL(httpURL);
303     }
304
305
306     /**
307      * The constructor.
308      *
309      * @param httpURL The specified http URL.
310      * @param proxyHost The hostname of the proxy to use.
311      * @param proxyPort The port number of the proxy to use.
312      * @exception HttpException
313      * @exception IOException
314      * @see #setDefaultAction(int)
315      */

316     public WebdavResource(HttpURL httpURL, String JavaDoc proxyHost, int proxyPort)
317         throws HttpException, IOException JavaDoc {
318
319         setProxy(proxyHost, proxyPort);
320         setHttpURL(httpURL);
321     }
322     public WebdavResource(HttpURL httpURL, String JavaDoc proxyHost, int proxyPort, boolean followRedirects)
323        throws HttpException, IOException JavaDoc {
324        
325        setFollowRedirects(followRedirects);
326        setProxy(proxyHost, proxyPort);
327        setHttpURL(httpURL);
328     }
329
330
331     /**
332      * The constructor.
333      *
334      * @param httpURL The specified http URL.
335      * @param proxyHost The hostname of the proxy to use.
336      * @param proxyPort The port number of the proxy to use.
337      * @param proxyCredentials Credentials to use for proxy authentication.
338      * @exception HttpException
339      * @exception IOException
340      * @see #setDefaultAction(int)
341      */

342     public WebdavResource(HttpURL httpURL, String JavaDoc proxyHost, int proxyPort,
343                           Credentials proxyCredentials)
344         throws HttpException, IOException JavaDoc {
345
346         setProxy(proxyHost, proxyPort);
347         setProxyCredentials(proxyCredentials);
348         setHttpURL(httpURL);
349     }
350     
351     public WebdavResource(HttpURL httpURL, String JavaDoc proxyHost, int proxyPort,
352           Credentials proxyCredentials, boolean followRedirects)
353         throws HttpException, IOException JavaDoc {
354        
355         setFollowRedirects(followRedirects);
356         setProxy(proxyHost, proxyPort);
357         setProxyCredentials(proxyCredentials);
358         setHttpURL(httpURL);
359     }
360
361     /**
362      * The constructor.
363      * It must be put an escaped http URL as an argument.
364      *
365      * @param escapedHttpURL The escaped http URL string.
366      * @exception HttpException
367      * @exception IOException
368      * @see #setDefaultAction(int)
369      */

370     public WebdavResource(String JavaDoc escapedHttpURL)
371         throws HttpException, IOException JavaDoc {
372
373         setHttpURL(escapedHttpURL);
374     }
375     public WebdavResource(String JavaDoc escapedHttpURL, boolean followRedirects)
376        throws HttpException, IOException JavaDoc {
377        
378        setFollowRedirects(followRedirects);
379        setHttpURL(escapedHttpURL);
380     }
381
382
383     /**
384      * The constructor.
385      * It must be put an escaped http URL as an argument.
386      *
387      * @param escapedHttpURL The escaped http URL string.
388      * @param credentials The credentials used for Authentication.
389      * @exception HttpException
390      * @exception IOException
391      * @see #setDefaultAction(int)
392      */

393     public WebdavResource(String JavaDoc escapedHttpURL, Credentials credentials)
394         throws HttpException, IOException JavaDoc {
395
396         setCredentials(credentials);
397         setHttpURL(escapedHttpURL);
398     }
399     
400     public WebdavResource(String JavaDoc escapedHttpURL, Credentials credentials,
401           boolean followRedirects)
402        throws HttpException, IOException JavaDoc {
403        
404        setFollowRedirects(followRedirects);
405        setCredentials(credentials);
406        setHttpURL(escapedHttpURL);
407     }
408
409
410     /**
411      * The constructor.
412      * It must be put an escaped http URL as an argument.
413      *
414      * @param escapedHttpURL The escaped http URL string.
415      * @param proxyHost The hostname of the proxy to use.
416      * @param proxyPort The port number of the proxy to use.
417      * @exception HttpException
418      * @exception IOException
419      * @see #setDefaultAction(int)
420      */

421     public WebdavResource(String JavaDoc escapedHttpURL, String JavaDoc proxyHost,
422                           int proxyPort) throws HttpException, IOException JavaDoc {
423
424         setProxy(proxyHost, proxyPort);
425         setHttpURL(escapedHttpURL);
426     }
427
428     /**
429      * The constructor.
430      * It must be put an escaped http URL as an argument.
431      *
432      * @param escapedHttpURL The escaped http URL string.
433      * @param proxyHost The hostname of the proxy to use.
434      * @param proxyPort The port number of the proxy to use.
435      * @param proxyCredentials Credentials to use for proxy authentication.
436      * @exception HttpException
437      * @exception IOException
438      * @see #setDefaultAction(int)
439      */

440     public WebdavResource(String JavaDoc escapedHttpURL, String JavaDoc proxyHost,
441                           int proxyPort, Credentials proxyCredentials)
442         throws HttpException, IOException JavaDoc {
443
444         setProxy(proxyHost, proxyPort);
445         setProxyCredentials(proxyCredentials);
446         setHttpURL(escapedHttpURL);
447     }
448
449
450     /**
451      * The constructor.
452      *
453      * @param httpURL The http URL.
454      * @param additionalPath The added relative path.
455      * @exception HttpException
456      * @exception IOException
457      * @see #setDefaultAction(int)
458      */

459     public WebdavResource(HttpURL httpURL, String JavaDoc additionalPath)
460         throws HttpException, IOException JavaDoc {
461
462         setHttpURL(httpURL, additionalPath);
463     }
464
465     /**
466      * The constructor.
467      *
468      * @param httpURL The http URL.
469      * @param additionalPath The added relative path.
470      * @param followRedirects shall redirects be accepted
471      */

472     public WebdavResource(HttpURL httpURL, String JavaDoc additionalPath, boolean followRedirects)
473        throws HttpException, IOException JavaDoc {
474    
475        setFollowRedirects(followRedirects);
476        setHttpURL(httpURL, additionalPath);
477     }
478
479
480     // -------------------------------------- Constants for WebDAV properties.
481

482
483     /**
484      * The displayname property.
485      */

486     public static final String JavaDoc DISPLAYNAME = "displayname";
487
488
489     /**
490      * The getcontentlanguage property.
491      */

492     public static final String JavaDoc GETCONTENTLANGUAGE = "getcontentlanguage";
493
494
495     /**
496      * The getcontentlength property.
497      */

498     public static final String JavaDoc GETCONTENTLENGTH = "getcontentlength";
499
500
501     /**
502      * The getlastmodifed property.
503      */

504     public static final String JavaDoc GETLASTMODIFIED = "getlastmodified";
505
506
507     /**
508      * The creationdate property.
509      */

510     public static final String JavaDoc CREATIONDATE = "creationdate";
511
512
513     /**
514      * The resourcetype property.
515      */

516     public static final String JavaDoc RESOURCETYPE = "resourcetype";
517
518
519     /**
520      * The source property.
521      */

522     public static final String JavaDoc SOURCE = "source";
523
524
525     /**
526      * The getcontenttype property.
527      */

528     public static final String JavaDoc GETCONTENTTYPE = "getcontenttype";
529
530
531     /**
532      * The getetag property.
533      */

534     public static final String JavaDoc GETETAG = "getetag";
535
536
537     /**
538      * The ishidden property.
539      */

540     public static final String JavaDoc ISHIDDEN = "ishidden";
541
542
543     /**
544      * The iscollection property.
545      */

546     public static final String JavaDoc ISCOLLECTION = "iscollection";
547
548
549     /**
550      * The supportedlock property.
551      */

552     public static final String JavaDoc SUPPORTEDLOCK = "supportedlock";
553
554
555     /**
556      * The lockdiscovery property.
557      */

558     public static final String JavaDoc LOCKDISCOVERY = "lockdiscovery";
559
560
561     // ------------------------------------------------------------ Constants
562

563
564     /**
565      * No action to find properties for this resource.
566      */

567     public static final int NOACTION = 1;
568
569
570     /**
571      * The action setting only the displayname for this resource.
572      */

573     public static final int NAME = 2;
574
575
576     /**
577      * The action setting the basic properties for this resource.
578      */

579     public static final int BASIC = 3;
580
581
582     /**
583      * The action setting the default DAV properties for this resource.
584      */

585     public static final int DEFAULT = 4;
586
587
588     /**
589      * The action setting the all properties for this resource.
590      */

591     public static final int ALL = 5;
592
593
594     /**
595      *
596      */

597     public static final int OPTIONS_WORKSPACE = 8;
598
599     /**
600      *
601      */

602     public static final int OPTIONS_VERSION_HISTORY = 9;
603
604     public static final int LABEL_SET = 10;
605     public static final int LABEL_REMOVE = 11;
606     public static final int LABEL_ADD = 12;
607
608
609     /**
610      * Owner information for locking and unlocking.
611      */

612     public static final String JavaDoc defaultOwner = "Slide";
613
614
615     /**
616      * The true constant string.
617      */

618     public static final String JavaDoc TRUE = "1";
619
620
621     /**
622      * The false constant string.
623      */

624     public static final String JavaDoc FALSE = "0";
625
626
627     /**
628      * Date formats using for Date parsing.
629      */

630     public static final SimpleDateFormat JavaDoc formats[] = {
631         new SimpleDateFormat JavaDoc("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
632             new SimpleDateFormat JavaDoc("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US),
633             new SimpleDateFormat JavaDoc("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
634             new SimpleDateFormat JavaDoc("EEE MMMM d HH:mm:ss yyyy", Locale.US),
635             new SimpleDateFormat JavaDoc("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US),
636             new SimpleDateFormat JavaDoc("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US)
637     };
638
639
640     /**
641      * GMT timezone.
642      */

643     protected final static TimeZone JavaDoc gmtZone = TimeZone.getTimeZone("GMT");
644
645
646     static {
647         for (int i = 0; i < formats.length; i++) {
648             formats[i].setTimeZone(gmtZone);
649         }
650     }
651
652
653     // --------------------------------------------------- Instance Variables
654

655
656     /**
657      * The HttpURL to represent a WebDAV resource.
658      */

659     protected HttpURL httpURL;
660
661
662     /**
663      * Table of the hrefs gotten in a collection.
664      */

665     protected WebdavResources childResources = new WebdavResources();
666
667
668     /**
669      * The default action to find properties.
670      */

671     protected static int defaultAction = BASIC;
672
673
674     /**
675      * The default depth for WebDAV methods.
676      */

677     protected static int defaultDepth = DepthSupport.DEPTH_0;
678
679
680     /**
681      * The default temporary directory for the GET method.
682      * @deprecated The client is responsible for disk I/O.
683      */

684     protected static String JavaDoc tempDirForGet;
685
686
687     /**
688      * The flag setter to use the disk for the GET method.
689      * @deprecated The client is responsible for disk I/O.
690      */

691     protected static boolean useDiskForGet = true;
692
693
694     /**
695      * The flag to set the status code by propfind.
696      */

697     protected boolean thisResource;
698
699
700     /**
701      * The allowed HTTP methods.
702      */

703     protected Enumeration JavaDoc allowedMethods;
704
705
706     /**
707      * The capabilities of the WebDAV server.
708      */

709     protected Enumeration JavaDoc davCapabilities;
710
711
712     /**
713      * An WebdavResource flag to check its existence;
714      */

715     protected boolean exists;
716
717
718     /**
719      * An WebdavResource flag to check overwriting;
720      */

721     protected boolean overwrite;
722
723
724     /**
725      * An status code performed by HTTP methods at the most recent.
726      */

727     protected int latestStatusCode;
728
729
730     /**
731      * An status message performed by HTTP methods at the most recent.
732      */

733     protected String JavaDoc latestStatusMessage = "";
734
735
736     /**
737      * An WebDAV property, displayname.
738      */

739     protected String JavaDoc displayName = "";
740
741
742     /**
743      * An WebDAV property, getcontentlength.
744      */

745     protected long getContentLength;
746
747
748     /**
749      * An WebDAV property, getcontenttype.
750      */

751     protected String JavaDoc getContentType = "";
752
753
754     /**
755      * An WebDAV property, resourcetype.
756      */

757     protected ResourceTypeProperty resourceType;
758
759
760     /**
761      * An WebDAV property, getlastmodified.
762      */

763     protected long getLastModified;
764
765
766     /**
767      * An WebDAV property, creationdate.
768      */

769     protected long creationDate;
770
771
772     /**
773      * An WebDAV property, getetag.
774      */

775     protected String JavaDoc getEtag = "";
776
777     /**
778      * Owner information for locking and unlocking.
779      */

780     protected String JavaDoc owner = null;
781
782
783     /**
784      * An WebDAV property, ishidden.
785      */

786     protected boolean isHidden;
787
788
789     /**
790      * An WebDAV property, iscollection.
791      */

792     protected boolean isCollection;
793
794
795     /**
796      * An WebDAV property, supportedlock.
797      */

798     protected String JavaDoc supportedLock = "";
799
800
801     /**
802      * An WebDAV property, lockdiscovery.
803      */

804     protected LockDiscoveryProperty lockDiscovery;
805
806     protected boolean followRedirects = false;
807
808     // --------------------------------------------------------- Basic settings
809

810     /**
811      * Generates and adds the "Transaction" header if this method is part of
812      * an externally controlled transaction.
813      */

814     protected void generateTransactionHeader(HttpMethod method) {
815         if (client == null || method == null) return;
816
817         WebdavState state = (WebdavState) client.getState();
818         String JavaDoc txHandle = state.getTransactionHandle();
819         if (txHandle != null) {
820             method.setRequestHeader("Transaction", "<" + txHandle + ">");
821         }
822     }
823     
824     /**
825      * Generate and add the If header to the specified HTTP method.
826      */

827     protected void generateIfHeader(HttpMethod method) {
828
829         if (client == null) return;
830         if (method == null) return;
831
832         WebdavState state = (WebdavState) client.getState();
833         String JavaDoc[] lockTokens = state.getAllLocks(method.getPath());
834
835         if (lockTokens.length == 0) return;
836
837         StringBuffer JavaDoc ifHeaderValue = new StringBuffer JavaDoc();
838
839         for (int i = 0; i < lockTokens.length; i++) {
840             ifHeaderValue.append("(<").append(lockTokens[i]).append(">) ");
841         }
842
843         method.setRequestHeader("If", ifHeaderValue.toString());
844
845     }
846
847
848     /**
849      * Parse the <code>java.util.Date</code> string for HTTP-date.
850      *
851      * @return The parsed date.
852      */

853     protected Date JavaDoc parseDate(String JavaDoc dateValue) {
854         // TODO: move to the common util package related to http.
855
Date JavaDoc date = null;
856         for (int i = 0; (date == null) && (i < formats.length); i++) {
857             try {
858                 synchronized (formats[i]) {
859                     date = formats[i].parse(dateValue);
860                 }
861             } catch (ParseException JavaDoc e) {
862             }
863         }
864
865         return date;
866     }
867
868
869     /**
870      * Set only the displayname property for this resource.
871      *
872      * @param depth The depth to find properties.
873      */

874     protected void setNameProperties(int depth)
875         throws HttpException, IOException JavaDoc {
876
877         Vector JavaDoc properties = new Vector JavaDoc();
878         properties.addElement(DISPLAYNAME);
879
880         setNamedProp(depth, properties);
881     }
882
883
884     /**
885      * Sets the basic properties on a resource by indirectly issuing a PROPFIND
886      * on the resource.
887      *
888      * <p>Properties retrieved include:
889      *
890      * <ul>
891      * <li>displayname</li>
892      * <li>getcontentlength</li>
893      * <li>getcontenttype</li>
894      * <li>resourcetype</li>
895      * <li>getlastmodified</li>
896      * <li>lockdiscovery</li>
897      * </ul>
898      *
899      * @param depth The depth to find properties.
900      */

901     protected void setBasicProperties(int depth)
902         throws HttpException, IOException JavaDoc {
903
904         Vector JavaDoc properties = new Vector JavaDoc();
905         properties.addElement(DISPLAYNAME);
906         properties.addElement(GETCONTENTLENGTH);
907         properties.addElement(GETCONTENTTYPE);
908         properties.addElement(RESOURCETYPE);
909         properties.addElement(GETLASTMODIFIED);
910         properties.addElement(LOCKDISCOVERY);
911
912         setNamedProp(depth, properties);
913     }
914
915
916     /**
917      * Set the default properties on the resource by indirectly issuing a PROPFIND request
918      * for a default set of properties.
919      *
920      * <p>Properties retrieved include:
921      *
922      * <ul>
923      * <li>creationdate</li>
924      * <li>displayname</li>
925      * <li>getcontentlanguage</li>
926      * <li>getcontentlength</li>
927      * <li>getcontenttype</li>
928      * <li>getetag</li>
929      * <li>getlastmodified</li>
930      * <li>lockdiscovery</li>
931      * <li>resourcetype</li>
932      * <li>source</li>
933      * <li>supportedlock</li>
934      * </ul>
935      *
936      * @param depth The depth to find properties.
937      */

938     protected void setDefaultProperties(int depth)
939         throws HttpException, IOException JavaDoc {
940
941         Vector JavaDoc properties = new Vector JavaDoc();
942         properties.addElement(CREATIONDATE);
943         properties.addElement(DISPLAYNAME);
944         properties.addElement(GETCONTENTLANGUAGE);
945         properties.addElement(GETCONTENTLENGTH);
946         properties.addElement(GETCONTENTTYPE);
947         properties.addElement(GETETAG);
948         properties.addElement(GETLASTMODIFIED);
949         properties.addElement(LOCKDISCOVERY);
950         properties.addElement(RESOURCETYPE);
951         properties.addElement(SOURCE);
952         properties.addElement(SUPPORTEDLOCK);
953
954         setNamedProp(depth, properties);
955     }
956
957
958     /**
959      * Set the named properties for this resource.
960      *
961      * @param depth The depth.
962      * @param propertyNames The property-names.
963      */

964     protected void setNamedProp(int depth, Vector JavaDoc propertyNames)
965         throws HttpException, IOException JavaDoc {
966
967         Enumeration JavaDoc responses = propfindMethod(depth, propertyNames);
968         setWebdavProperties(responses);
969     }
970
971
972     /**
973      * Set all properties for this resource.
974      *
975      * @param depth The depth
976      */

977     protected void setAllProp(int depth)
978         throws HttpException, IOException JavaDoc {
979
980         Enumeration JavaDoc responses = propfindMethod(depth);
981         setWebdavProperties(responses);
982     }
983
984
985     /**
986      * Set WebDAV properties following to the given http URL.
987      * This method is fundamental for getting information of a collection.
988      *
989      * @param responses An enumeration over {@link ResponseEntity} items, one
990      * for each resource for which information was returned via PROPFIND.
991      *
992      * @exception HttpException