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
993      * @exception IOException The socket error with a server.
994      */

995     protected void setWebdavProperties(Enumeration JavaDoc responses)
996         throws HttpException, IOException JavaDoc {
997     
998         // Make the resources in the collection empty.
999
childResources.removeAll();
1000        while (responses.hasMoreElements()) {
1001    
1002            ResponseEntity response =
1003                (ResponseEntity) responses.nextElement();
1004    
1005            boolean itself = false;
1006            String JavaDoc href = response.getHref();
1007            if (!href.startsWith("/"))
1008                href = URIUtil.getPath(href);
1009            href = decodeMarks(href);
1010
1011            /*
1012             * Decode URIs to common (unescaped) format for comparison
1013             * as HttpClient.URI.setPath() doesn't escape $ and : chars.
1014             */

1015            String JavaDoc httpURLPath = httpURL.getPath();
1016            String JavaDoc escapedHref = URIUtil.decode(href);
1017            
1018            // Normalize them to both have trailing slashes if they differ by one in length.
1019
int lenDiff = escapedHref.length() - httpURLPath.length();
1020            int compareLen = 0;
1021            
1022            if ( lenDiff == -1 && !escapedHref.endsWith("/")) {
1023                compareLen = escapedHref.length();
1024                lenDiff = 0;
1025            }
1026            else
1027            if ( lenDiff == 1 && !httpURLPath.endsWith("/")) {
1028                compareLen = httpURLPath.length();
1029                lenDiff = 0;
1030            }
1031
1032            // if they are the same length then compare them.
1033
if (lenDiff == 0) {
1034                if ((compareLen == 0 && httpURLPath.equals(escapedHref))
1035                    || httpURLPath.regionMatches(0, escapedHref, 0, compareLen))
1036                {
1037                    // escaped href and http path are the same
1038
// Set the status code for this resource.
1039
if (response.getStatusCode() > 0)
1040                        setStatusCode(response.getStatusCode());
1041                    setExistence(true);
1042                    itself = true;
1043                }
1044            }
1045    
1046            // Get to know each resource.
1047
WebdavResource workingResource = null;
1048            if (itself) {
1049                workingResource = this;
1050            }
1051            else {
1052                workingResource = createWebdavResource(client);
1053                workingResource.setDebug(debug);
1054            }
1055    
1056            // clear the current lock set
1057
workingResource.setLockDiscovery(null);
1058    
1059            // Process the resource's properties
1060
Enumeration JavaDoc properties = response.getProperties();
1061            while (properties.hasMoreElements()) {
1062    
1063                Property property = (Property) properties.nextElement();
1064    
1065                // ------------------------------ Checking WebDAV properties
1066
workingResource.processProperty(property);
1067            }
1068    
1069            String JavaDoc displayName = workingResource.getDisplayName();
1070    
1071            if (displayName == null || displayName.trim().equals("")) {
1072                displayName = getName(href);
1073            }
1074            if (!itself) {
1075                String JavaDoc myURI = httpURL.getEscapedURI();
1076                char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/")
1077                                   + URIUtil.getName(href)).toCharArray();
1078                HttpURL childURL = httpURL instanceof HttpsURL
1079                                   ? new HttpsURL(childURI)
1080                                   : new HttpURL(childURI);
1081                childURL.setRawAuthority(httpURL.getRawAuthority());
1082                workingResource.setHttpURL(childURL, NOACTION, defaultDepth);
1083                workingResource.setExistence(true);
1084                workingResource.setOverwrite(getOverwrite());
1085            }
1086            workingResource.setDisplayName(displayName);
1087    
1088            if (!itself)
1089                childResources.addResource(workingResource);
1090        }
1091    }
1092
1093
1094    // ------------------------------------------------------------ Properties
1095

1096
1097    /**
1098     * Set the default action for this resource.
1099     * The default action is set as 'BASIC' for the first time.
1100     *
1101     * ex)
1102     * WebdavResource.NOACTION
1103     * WebdavResource.NAME
1104     * WebdavResource.BASIC
1105     * WebdavResource.DEFAULT
1106     * WebdavResource.ALL
1107     *
1108     * @param action The action type.
1109     * @see #NOACTION
1110     * @see #NAME
1111     * @see #BASIC
1112     * @see #DEFAULT
1113     * @see #ALL
1114     */

1115    public static void setDefaultAction(int action) {
1116        defaultAction = action;
1117    }
1118
1119
1120    /**
1121     * Get the default action.
1122     *
1123     * @return The action type.
1124     */

1125    public static int getDefaultAction() {
1126        return defaultAction;
1127    }
1128
1129
1130    /**
1131     * Set the default action for this resource.
1132     *
1133     * ex)
1134     * DepthSupport.DEPTH_0
1135     * DepthSupport.DEPTH_1
1136     * DepthSupport.DEPTH_INFINITY
1137     *
1138     * @param depth The depth.
1139     */

1140    public static void setDefaultDepth(int depth) {
1141        defaultDepth = depth;
1142    }
1143
1144
1145    /**
1146     * Get the default action.
1147     *
1148     * @return The depth.
1149     */

1150    public static int getDefaultDepth() {
1151        return defaultDepth;
1152    }
1153
1154
1155    /**
1156     * Get the default temporary directory for the GET method.
1157     *
1158     * @param tempDir The temporary directory.
1159     * @deprecated The given directory will not be used.
1160     */

1161    public static void setGetTempDir(String JavaDoc tempDir) {
1162        tempDirForGet = tempDir;
1163    }
1164
1165
1166    /**
1167     * Get the default temporary directory for the GET method.
1168     * The default temporary directory is "temp/".
1169     *
1170     * @return The temporary directory path.
1171     * It's set by default, if it returns null.
1172     * @deprecated The returned directory is not used by the GET method.
1173     */

1174    public static String JavaDoc getGetTempDir() {
1175        return tempDirForGet;
1176    }
1177
1178
1179
1180    /**
1181     * Set the use disk flag for the GET method.
1182     *
1183     * @param useDisk The use disk flag.
1184     * @deprecated This method has no effect.
1185     */

1186    public static void setGetUseDisk(boolean useDisk) {
1187        //useDiskForGet = useDisk;
1188
}
1189
1190
1191    /**
1192     * Get the use disk flag for the GET method.
1193     *
1194     * @return The current flag of the use disk.
1195     * By default, it's true.
1196     * @deprecated This method always returns false.
1197     */

1198    public static boolean getGetUseDisk() {
1199        return false;
1200    }
1201
1202    /**
1203     * Sets a flag indicating that redirect responses from
1204     * the server shall be followed.
1205     */

1206    public void setFollowRedirects(boolean value) {
1207       this.followRedirects = value;
1208    }
1209    /**
1210     * Returns the current "follow redirects" flag.
1211     * @see #setFollowRedirects(boolean)
1212     */

1213    public boolean getFollowRedirects() {
1214       return this.followRedirects;
1215    }
1216
1217
1218    /**
1219     * Test that the httpURL is the same with the client.
1220     *
1221     * @return true if the given httpURL is the client for this resource.
1222     */

1223    protected synchronized boolean isTheClient() throws URIException {
1224        HostConfiguration hostConfig = client.getHostConfiguration();
1225        Credentials creds =
1226            client.getState().getCredentials(null, hostConfig.getHost());
1227        String JavaDoc userName = null;
1228        String JavaDoc password = null;
1229
1230        if (creds instanceof UsernamePasswordCredentials) {
1231            UsernamePasswordCredentials upc = (UsernamePasswordCredentials) creds;
1232            userName = upc.getUserName();
1233            password = upc.getPassword();
1234        }
1235        String JavaDoc ref = httpURL.getUser();
1236        boolean userMatches = userName != null ? userName.equals(ref)
1237                                               : ref == null;
1238        if (userMatches) {
1239            ref = httpURL.getPassword();
1240            userMatches = password != null ? password.equals(ref)
1241                                           : ref == null;
1242        } else {
1243            return false;
1244        }
1245        if (userMatches) {
1246            return httpURL.getHost().equalsIgnoreCase(hostConfig.getHost())
1247                && httpURL.getPort()
1248                == hostConfig.getProtocol().resolvePort(hostConfig.getPort());
1249        }
1250        return false;
1251    }
1252
1253
1254    /**
1255     * Set the client for this resource.
1256     *
1257     * @exception IOException
1258     */

1259    protected void setClient() throws IOException JavaDoc {
1260        setClient(httpURL);
1261    }
1262
1263
1264    /**
1265     * Set the client for this resource and the given http URL.
1266     *
1267     * @param httpURL The http URL.
1268     * @exception IOException
1269     */

1270    protected synchronized void setClient(HttpURL httpURL) throws IOException JavaDoc {
1271
1272        if (client == null) {
1273            client = getSessionInstance(httpURL);
1274        } else if (!isTheClient()) {
1275            closeSession();
1276            client = getSessionInstance(httpURL);
1277        }
1278    }
1279
1280
1281    /**
1282     * Set the HttpURL for this WebdavResource.
1283     *
1284     * @param httpURL the specified HttpURL.
1285     * @param action The action to decide, which properties to find.
1286     * @param depth The depth to find properties.
1287     * @exception HttpException
1288     * @exception IOException
1289     * @see #setHttpURL(java.lang.String)
1290     * @see #setUserInfo(java.lang.String, java.lang.String)
1291     * @see #setPath(java.lang.String)
1292     * @see #setDefaultAction(int)
1293     */

1294    public void setHttpURL(HttpURL httpURL, int action, int depth)
1295        throws HttpException, IOException JavaDoc {
1296
1297        this.httpURL = httpURL;
1298        setClient(httpURL);
1299        // make its existence false
1300
setExistence(false);
1301        setProperties(action, depth);
1302    }
1303
1304
1305    /**
1306     * Set the HttpURL for this WebdavResource.
1307     *
1308     * @param httpURL the specified HttpURL.
1309     * @param depth The depth to find properties.
1310     * @exception HttpException
1311     * @exception IOException
1312     * @see #setHttpURL(java.lang.String)
1313     * @see #setUserInfo(java.lang.String, java.lang.String)
1314     * @see #setPath(java.lang.String)
1315     */

1316    public void setHttpURL(HttpURL httpURL, int depth)
1317        throws HttpException, IOException JavaDoc {
1318
1319        // Follow the default action.
1320
setHttpURL(httpURL, defaultAction, depth);
1321    }
1322
1323
1324    /**
1325     * Set the HttpURL for this WebdavResource.
1326     * It must be put an escaped path part of the http URL as an argument.
1327     *
1328     * @param httpURL The specified HttpURL.
1329     * @param additionalPath The added relative path.
1330     * @param action The action to decide, which properties to find.
1331     * @param depth The depth.
1332     * @exception HttpException
1333     * @exception IOException
1334     * @see #setHttpURL(java.lang.String)
1335     * @see #setUserInfo(java.lang.String, java.lang.String)
1336     * @see #setPath(java.lang.String)
1337     * @see #setDefaultAction(int)
1338     */

1339    public void setHttpURL
1340        (HttpURL httpURL, String JavaDoc additionalPath, int action, int depth)
1341        throws HttpException, IOException JavaDoc {
1342
1343        setHttpURL(httpURL instanceof HttpsURL
1344                   ? new HttpsURL((HttpsURL) httpURL, additionalPath)
1345                   : new HttpURL(httpURL, additionalPath), action, depth);
1346    }
1347
1348
1349    /**
1350     * Set the HttpURL for this WebdavResource.
1351     * It must be put an escaped path part of the http URL as an argument.
1352     *
1353     * @param httpURL The specified HttpURL.
1354     * @param additionalPath The added relative path.
1355     * @param action The action to decide, which properties to find.
1356     * @exception HttpException
1357     * @exception IOException
1358     * @see #setHttpURL(java.lang.String)
1359     * @see #setUserInfo(java.lang.String, java.lang.String)
1360     * @see #setPath(java.lang.String)
1361     * @see #setDefaultAction(int)
1362     */

1363    public void setHttpURL
1364        (HttpURL httpURL, String JavaDoc additionalPath, int action)
1365        throws HttpException, IOException JavaDoc {
1366
1367        setHttpURL(httpURL instanceof HttpsURL
1368                   ? new HttpsURL((HttpsURL) httpURL, additionalPath)
1369                   : new HttpURL(httpURL, additionalPath),
1370                   action, defaultDepth);
1371    }
1372
1373
1374    /**
1375     * Set the HttpURL for this WebdavResource.
1376     *
1377     * @param httpURL The specified HttpURL.
1378     * @param additionalPath The added relative path.
1379     * @exception HttpException
1380     * @exception IOException
1381     * @see #setHttpURL(java.lang.String)
1382     * @see #setUserInfo(java.lang.String, java.lang.String)
1383     * @see #setPath(java.lang.String)
1384     */

1385    public void setHttpURL(HttpURL httpURL, String JavaDoc additionalPath)
1386        throws HttpException, IOException JavaDoc {
1387
1388        setHttpURL(httpURL instanceof HttpsURL
1389                   ? new HttpsURL((HttpsURL) httpURL, additionalPath)
1390                   : new HttpURL(httpURL, additionalPath),
1391                   defaultAction, defaultDepth);
1392    }
1393
1394
1395    /**
1396     * Set the HttpURL for this WebdavResource.
1397     *
1398     * @param httpURL the specified HttpURL.
1399     * @exception HttpException
1400     * @exception IOException
1401     * @see #setHttpURL(java.lang.String)
1402     * @see #setUserInfo(java.lang.String, java.lang.String)
1403     * @see #setPath(java.lang.String)
1404     */

1405    public void setHttpURL(HttpURL httpURL)
1406        throws HttpException, IOException JavaDoc {
1407
1408        setHttpURL(httpURL, defaultDepth);
1409    }
1410
1411
1412    /**
1413     * Set the HttpURL of this WebdavResource.
1414     * It must be put an escaped http URL as an argument.
1415     *
1416     * @param escapedHttpURL The escaped http URL string.
1417     * @exception HttpException
1418     * @exception IOException
1419     * @see #setHttpURL(HttpURL)
1420     * @see #setUserInfo(java.lang.String, java.lang.String)
1421     * @see #setPath(java.lang.String)
1422     */

1423    public void setHttpURL(String JavaDoc escapedHttpURL)
1424        throws HttpException, IOException JavaDoc {
1425
1426        setHttpURL(escapedHttpURL.startsWith("https")
1427                   ? new HttpsURL(escapedHttpURL)
1428                   : new HttpURL(escapedHttpURL));
1429    }
1430
1431
1432    /**
1433     * Get the HttpURL of this WebdavResource.
1434     *
1435     * @return httpURL the http URL.
1436     */

1437    public HttpURL getHttpURL() {
1438        return httpURL;
1439    }
1440
1441
1442    /**
1443     * Get the HttpURL except for userinfo.
1444     *
1445     * @return httpURL the http URL.
1446     */

1447    public HttpURL getHttpURLExceptForUserInfo()
1448        throws URIException {
1449
1450        return httpURL instanceof HttpsURL ? new HttpsURL(httpURL.getRawURI())
1451                                           : new HttpURL(httpURL.getRawURI());
1452    }
1453
1454
1455    /**
1456     * Set the path part of this WebdavResource.
1457     *
1458     * @param path the specified path.
1459     * @exception HttpException
1460     * @exception IOException
1461     * @see #setHttpURL(HttpURL)
1462     * @see #setHttpURL(java.lang.String)
1463     * @see #setUserInfo(java.lang.String, java.lang.String)
1464     */

1465    public void setPath(String JavaDoc path)
1466        throws HttpException, IOException JavaDoc {
1467
1468        httpURL.setPath(path);
1469        setHttpURL(httpURL);
1470    }
1471
1472
1473    /**
1474     * Get the path part of this WebdavResource.
1475     * If the decoding of the path fails, this method will not throw an
1476     * exception but return the escaped path instead.
1477     *
1478     * @return the path for this WebdavResource.
1479     * @see org.apache.commons.httpclient.HttpURL#getPath()
1480     * @see #setPath(java.lang.String)
1481     */

1482    public String JavaDoc getPath() {
1483        try {
1484            return httpURL.getPath();
1485        } catch (URIException e) {
1486            return httpURL.getEscapedPath();
1487        }
1488    }
1489
1490
1491    /**
1492     * Get the name of this WebdavResource.
1493     * If the decoding of the name fails, this method will not throw an
1494     * exception but return the escaped name instead.
1495     *
1496     * @return the name of this WebdavResource.
1497     * @see org.apache.commons.httpclient.HttpURL#getName()
1498     */

1499    public String JavaDoc getName() {
1500        return getName(httpURL.getEscapedPath());
1501    }
1502
1503
1504    /**
1505     * Get the hostname of this WebdavResource.
1506     *
1507     * @return the hostname.
1508     * @exception URIException
1509     */

1510    public String JavaDoc getHost() throws URIException {
1511        return httpURL.getHost();
1512    }
1513
1514
1515    /**
1516     * Set the userinfo part of this WebdavResource.
1517     *
1518     * @exception HttpException
1519     * @exception IOException
1520     * @see #setHttpURL(HttpURL)
1521     * @see #setHttpURL(java.lang.String)
1522     * @see #setPath(java.lang.String)
1523     */

1524    public void setUserInfo(String JavaDoc userName, String JavaDoc password)
1525        throws HttpException, IOException JavaDoc {
1526
1527        httpURL.setUserinfo(userName, password);
1528        setHttpURL(httpURL);
1529    }
1530
1531
1532    // ------------------------------------------------ DAV properties checking
1533

1534
1535    /**
1536     * Get the value of DAV property, displayname.
1537     *
1538     * @return The displayname string.
1539     */

1540    public String JavaDoc getDisplayName() {
1541        return displayName;
1542    }
1543
1544
1545    /**
1546     * Set the value of DAV property, displayname.
1547     *
1548     * @param displayName The displayname string.
1549     */

1550    protected void setDisplayName(String JavaDoc displayName) {
1551        this.displayName = displayName;
1552    }
1553
1554
1555    /**
1556     * Get the value of DAV property, getcontentlength.
1557     *
1558     * @return The getcontentlength value.
1559     */

1560    public long getGetContentLength() {
1561        return getContentLength;
1562    }
1563
1564
1565    /**
1566     * Set the value of DAV property, getcontentlength.
1567     *
1568     * @param getContentLength The getcontentlength value.
1569     */

1570    protected void setGetContentLength(long getContentLength) {
1571        this.getContentLength = getContentLength;
1572    }
1573
1574
1575    /**
1576     * Set the value of DAV property, getcontentlength.
1577     *
1578     * @param getContentLength The getcontentlength value.
1579     */

1580    protected void setGetContentLength(String JavaDoc getContentLength) {
1581        try {
1582            this.getContentLength = Long.parseLong(getContentLength);
1583        } catch (NumberFormatException JavaDoc nfe) {
1584            // it's ok to ignore this error.
1585
}
1586    }
1587
1588
1589    /**
1590     * Get the value of DAV property, resourcetype.
1591     *
1592     * @return The resourcetype property.
1593     * @see #isCollection()
1594     */

1595    public ResourceTypeProperty getResourceType() {
1596        return resourceType;
1597    }
1598
1599
1600    /**
1601     * Set the value of DAV property, resourcetype.
1602     *
1603     * @param resourceType The resourcetype property.
1604     */

1605    protected void setResourceType(ResourceTypeProperty resourceType) {
1606        this.resourceType = resourceType;
1607    }
1608
1609
1610    /**
1611     * Get the value of DAV property, resourcetype
1612     *
1613     * @return The resourcetype string.
1614     * @see #getResourceType()
1615     * @see #getIsCollection()
1616     */

1617    public boolean isCollection() {
1618        if (getResourceType() == null) return false;
1619        return getResourceType().isCollection();
1620    }
1621
1622
1623    /**
1624     * Get the value of DAV property, getcontenttype.
1625     *
1626     * @return The getcontenttype string.
1627     */

1628    public String JavaDoc getGetContentType() {
1629        return getContentType;
1630    }
1631
1632
1633    /**
1634     * Set the value of DAV property, getcontenttype.
1635     *
1636     * @param getContentType The getcontenttype string.
1637     */

1638    protected void setGetContentType(String JavaDoc getContentType) {
1639        this.getContentType = getContentType;
1640    }
1641
1642    /**
1643     * Set the content-type to use for this resource, for PUTs.
1644     * @param contentType The content-type string.
1645     */

1646    public void setContentType(String JavaDoc contentType) {
1647        this.getContentType = contentType;
1648    }
1649
1650    /**
1651     * Get the value of DAV property, getlastmodified.
1652     *
1653     * @return The getlastmodified value.
1654     */

1655    public long getGetLastModified() {
1656        return getLastModified;
1657    }
1658
1659
1660    /**
1661     * Set the value of DAV property, getlastmodified.
1662     *
1663     * @param getLastModified The getlastmodified value.
1664     * @see #setGetLastModified(java.lang.String)
1665     */

1666    protected void setGetLastModified(long getLastModified) {
1667        this.getLastModified = getLastModified;
1668    }
1669
1670
1671    /**
1672     * Set the value of DAV property, getlastmodified.
1673     *
1674     * @param getLastModified The getlastmodified value.
1675     * @see #setGetLastModified(long)
1676     */

1677    protected void setGetLastModified(String JavaDoc getLastModified) {
1678        Date JavaDoc date = parseDate(getLastModified);
1679        if (date != null)
1680            this.getLastModified = date.getTime();
1681    }
1682
1683
1684    /**
1685     * Get the value of DAV property, creationdate.
1686     *
1687     * @return The creationdate string.
1688     */

1689    public long getCreationDate() {
1690        return creationDate;
1691    }
1692
1693
1694    /**
1695     * Set the value of DAV property, creationdate.
1696     *
1697     * @param creationDate The creationdate string.
1698     */

1699    protected void setCreationDate(long creationDate) {
1700        this.creationDate = creationDate;
1701    }
1702
1703
1704    /**
1705     * Set the value of DAV property, creationdate.
1706     *
1707     * @param creationDate The creationdate string.
1708     */

1709    protected void setCreationDate(String JavaDoc creationDate) {
1710        Date JavaDoc date = parseDate(creationDate);
1711        if (date != null)
1712            this.creationDate = date.getTime();
1713    }
1714
1715
1716    /**
1717     * Get the value of DAV property, getetag.
1718     *
1719     * @return The getetag string.
1720     */

1721    public String JavaDoc getGetEtag() {
1722        return getEtag;
1723    }
1724
1725
1726    /**
1727     * Set the value of DAV property, getetag.
1728     *
1729     * @param getEtag The getetag string.
1730     */

1731    protected void setGetEtag(String JavaDoc getEtag) {
1732        this.getEtag = getEtag;
1733    }
1734
1735    /**
1736     * Get the owner string, as used for locking purposes.
1737     */

1738    public String JavaDoc getOwner() {
1739        return owner;
1740    }
1741
1742    /**
1743     * Get the value of DAV property, supportedlock.
1744     *
1745     * @return The supportedlock string.
1746     */

1747    public String JavaDoc getSupportedLock() {
1748        return supportedLock;
1749    }
1750
1751
1752    /**
1753     * Set the value of DAV property, supportedlock.
1754     *
1755     * @param supportedLock The supportedlock string.
1756     */

1757    protected void setSupportedLock(String JavaDoc supportedLock) {
1758        this.supportedLock = supportedLock;
1759    }
1760
1761
1762    /**
1763     * Get the value of DAV property, lockdiscovery.
1764     *
1765     * @return The lockdiscovery property.
1766     */

1767    public LockDiscoveryProperty getLockDiscovery() {
1768        return lockDiscovery;
1769    }
1770
1771    /**
1772     * Set the value of DAV property, lockdiscovery.
1773     *
1774     * @param lockDiscovery The lockdiscovery property.
1775     */

1776    protected void setLockDiscovery(LockDiscoveryProperty lockDiscovery) {
1777        this.lockDiscovery = lockDiscovery;
1778    }
1779
1780
1781    /**
1782     * Get the activelock owners for this resource.
1783     *
1784     * @return An enumeration of owners.
1785     */

1786    public Enumeration JavaDoc getActiveLockOwners() {
1787        if (lockDiscovery == null) return null;
1788        Lock[] activeLocks = lockDiscovery.getActiveLocks();
1789        if (activeLocks == null) return null;
1790        Vector JavaDoc buff = new Vector JavaDoc();
1791        int count = activeLocks.length;
1792        for (int i = 0; i < count; i++) {
1793            buff.addElement(activeLocks[i].getOwner());
1794        }
1795        return buff.elements();
1796    }
1797
1798
1799    /**
1800     * Test that this resource is locked.
1801     *
1802     * @return true if it's locked.
1803     */

1804    public boolean isLocked() {
1805        if (lockDiscovery == null) return false;
1806        Lock[] activeLocks = lockDiscovery.getActiveLocks();
1807        if (activeLocks == null) return false;
1808        for (int i = 0; i < activeLocks.length; i++) {
1809            if (activeLocks[i].getLockType() == Lock.TYPE_WRITE) return true;
1810        }
1811        return false;
1812    }
1813
1814
1815    /**
1816     * Get the value of DAV property, ishidden.
1817     *
1818     * @return true if it is hidden, otherwise false.
1819     */

1820    public boolean getIsHidden() {
1821        return isHidden;
1822    }
1823
1824
1825    /**
1826     * Set the value of DAV property, ishidden.
1827     *
1828     * @param isHidden
1829     */

1830    protected void setIsHidden(boolean isHidden) {
1831        this.isHidden = isHidden;
1832    }
1833
1834
1835    /**
1836     * Set the value of DAV property, ishidden.
1837     *
1838     * @param isHidden
1839     */

1840    protected void setIsHidden(String JavaDoc isHidden) {
1841        this.isHidden = isHidden.equals(TRUE) ? true : false;
1842    }
1843
1844
1845    /**
1846     * Get the value of DAV property, iscollection
1847     *
1848     * @return true if it is collection, otherwise false.
1849     * @see #isCollection()
1850     */

1851    public boolean getIsCollection() {
1852        return isCollection;
1853    }
1854
1855
1856    /**
1857     * Set the value of DAV property, iscollection
1858     *
1859     * @param isCollection
1860     */

1861    protected void setIsCollection(boolean isCollection) {
1862        this.isCollection = isCollection;
1863    }
1864
1865
1866    /**
1867     * Set the value of DAV property, iscollection
1868     *
1869     * @param isCollection
1870     */

1871    protected void setIsCollection(String JavaDoc isCollection) {
1872        this.isCollection = isCollection.equals(TRUE) ? true : false;
1873    }
1874
1875
1876    // --------------------------------------- WebDAV Resource Public Methods
1877

1878
1879    /**
1880     * Set the properties for this resource.
1881     *
1882     * @param action The action to find properties for this resource.
1883     * @param depth the depth to which properties shall be found
1884     * @see #setDefaultAction(int)
1885     */

1886    public void setProperties(int action, int depth)
1887        throws HttpException, IOException JavaDoc {
1888
1889        switch (action) {
1890            case NAME:
1891                setNameProperties(depth);
1892                break;
1893            case BASIC:
1894                setBasicProperties(depth);
1895                break;
1896            case DEFAULT:
1897                setDefaultProperties(depth);
1898                break;
1899            case ALL:
1900                setAllProp(depth);
1901                break;
1902            case NOACTION:
1903            default:
1904                break;
1905        }
1906    }
1907
1908
1909    /**
1910     * Set the properties for this resource.
1911     *
1912     * @param depth the depth to which properties shall be found
1913     */

1914    public void setProperties(int depth)
1915        throws HttpException, IOException JavaDoc {
1916
1917        setProperties(defaultAction, depth);
1918    }
1919
1920    /**
1921     * Refresh the properties of this resource
1922     * without changing the status of the previous command
1923     */

1924    protected void refresh() throws HttpException, IOException JavaDoc {
1925        int latestStatusCode = this.latestStatusCode;
1926        String JavaDoc latestStatusMessage = this.latestStatusMessage;
1927        setProperties(DepthSupport.DEPTH_0);
1928        this.latestStatusCode = latestStatusCode;
1929        this.latestStatusMessage = latestStatusMessage;
1930    }
1931
1932    /**
1933     * Returns the last known information about the existence of this resource.
1934     * This is a wrapper method for getExistence.
1935     *
1936     * A previous call to the method setProperties might be necessary to update
1937     * that information.
1938     *
1939     * @return true if the resource is known to exist<br>
1940     * false if the resource is known not to exist or its status is unknown.
1941     * @see #getExistence()
1942     * @see #setProperties(int, int)
1943     */

1944    public boolean exists() {
1945        return getExistence();
1946    }
1947
1948
1949    /**
1950     * Set its existence.
1951     *
1952     * @param exists The boolean value to be set for its existence.
1953     */

1954    protected void setExistence(boolean exists) {
1955        this.exists = exists;
1956    }
1957
1958
1959    /**
1960     * Returns the last known information about the existence of this resource.
1961     *
1962     * A previous call to the method setProperties might be necessary to update that
1963     * information.
1964     *
1965     * @return true if the resource is known to exist<br>
1966     * false if the resource is known not to exist or its status is unknown.
1967     * @see #setProperties(int, int)
1968     */

1969    public boolean getExistence() {
1970        return exists;
1971    }
1972
1973
1974    /**
1975     * Set the overwrite flag for COPY, MOVE, BIND and REBIND.
1976     * Should be set before the method is executed.
1977     *
1978     * @param overwrite the overwrite flag
1979     * @see #getOverwrite()
1980     */

1981    public void setOverwrite(boolean overwrite) {
1982        this.overwrite = overwrite;
1983    }
1984
1985
1986    /**
1987     * Get the current value of the overwrite flag for COPY, MOVE, BIND and
1988     * REBIND.
1989     *
1990     * @return true if the current flag is overwriting.
1991     * @see #setOverwrite(boolean)
1992     */

1993    public boolean getOverwrite() {
1994        return overwrite;
1995    }
1996
1997
1998    /**
1999     * Close the session of this client
2000     */

2001    public void close() throws IOException JavaDoc {
2002        closeSession();
2003    }
2004
2005
2006    /**
2007     * Get the lastest value of the status message by HTTP methods.
2008     *
2009     * @return The http status string.
2010     */

2011    public String JavaDoc getStatusMessage() {
2012        return latestStatusMessage;
2013    }
2014
2015
2016    /**
2017     * Get the lastest value of the status code by HTTP methods.
2018     *
2019     * @return The http status code.
2020     */

2021    public int getStatusCode() {
2022        return latestStatusCode;
2023    }
2024
2025
2026    /**
2027     * Set the lastest value of the status code by HTTP methods.
2028     *
2029     * @param statusCode the HTTP status code.
2030     */

2031    protected void setStatusCode(int statusCode) {
2032        setStatusCode(statusCode, null);
2033    }
2034
2035
2036    /**
2037     * Set the lastest value of the status code by HTTP methods.
2038     *
2039     * @param statusCode the HTTP status code.
2040     * @param message the additional message.
2041     */

2042    protected void setStatusCode(int statusCode, String JavaDoc message) {
2043
2044        latestStatusCode = statusCode;
2045        latestStatusMessage = WebdavStatus.getStatusText(statusCode) +
2046            " (" + statusCode + ")" + ((message == null) ? "" : message);
2047    }
2048
2049
2050    /**
2051     * Get the allowed methods, checked by HTTP OPTIONS.
2052     *
2053     * @return the allowed HTTP methods.
2054     * @see #optionsMethod(java.lang.String)
2055     */

2056    public Enumeration JavaDoc getAllowedMethods() {
2057        return allowedMethods;
2058    }
2059
2060
2061    /**
2062     * Get the WebDAV capabilities, checked by HTTP OPTIONS.
2063     *
2064     * @return the WebDAV capabilities.
2065     * @see #optionsMethod(java.lang.String)
2066     */

2067    public Enumeration JavaDoc getDavCapabilities() {
2068        return davCapabilities;
2069    }
2070
2071
2072    /**
2073     * Get all resources in this collection with the depth 1.
2074     *
2075     * @return resources in this collection with the depth 1.
2076     * @exception HttpException
2077     * @exception IOException
2078     */

2079    public WebdavResources getChildResources()
2080        throws HttpException, IOException JavaDoc {
2081
2082        setProperties(DepthSupport.DEPTH_1);
2083
2084        return childResources;
2085    }
2086
2087
2088    /**
2089     * Get an array of resources denoting the WebDAV child resources in the
2090     * collection of this resources.
2091     *
2092     * @return An array of child resources in this resource.
2093     * @exception HttpException
2094     * @exception IOException
2095     */

2096    public WebdavResource[] listWebdavResources()
2097        throws HttpException, IOException JavaDoc {
2098
2099        return getChildResources().listResources();
2100    }
2101
2102
2103    /**
2104     * Get an array of pathnames denoting the WebDAV resources in the
2105     * collection denoted by this pathname.
2106     *
2107     * @return An array of pathnames denoting the resources, null if an
2108     * IOException occurs.
2109     */

2110    public String JavaDoc[] list() {
2111
2112        try {
2113            setNameProperties(DepthSupport.DEPTH_1);
2114        } catch (IOException JavaDoc e) {
2115            return null;
2116        }
2117        Enumeration JavaDoc hrefs = childResources.getResourceNames();
2118
2119        // To be atomic.
2120
Vector JavaDoc hrefList = new Vector JavaDoc();
2121        while (hrefs.hasMoreElements()) {
2122            hrefList.addElement((String JavaDoc) hrefs.nextElement());
2123        }
2124        // Calculate the size of the string array.
2125
int num = hrefList.size();
2126        String JavaDoc[] pathnames = new String JavaDoc[num];
2127        for (int i = 0; i < num; i++) {
2128            pathnames[i] = (String JavaDoc) hrefList.elementAt(i);
2129        }
2130
2131        return pathnames;
2132    }
2133
2134
2135    /**
2136     * Get an array of pathnames and basic information denoting the WebDAV
2137     * resources in the denoted by this pathname.
2138     *
2139     * array 0: displayname
2140     * array 1: getcontentlength
2141     * array 2: iscollection or getcontentype
2142     * array 3: getlastmodifieddate
2143     * array 4: name
2144     *
2145     * @return An array of pathnames and more denoting the resources.
2146     * @exception HttpException
2147     * @exception IOException
2148     */

2149    public Vector JavaDoc listBasic()
2150        throws HttpException, IOException JavaDoc {
2151
2152        setBasicProperties(DepthSupport.DEPTH_1);
2153        Enumeration JavaDoc hrefs = childResources.getResourceNames();
2154
2155        Vector JavaDoc hrefList = new Vector JavaDoc();
2156        while (hrefs.hasMoreElements()) {
2157            try {
2158                String JavaDoc resourceName = (String JavaDoc) hrefs.nextElement();
2159                WebdavResource currentResource =
2160                    childResources.getResource(resourceName);
2161
2162                String JavaDoc[] longFormat = new String JavaDoc[5];
2163                // displayname.
2164
longFormat[0] = currentResource.getDisplayName();
2165
2166
2167                long length = currentResource.getGetContentLength();
2168                // getcontentlength
2169
longFormat[1] = new Long JavaDoc(length).toString();
2170                // resourcetype
2171
ResourceTypeProperty resourceTypeProperty =
2172                    currentResource.getResourceType();
2173                // getcontenttype
2174
String JavaDoc getContentType =
2175                    currentResource.getGetContentType();
2176                longFormat[2] = resourceTypeProperty.isCollection() ?
2177                    "COLLECTION" : getContentType ;
2178                Date JavaDoc date = new Date JavaDoc(currentResource.getGetLastModified());
2179                // getlastmodified
2180
// Save the dummy what if failed.
2181
longFormat[3] = (date == null) ? "-- -- ----" :
2182                    // Print the local fancy date format.
2183
DateFormat.getDateTimeInstance().format(date);
2184                hrefList.addElement(longFormat);
2185
2186                // real name of componente
2187
longFormat[4] = currentResource.getName();
2188
2189
2190            } catch (Exception JavaDoc e) {
2191                // FIXME: After if's gotten an exception, any solution?
2192
if (debug > 0)
2193                    e.printStackTrace();
2194                //log.error(e,e);
2195
}
2196        }
2197
2198        return hrefList;
2199    }
2200
2201
2202    /**
2203     * Set the URL encoding flag for this http URL.
2204     *
2205     * @param encodeURLs true if it is encoded.
2206     * @exception MalformedURLException
2207     * @exception IOException
2208     *
2209     * @deprecated No longer has any effect.
2210     */

2211    public void setEncodeURLs(boolean encodeURLs) {
2212
2213    }
2214
2215
2216    // -------------------------- General accessor to use http request methods.
2217

2218
2219    /**
2220     * Retrieve the current http client for this resource.
2221     *
2222     * @return The http client.
2223     * @see #executeHttpRequestMethod(HttpClient, HttpMethod)
2224     */

2225    public HttpClient retrieveSessionInstance()
2226        throws IOException JavaDoc {
2227
2228        setClient();
2229        return client;
2230    }
2231
2232
2233    /**
2234     * Execute the http request method. And get its status code.
2235     *
2236     * @param client The http client.
2237     * @param method The http method.
2238     * @return The status code.
2239     * @see #retrieveSessionInstance()
2240     */

2241    public int executeHttpRequestMethod(HttpClient client, HttpMethod method)
2242        throws IOException JavaDoc, HttpException {
2243
2244        client.executeMethod(method);
2245        return method.getStatusCode();
2246    }
2247
2248
2249    // --------------------------------- WebDAV Request-method Public Methods
2250

2251    /**
2252     * Updates the resource with a new set of aces.
2253     *
2254     * @param path the server relative path of the resource to which the given
2255     * ACEs shall be applied
2256     * @param aces the ACEs to apply
2257     * @return true if the method succeeded
2258     */

2259    public boolean aclMethod(String JavaDoc path, Ace[] aces)
2260        throws HttpException, IOException JavaDoc {
2261
2262        setClient();
2263
2264        AclMethod method = new AclMethod(URIUtil.encodePath(path));
2265        method.setDebug(debug);
2266        method.setFollowRedirects(this.followRedirects);
2267
2268        generateIfHeader(method);
2269        for (int i=0; i<aces.length ; i++) {
2270            Ace ace = aces[i];
2271            method.addAce(ace);
2272        }
2273
2274        generateTransactionHeader(method);
2275        int statusCode = client.executeMethod(method);
2276
2277        setStatusCode(statusCode);
2278
2279        return (statusCode >= 200 && statusCode < 300) ? true : false;
2280    }
2281
2282
2283    /**
2284     * Return the <code>AclProperty</code> for the current resource
2285     *
2286     * @return acl property, null if the server doesn't respond with
2287     * <code>AclProperty</code>
2288     */

2289    public AclProperty aclfindMethod() throws HttpException, IOException JavaDoc {
2290        thisResource = true;
2291        return aclfindMethod(httpURL.getPath());
2292    }
2293
2294
2295    /**
2296     * Return the <code>AclProperty</code> for the resource at the given path
2297     *
2298     * @param path the server relative path of the resource to request
2299     * @return acl property, null if the server doesn't respond with
2300     * <code>AclProperty</code>
2301     */

2302    public AclProperty aclfindMethod(String JavaDoc path)
2303        throws HttpException, IOException JavaDoc {
2304
2305        setClient();
2306
2307        AclProperty acl = null;
2308
2309        Vector JavaDoc properties = new Vector JavaDoc();
2310        properties.addElement(AclProperty.TAG_NAME);
2311
2312        // Default depth=0, type=by_name
2313
PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
2314                                                   DepthSupport.DEPTH_0,
2315                                                   properties.elements());
2316        method.setDebug(debug);
2317        method.setFollowRedirects(this.followRedirects);
2318
2319        generateTransactionHeader(method);
2320        client.executeMethod(method);
2321
2322        Enumeration JavaDoc responses = method.getResponses();
2323        if (responses.hasMoreElements()) {
2324            ResponseEntity response =
2325                (ResponseEntity) responses.nextElement();
2326            String JavaDoc href = response.getHref();
2327
2328            // Set status code for this resource.
2329
if ((thisResource == true) && (response.getStatusCode() > 0))
2330                setStatusCode(response.getStatusCode());
2331            thisResource = false;
2332
2333            Enumeration JavaDoc responseProperties =
2334                method.getResponseProperties(href);
2335            while (responseProperties.hasMoreElements()) {
2336                Property property =
2337                    (Property) responseProperties.nextElement();
2338                if (property instanceof AclProperty) {
2339                    acl = (AclProperty)property;
2340                }
2341
2342            }
2343        }
2344
2345        return acl;
2346    }
2347
2348
2349    /**
2350     * Get the <code>PrincipalCollectionSetProperty</code> for the current
2351     * resource.
2352     *
2353     * @return principal collection set Property, null if the server doesn't
2354     * respond with a <code>PrincipalCollectionSetProperty</code>
2355     */

2356    public PrincipalCollectionSetProperty principalCollectionSetFindMethod()
2357        throws HttpException, IOException JavaDoc {
2358        thisResource = true;
2359        return principalCollectionSetFindMethod(httpURL.getPath());
2360    }
2361
2362    /**
2363     * Get the <code>PrincipalCollectionSetProperty</code> for the resource.
2364     *
2365     * @param path the server relative path of the resource to request
2366     * @return principal collection set Property, null if the server doesn't
2367     * respond with a <code>PrincipalCollectionSetProperty</code>
2368     */

2369    public PrincipalCollectionSetProperty principalCollectionSetFindMethod(
2370        String JavaDoc path) throws HttpException, IOException JavaDoc {
2371
2372        setClient();
2373
2374        PrincipalCollectionSetProperty set = null;
2375
2376        Vector JavaDoc properties = new Vector JavaDoc();
2377        properties.addElement(PrincipalCollectionSetProperty.TAG_NAME);
2378
2379        // Default depth=0, type=by_name
2380
PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
2381                                                   DepthSupport.DEPTH_0,
2382                                                   properties.elements());
2383        method.setDebug(debug);
2384        method.setFollowRedirects(this.followRedirects);
2385        generateTransactionHeader(method);
2386        client.executeMethod(method);
2387
2388        Enumeration JavaDoc responses = method.getResponses();
2389        if (responses.hasMoreElements()) {
2390            ResponseEntity response =
2391                (ResponseEntity) responses.nextElement();
2392            String JavaDoc href = response.getHref();
2393
2394            // Set status code for this resource.
2395
if ((thisResource == true) && (response.getStatusCode() > 0))
2396                setStatusCode(response.getStatusCode());
2397            thisResource = false;
2398
2399            Enumeration JavaDoc responseProperties =
2400                method.getResponseProperties(href);
2401            while (responseProperties.hasMoreElements()) {
2402                Property property =
2403                    (Property) responseProperties.nextElement();
2404                if (property instanceof PrincipalCollectionSetProperty) {
2405                    set = (PrincipalCollectionSetProperty)property;
2406                }
2407
2408            }
2409        }
2410
2411        return set;
2412    }
2413
2414
2415    /**
2416     * Return the LockDiscoveryProperty for the current resource
2417     *
2418     * @return null if the server doesn't respond with a LockDiscoveryProperty
2419     */

2420    public LockDiscoveryProperty lockDiscoveryPropertyFindMethod()
2421        throws HttpException, IOException JavaDoc {
2422        thisResource = true;
2423        return lockDiscoveryPropertyFindMethod(httpURL.getPath());
2424    }
2425
2426
2427    /**
2428     * Return the LockDiscoveryProperty for the resource at the given path
2429     *
2430     * @param path the server relative path of the resource to request
2431     * @return null if the server doesn't respond with a LockDiscoveryProperty
2432     */

2433    public LockDiscoveryProperty lockDiscoveryPropertyFindMethod(String JavaDoc path)
2434        throws HttpException, IOException JavaDoc {
2435
2436        setClient();
2437
2438        LockDiscoveryProperty set = null;
2439
2440        Vector JavaDoc properties = new Vector JavaDoc();
2441        properties.addElement(LockDiscoveryProperty.TAG_NAME);
2442
2443        // Default depth=0, type=by_name
2444
PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
2445                                                   DepthSupport.DEPTH_0,
2446                                                   properties.elements());
2447        method.setDebug(debug);
2448        method.setFollowRedirects(this.followRedirects);
2449        generateTransactionHeader(method);
2450        client.executeMethod(method);
2451
2452        Enumeration JavaDoc responses = method.getResponses();
2453        if (responses.hasMoreElements()) {
2454            ResponseEntity response =
2455                (ResponseEntity) responses.nextElement();
2456            String JavaDoc href = response.getHref();
2457
2458            // Set status code for this resource.
2459
if ((thisResource == true) && (response.getStatusCode() > 0))
2460                setStatusCode(response.getStatusCode());
2461            thisResource = false;
2462
2463            Enumeration JavaDoc responseProperties =
2464                method.getResponseProperties(href);
2465            while (responseProperties.hasMoreElements()) {
2466                Property property =
2467                    (Property) responseProperties.nextElement();
2468                if (property instanceof LockDiscoveryProperty) {
2469                    set = (LockDiscoveryProperty)property;
2470                }
2471
2472            }
2473        }
2474
2475        return set;
2476    }
2477
2478
2479    /**
2480     * Get InputStream for the GET method.
2481     *
2482     * @return InputStream
2483     * @exception HttpException
2484     * @exception IOException
2485     */

2486    public InputStream JavaDoc getMethodData()
2487        throws HttpException, IOException JavaDoc {
2488
2489        return getMethodData(httpURL.getPathQuery());
2490    }
2491
2492
2493    /**
2494     * Get InputStream for the GET method for the given path.
2495     *
2496     * @param path the server relative path of the resource to get
2497     * @return InputStream
2498     * @exception HttpException
2499     * @exception IOException
2500     */

2501    public InputStream JavaDoc getMethodData(String JavaDoc path)
2502        throws HttpException, IOException JavaDoc {
2503
2504        setClient();
2505
2506        GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
2507
2508        generateTransactionHeader(method);
2509        client.executeMethod(method);
2510
2511        int statusCode = method.getStatusLine().getStatusCode();
2512        setStatusCode(statusCode);
2513
2514        if(statusCode >= 200 && statusCode < 300)
2515            return method.getResponseBodyAsStream();
2516        else
2517            throw new IOException JavaDoc("Couldn't get file");
2518    }
2519
2520
2521    /**
2522     * Get data as a String for the GET method.
2523     *
2524     * @return the contents of this resource as a string
2525     * @exception HttpException
2526     * @exception IOException
2527     */

2528    public String JavaDoc getMethodDataAsString()
2529        throws HttpException, IOException JavaDoc {
2530
2531        return getMethodDataAsString(httpURL.getPathQuery());
2532    }
2533
2534
2535    /**
2536     * Get data as a String for the GET method for the given path.
2537     *
2538     * @param path the server relative path of the resource to get
2539     * @return the contents of the given resource as a string
2540     * @exception HttpException
2541     * @exception IOException
2542     */

2543    public String JavaDoc getMethodDataAsString(String JavaDoc path)
2544        throws HttpException, IOException JavaDoc {
2545
2546        setClient();
2547        GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
2548        generateTransactionHeader(method);
2549        int statusCode = client.executeMethod(method);
2550
2551        setStatusCode(statusCode);
2552
2553        return method.getResponseBodyAsString();
2554    }
2555
2556
2557    /**
2558     * Execute the GET method for this WebdavResource path.
2559     *
2560     * @param file The local file.
2561     * @return true if the method is succeeded.
2562     * @exception HttpException
2563     * @exception IOException
2564     */

2565    public boolean getMethod(File JavaDoc file)
2566        throws HttpException, IOException JavaDoc {
2567
2568        return getMethod(httpURL.getPathQuery(), file);
2569    }
2570
2571
2572    /**
2573     * Execute the GET method for the given path.
2574     *
2575     * @param path the server relative path of the resource to get
2576     * @param file The local file.
2577     * @return true if the method is succeeded.
2578     * @exception HttpException
2579     * @exception IOException
2580     */

2581    public boolean getMethod(String JavaDoc path, File JavaDoc file)
2582        throws HttpException, IOException JavaDoc {
2583
2584        setClient();
2585        GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
2586
2587        generateTransactionHeader(method);
2588        int statusCode = client.executeMethod(method);
2589
2590        setStatusCode(statusCode);
2591
2592        // get the file only if status is any kind of OK
2593
if (statusCode >= 200 && statusCode < 300) {
2594
2595            // Do a simple little loop to read the response back into the passed
2596
// file parameter.
2597
InputStream JavaDoc inStream = method.getResponseBodyAsStream();
2598
2599            FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(file);
2600            byte buffer[] = new byte[65535];
2601            int bytesRead;
2602            while ((bytesRead = inStream.read(buffer)) >= 0) {
2603                fos.write(buffer, 0, bytesRead);
2604            }
2605            inStream.close();
2606            fos.close();
2607
2608            return true;
2609
2610        } else {
2611            return false;
2612
2613        }
2614
2615
2616   }
2617
2618
2619    /**
2620     * Execute the PUT method for this resource.
2621     *
2622     * @param data The byte array.
2623     * @return true if the method is succeeded.
2624     * @exception HttpException
2625     * @exception IOException
2626     */

2627    public boolean putMethod(byte[] data)
2628        throws HttpException, IOException JavaDoc {
2629
2630        boolean result = putMethod(httpURL.getPathQuery(), data);
2631        if (result) refresh();
2632        return result;
2633    }
2634
2635
2636    /**
2637     * Execute the PUT method for the given path.
2638     *
2639     * @param path the server relative path to put the data
2640     * @param data The byte array.
2641     * @return true if the method is succeeded.
2642     * @exception HttpException
2643     * @exception IOException
2644     */

2645    public boolean putMethod(String JavaDoc path, byte[] data)
2646        throws HttpException, IOException JavaDoc {
2647
2648        setClient();
2649        PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
2650        generateIfHeader(method);
2651        if (getGetContentType() != null && !getGetContentType().equals(""))
2652            method.setRequestHeader("Content-Type", getGetContentType());
2653
2654        method.setRequestHeader("Content-Length", String.valueOf(data.length));
2655        method.setRequestBody(new ByteArrayInputStream JavaDoc(data));
2656
2657        generateTransactionHeader(method);
2658        int statusCode = client.executeMethod(method);
2659
2660        setStatusCode(statusCode);
2661        return (statusCode >= 200 && statusCode < 300) ? true : false;
2662    }
2663
2664
2665    /**
2666     * Execute the PUT method for this resource.
2667     *
2668     * @param is The input stream.
2669     * @return true if the method is succeeded.
2670     * @exception HttpException
2671     * @exception IOException
2672     */

2673    public boolean putMethod(InputStream JavaDoc is)
2674        throws HttpException, IOException JavaDoc {
2675
2676        return putMethod(httpURL.getPathQuery(), is);
2677    }
2678
2679
2680    /**
2681     * Execute the PUT method for the given path.
2682     *
2683     * @param path the server relative path to put the data
2684     * @param is The input stream.
2685     * @return true if the method is succeeded.
2686     * @exception HttpException
2687     * @exception IOException
2688     */

2689    public boolean putMethod(String JavaDoc path, InputStream JavaDoc is)
2690        throws HttpException, IOException JavaDoc {
2691
2692        setClient();
2693        PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
2694        generateIfHeader(method);
2695        if (getGetContentType() != null && !getGetContentType().equals(""))
2696            method.setRequestHeader("Content-Type", getGetContentType());
2697        method.setRequestContentLength(PutMethod.CONTENT_LENGTH_CHUNKED);
2698        method.setRequestBody(is);
2699        generateTransactionHeader(method);
2700        int statusCode = client.executeMethod(method);
2701
2702        setStatusCode(statusCode);
2703        return (statusCode >= 200 && statusCode < 300) ? true : false;
2704    }
2705
2706
2707    /**
2708     * Execute the PUT method for this WebdavResource.
2709     *
2710     * @param data String</cdoe> data to send.
2711     * @return true if the method is succeeded.
2712     * @exception HttpException
2713     * @exception IOException
2714     */

2715    public boolean putMethod(String JavaDoc data)
2716        throws HttpException, IOException JavaDoc {
2717
2718        boolean result = putMethod(httpURL.getPathQuery(), data);
2719        if (result) refresh();
2720
2721        return result;
2722    }
2723
2724
2725    /**
2726     * Execute the PUT method for the given path.
2727     *
2728     * @param path the server relative path to put the data
2729     * @param data String to send.
2730     * @return true if the method is succeeded.
2731     * @exception HttpException
2732     * @exception IOException
2733     */

2734    public boolean putMethod(String JavaDoc path, String JavaDoc data)
2735        throws HttpException, IOException JavaDoc {
2736
2737        setClient();
2738        PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
2739        generateIfHeader(method);
2740        if (getGetContentType() != null && !getGetContentType().equals(""))
2741            method.setRequestHeader("Content-Type", getGetContentType());
2742        method.setRequestBody(data);
2743        generateTransactionHeader(method);
2744        int statusCode = client.executeMethod(method);
2745
2746        setStatusCode(statusCode);
2747        return (statusCode >= 200 && statusCode < 300) ? true : false;
2748    }
2749
2750
2751    /**
2752     * Execute the PUT method for this WebdavResource.
2753     *
2754     * @param file the filename to get on local.
2755     * @return true if the method is succeeded.
2756     * @exception HttpException
2757     * @exception IOException
2758     */

2759    public boolean putMethod(File JavaDoc file)
2760        throws HttpException, IOException JavaDoc {
2761
2762        boolean result = putMethod(httpURL.getPathQuery(), file);
2763        if (result) refresh();
2764
2765        return result;
2766    }
2767
2768
2769    /**
2770     * Execute the PUT method for the given path.
2771     *
2772     * @param path the server relative path to put the given file
2773     * @param file the filename to get on local.
2774     * @return true if the method is succeeded.
2775     * @exception HttpException
2776     * @exception IOException
2777     */

2778    public boolean putMethod(String JavaDoc path, File JavaDoc file)
2779        throws HttpException, IOException JavaDoc {
2780
2781        setClient();
2782        PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
2783        generateIfHeader(method);
2784        if (getGetContentType() != null && !getGetContentType().equals(""))
2785            method.setRequestHeader("Content-Type", getGetContentType());
2786        long fileLength = file.length();
2787        method.setRequestContentLength(fileLength <= Integer.MAX_VALUE
2788                                       ? (int) fileLength
2789                                       : PutMethod.CONTENT_LENGTH_CHUNKED);
2790        method.setRequestBody(new FileInputStream JavaDoc(file));
2791        generateTransactionHeader(method);
2792        int statusCode = client.executeMethod(method);
2793
2794        setStatusCode(statusCode);
2795        return (statusCode >= 200 && statusCode < 300) ? true : false;
2796    }
2797
2798
2799
2800    /**
2801     * Execute the PUT method for this resource from the given url.
2802     * It's like a streaming copy about a resource of the specified remote url
2803     * to another remote url of this resource.
2804     *
2805     * @param url The URL to get a resource.
2806     * @return true if the method is succeeded.
2807     * @exception HttpException
2808     * @exception IOException
2809     */

2810    public boolean putMethod(URL JavaDoc url)
2811        throws HttpException, IOException JavaDoc {
2812
2813        boolean result = putMethod(httpURL.getPathQuery(), url);
2814        if (result) refresh();
2815
2816        return result;
2817    }
2818
2819
2820    /**
2821     * Execute the PUT method for the given path from the given url.
2822     *
2823     * @param path the server relative path to put the data
2824     * @param url The URL to get a resource.
2825     * @return true if the method is succeeded.
2826     * @exception HttpException
2827     * @exception IOException
2828     */

2829    public boolean putMethod(String JavaDoc path, URL JavaDoc url)
2830        throws HttpException, IOException JavaDoc {
2831
2832        setClient();
2833        PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
2834        generateIfHeader(method);
2835        if (getGetContentType() != null && !getGetContentType().equals(""))
2836            method.setRequestHeader("Content-Type", getGetContentType());
2837        method.setRequestBody(url.openStream());
2838        generateTransactionHeader(method);
2839        int statusCode = client.executeMethod(method);
2840
2841        setStatusCode(statusCode);
2842        return (statusCode >= 200 && statusCode < 300) ? true : false;
2843    }
2844
2845
2846    /**
2847     * Execute OPTIONS method for this WebdavResource.
2848     *
2849     * @return true if the method is succeeded.
2850     * @exception HttpException
2851     * @exception IOException
2852     */

2853    public boolean optionsMethod()
2854        throws HttpException, IOException JavaDoc {
2855
2856        return optionsMethod(httpURL.getPath());
2857    }
2858
2859
2860    /**
2861     * Execute OPTIONS method for the given path.
2862     *
2863     * @param path the server relative path of the resource to request
2864     * @return true if the method is succeeded.
2865     * @exception HttpException
2866     * @exception IOException
2867     * @see #getAllowedMethods()
2868     */

2869    public boolean optionsMethod(String JavaDoc path)
2870        throws HttpException, IOException JavaDoc {
2871
2872        setClient();
2873        OptionsMethod method;
2874        if (path.trim().equals("*"))
2875            method = new OptionsMethod("*");
2876        else
2877            method = new OptionsMethod(URIUtil.encodePath(path));
2878
2879        method.setDebug(debug);
2880        method.setFollowRedirects(this.followRedirects);
2881        generateTransactionHeader(method);
2882        int statusCode = client.executeMethod(method);
2883
2884        setStatusCode(statusCode);
2885
2886        if (statusCode >= 200 && statusCode < 300) {
2887            // check if the specific method is possbile
2888
allowedMethods = method.getAllowedMethods();
2889            // check WebDAV capabilities.
2890
davCapabilities = method.getDavCapabilities();
2891            return true;
2892        }
2893
2894        return false;
2895    }
2896
2897
2898    /**
2899     * Execute OPTIONS method for the given path.
2900     *
2901     * @param path the server relative path to send the request
2902     * @param aMethod a method to check it's supported.
2903     * @return true if the method is succeeded.
2904     * @exception HttpException
2905     * @exception IOException
2906     */

2907    public boolean optionsMethod(String JavaDoc path, String JavaDoc aMethod)
2908        throws HttpException, IOException JavaDoc {
2909
2910        if (aMethod != null && optionsMethod(path)) {
2911            while (allowedMethods.hasMoreElements()) {
2912                if (aMethod.equalsIgnoreCase((String JavaDoc)
2913                                                 allowedMethods.nextElement()))
2914                    return true;
2915            }
2916        }
2917
2918        return false;
2919    }
2920
2921
2922    /**
2923     * Execute OPTIONS method for the given http URL.
2924     *
2925     * @param httpURL the http URL.
2926     * @return the allowed methods and capabilities.
2927     * @exception HttpException
2928     * @exception IOException
2929     */

2930    public Enumeration JavaDoc optionsMethod(HttpURL httpURL)
2931        throws HttpException, IOException JavaDoc {
2932
2933        HttpClient client = getSessionInstance(httpURL, true);
2934
2935        OptionsMethod method = new OptionsMethod(httpURL.getEscapedPath());
2936        method.setDebug(debug);
2937        method.setFollowRedirects(this.followRedirects);
2938
2939        generateTransactionHeader(method);
2940        client.executeMethod(method);
2941
2942        Vector JavaDoc options = new Vector JavaDoc();
2943        int statusCode = method.getStatusLine().getStatusCode();
2944        if (statusCode >= 200 && statusCode < 300) {
2945            // check if the specific method is possbile
2946
Enumeration JavaDoc allowedMethods = method.getAllowedMethods();
2947            while (allowedMethods.hasMoreElements()) {
2948                options.addElement(allowedMethods.nextElement());
2949            }
2950            // check WebDAV capabilities.
2951
Enumeration JavaDoc davCapabilities = method.getDavCapabilities();
2952            while (davCapabilities.hasMoreElements()) {
2953                options.addElement(davCapabilities.nextElement());
2954            }
2955            Enumeration JavaDoc responses = method.getResponses();
2956            if (responses.hasMoreElements()) {
2957                ResponseEntity response =
2958                    (ResponseEntity) responses.nextElement();
2959                Enumeration JavaDoc workspaces = response.getWorkspaces();
2960                String JavaDoc sResult="";
2961                while (workspaces.hasMoreElements()){
2962                    sResult += workspaces.nextElement().toString();
2963                }
2964                Enumeration JavaDoc histories = response.getHistories();
2965                while (histories.hasMoreElements()){
2966                    sResult += histories.nextElement().toString();
2967                }
2968                // Set status code for this resource.
2969
if ((thisResource == true) && (response.getStatusCode() > 0))
2970                    setStatusCode(response.getStatusCode());
2971                thisResource = false;
2972                options.addElement(sResult);
2973            }
2974        }
2975
2976        return options.elements();
2977    }
2978
2979
2980    /**
2981     * Execute OPTIONS method for the given http URL, DELTAV
2982     *
2983     * @param httpURL the http URL.
2984     * @return the allowed methods and capabilities.
2985     * @exception HttpException
2986     * @exception IOException
2987     */

2988    public Enumeration JavaDoc optionsMethod(HttpURL httpURL, int type)
2989        throws HttpException, IOException JavaDoc {
2990
2991        HttpClient client = getSessionInstance(httpURL, true);
2992
2993        OptionsMethod method = new OptionsMethod(httpURL.getEscapedPath(),
2994                                                 type);
2995        method.setDebug(debug);
2996        method.setFollowRedirects(this.followRedirects);
2997
2998        generateTransactionHeader(method);
2999        client.executeMethod(method);
3000
3001        Vector JavaDoc options = new Vector JavaDoc();
3002        int statusCode = method.getStatusLine().getStatusCode();
3003        if (statusCode >= 200 && statusCode < 300) {
3004            Enumeration JavaDoc responses = method.getResponses();
3005            if (responses.hasMoreElements()) {
3006                ResponseEntity response =
3007                    (ResponseEntity) responses.nextElement();
3008                // String sResult="";
3009
if (type == OPTIONS_WORKSPACE){
3010                    Enumeration JavaDoc workspaces = response.getWorkspaces();
3011                    while (workspaces.hasMoreElements()){
3012                        options.add(workspaces.nextElement().toString());
3013                    }
3014                } else if (type == OPTIONS_VERSION_HISTORY){
3015                    Enumeration JavaDoc histories = response.getHistories();
3016                    while (histories.hasMoreElements()){
3017                        options.add(histories.nextElement().toString());
3018                    }
3019                }
3020
3021                // Set status code for this resource.
3022
if ((thisResource == true) && (response.getStatusCode() > 0))
3023                    setStatusCode(response.getStatusCode());
3024                thisResource = false;
3025                // options.addElement(sResult);
3026
}
3027        }
3028
3029        return options.elements();
3030    }
3031
3032
3033    /**
3034     * Execute OPTIONS method for the given path.
3035     *
3036     * @param path the server relative path of the resource to request
3037     * @return the allowed methods and capabilities.
3038     * @exception HttpException
3039     * @exception IOException
3040     * @see #getAllowedMethods()
3041     */

3042    public Enumeration JavaDoc optionsMethod(String JavaDoc path, int type)
3043        throws HttpException, IOException JavaDoc {
3044
3045        setClient();
3046
3047        OptionsMethod method = new OptionsMethod(URIUtil.encodePath(path),
3048                                                 type);
3049        method.setDebug(debug);
3050        method.setFollowRedirects(this.followRedirects);
3051
3052        generateTransactionHeader(method);
3053        client.executeMethod(method);
3054
3055        Vector JavaDoc options = new Vector JavaDoc();
3056        int statusCode = method.getStatusLine().getStatusCode();
3057        if (statusCode >= 200 && statusCode < 300) {
3058            Enumeration JavaDoc responses = method.getResponses();
3059            if (responses.hasMoreElements()) {
3060                ResponseEntity response =
3061                    (ResponseEntity) responses.nextElement();
3062                // String sResult="";
3063
if (type == OPTIONS_WORKSPACE){
3064                    Enumeration JavaDoc workspaces = response.getWorkspaces();
3065                    while (workspaces.hasMoreElements()){
3066                        options.add(workspaces.nextElement().toString());
3067                    }
3068                } else if (type == OPTIONS_VERSION_HISTORY){
3069                    Enumeration JavaDoc histories = response.getHistories();
3070                    while (histories.hasMoreElements()){
3071                        options.add(histories.nextElement().toString());
3072                    }
3073                }
3074
3075                // Set status code for this resource.
3076
if ((thisResource == true) && (response.getStatusCode() > 0))
3077                    setStatusCode(response.getStatusCode());
3078                thisResource = false;
3079                // options.addElement(sResult);
3080
}
3081        }
3082
3083        return options.elements();
3084    }
3085
3086    /**
3087     * Execute a LABEL method on the current path, setting the given label
3088     *
3089     * @param labelname the label to set
3090     * @param type the type of action. One of:
3091     * <ul>
3092     * <li> LABEL_ADD
3093     * <li> LABEL_REMOVE
3094     * <li> LABEL_SET
3095     * </ul>
3096     * @return true if the method succeeded
3097     */

3098    public boolean labelMethod(String JavaDoc labelname, int type)
3099        throws HttpException, IOException JavaDoc {
3100        return labelMethod(httpURL.getPath(), labelname, type);
3101    }
3102
3103    /**
3104     * Execute a LABEL method on the given path, setting the given label
3105     *
3106     * @param path the server relative path of the resource to act on
3107     * @param labelname the label to set
3108     * @param type the type of action. One of:
3109     * <ul>
3110     * <li> LABEL_ADD
3111     * <li> LABEL_REMOVE
3112     * <li> LABEL_SET
3113     * </ul>
3114     * @return true if the method succeeded
3115     */

3116    public boolean labelMethod(String JavaDoc path, String JavaDoc labelname, int type)
3117        throws HttpException, IOException JavaDoc {
3118        int labeltype=0;
3119
3120        switch(type) {
3121            case LABEL_SET:
3122                labeltype = LabelMethod.LABEL_SET;
3123                break;
3124            case LABEL_REMOVE:
3125                labeltype = LabelMethod.LABEL_REMOVE;
3126                break;
3127            case LABEL_ADD:
3128                labeltype = LabelMethod.LABEL_ADD;
3129                break;
3130        }
3131
3132        setClient();
3133        LabelMethod method = new LabelMethod(URIUtil.encodePath(path),
3134                                             labeltype, labelname);
3135        method.setDebug(debug);
3136        method.setFollowRedirects(this.followRedirects);
3137
3138        generateTransactionHeader(method);
3139        int statusCode = client.executeMethod(method);
3140
3141        setStatusCode(statusCode);
3142        return (statusCode >= 200 && statusCode < 300) ? true : false;
3143    }
3144
3145    /**
3146     * Execute the REPORT method.
3147     */

3148    public Enumeration JavaDoc reportMethod(HttpURL httpURL, int depth)
3149
3150        throws HttpException, IOException JavaDoc {
3151        setClient();
3152        // Default depth=0, type=by_name
3153
ReportMethod method = new ReportMethod(httpURL.getEscapedPath(),
3154                                               depth);
3155        method.setDebug(debug);
3156        method.setFollowRedirects(this.followRedirects);
3157        generateTransactionHeader(method);
3158        client.executeMethod(method);
3159
3160        Vector JavaDoc results = new Vector JavaDoc();
3161
3162        Enumeration JavaDoc responses = method.getResponses();
3163        while (responses.hasMoreElements()) {
3164            ResponseEntity response = (ResponseEntity) responses.nextElement();
3165            String JavaDoc href = response.getHref();
3166            String JavaDoc sResult = href;
3167
3168            // Set status code for this resource.
3169
if ((thisResource == true) && (response.getStatusCode() > 0))
3170                setStatusCode(response.getStatusCode());
3171            thisResource = false;
3172
3173            Enumeration JavaDoc responseProperties = method.getResponseProperties(href);
3174            while (responseProperties.hasMoreElements()) {
3175                Property property = (Property) responseProperties.nextElement();
3176                sResult += "\n" + property.getName() + ":\t" +
3177                    DOMUtils.getTextValue(property.getElement());
3178
3179            }
3180            results.addElement(sResult);
3181        }
3182
3183        return results.elements();
3184    }
3185
3186    public Enumeration JavaDoc reportMethod(HttpURL httpURL, Vector JavaDoc properties)
3187
3188        throws HttpException, IOException JavaDoc {
3189        setClient();
3190        // Default depth=0, type=by_name
3191
ReportMethod method =
3192            new ReportMethod(httpURL.getEscapedPath(), DepthSupport.DEPTH_0,
3193                             properties.elements());
3194        method.setDebug(debug);
3195        method.setFollowRedirects(this.followRedirects);
3196        generateTransactionHeader(method);
3197        client.executeMethod(method);
3198
3199        return method.getResponses();
3200    }
3201
3202    public Enumeration JavaDoc reportMethod(HttpURL httpURL, Vector JavaDoc properties,
3203                                    int depth)
3204
3205        throws HttpException, IOException JavaDoc {
3206        setClient();
3207        // Default depth=0, type=by_name
3208
ReportMethod method = new ReportMethod(httpURL.getEscapedPath(), depth,
3209                                               properties.elements());
3210        method.setDebug(debug);
3211        method.setFollowRedirects(this.followRedirects);
3212        generateTransactionHeader(method);
3213        client.executeMethod(method);
3214
3215        /*first draft, does work anyhow
3216         Enumeration results = method.getAllResponseURLs();
3217
3218         return results;*/

3219        /* Enumeration responses = method.getResponses();
3220         ResponseEntity response = (ResponseEntity) responses.nextElement();
3221         String href = (String) response.getHref();
3222         Enumeration results = method.getResponseProperties(href);
3223
3224         return results;*/

3225
3226        Vector JavaDoc results = new Vector JavaDoc();
3227
3228        Enumeration JavaDoc responses = method.getResponses();
3229        while (responses.hasMoreElements()) {
3230            ResponseEntity response = (ResponseEntity) responses.nextElement();
3231            String JavaDoc href = response.getHref();
3232            String JavaDoc sResult = href;
3233
3234            // Set status code for this resource.
3235
if ((thisResource == true) && (response.getStatusCode() > 0))
3236                setStatusCode(response.getStatusCode());
3237            thisResource = false;
3238
3239            Enumeration JavaDoc responseProperties = method.getResponseProperties(href);
3240            while (responseProperties.hasMoreElements()) {
3241                Property property = (Property) responseProperties.nextElement();
3242                sResult += "\n" + property.getName() + ":\t" +
3243                    DOMUtils.getTextValue(property.getElement());
3244                // results.addElement(DOMUtils.getTextValue(property.getElement()));
3245
}
3246            results.addElement(sResult);
3247        }
3248
3249        return results.elements();
3250    }
3251
3252
3253    // locate-by-history Report
3254
public Enumeration JavaDoc reportMethod(HttpURL httpURL, Vector JavaDoc properties,
3255                                    Vector JavaDoc histUri, int depth)
3256
3257        throws HttpException, IOException JavaDoc {
3258        setClient();
3259        // Default depth=0, type=by_name
3260
ReportMethod method = new ReportMethod(httpURL.getEscapedPath(), depth,
3261                                               properties.elements(),
3262                                               histUri.elements());
3263        method.setDebug(debug);
3264        method.setFollowRedirects(this.followRedirects);
3265        generateTransactionHeader(method);
3266        client.executeMethod(method);
3267
3268        Vector JavaDoc results = new Vector JavaDoc();
3269
3270        Enumeration JavaDoc responses = method.getResponses();
3271        while (responses.hasMoreElements()) {
3272            ResponseEntity response = (ResponseEntity) responses.nextElement();
3273            String JavaDoc href = response.getHref();
3274            String JavaDoc sResult = href;
3275
3276            // Set status code for this resource.
3277
if ((thisResource == true) && (response.getStatusCode() > 0))
3278                setStatusCode(response.getStatusCode());
3279            thisResource = false;
3280
3281            Enumeration JavaDoc responseProperties = method.getResponseProperties(href);
3282            while (responseProperties.hasMoreElements()) {
3283                Property property = (Property) responseProperties.nextElement();
3284                sResult += "\n" + property.getName() + ":\t" +
3285                    DOMUtils.getTextValue(property.getElement());
3286            }
3287            results.addElement(sResult);
3288        }
3289
3290        return results.elements();
3291    }
3292    // expand-property Report
3293
public Enumeration JavaDoc reportMethod(HttpURL httpURL, String JavaDoc sQuery, int depth)
3294
3295        throws HttpException, IOException JavaDoc {
3296        setClient();
3297        // Default depth=0, type=by_name
3298
ReportMethod method = new ReportMethod(httpURL.getEscapedPath(), depth,
3299                                               sQuery);
3300
3301        method.setDebug(debug);
3302        method.setFollowRedirects(this.followRedirects);
3303        generateTransactionHeader(method);
3304        client.executeMethod(method);
3305
3306        Vector JavaDoc results = new Vector JavaDoc();
3307
3308        Enumeration JavaDoc responses = method.getResponses();
3309        while (responses.hasMoreElements()) {
3310            ResponseEntity response = (ResponseEntity) responses.nextElement();
3311            //String href = (String) response.getHref();
3312
String JavaDoc sResult; //= href;
3313

3314            // Set status code for this resource.
3315
if ((thisResource == true) && (response.getStatusCode() > 0))
3316                setStatusCode(response.getStatusCode());
3317            thisResource = false;
3318
3319            sResult = response.toString();
3320            /*while (responseProperties.hasMoreElements()) {
3321             Property property = (Property) responseProperties.nextElement();
3322             sResult += "\t" + DOMUtils.getTextValue(property.getElement());
3323
3324             }*/

3325            results.addElement(sResult);
3326        }
3327
3328        return results.elements();
3329    }
3330
3331
3332    /**
3333     * Execute PROPFIND method with allprop for this WebdavResource.
3334     * Get list of all WebDAV properties on this WebDAV resource.
3335     *
3336     * <p>Once used this method, the the status code in the 207
3337     * reponse is need to be set for the method of WebdavResource.
3338     *
3339     * <p>The values of DepthSupport.DEPTH_0, DepthSupport.DEPTH_1,
3340     * DepthSupport.DEPTH_INFINITY is possbile for the depth.
3341     *
3342     * @param depth
3343     * @return an enumeration of <code>ResponseEntity</code>
3344     * @exception HttpException
3345     * @exception IOException
3346     */

3347    public Enumeration JavaDoc propfindMethod(int depth)
3348        throws HttpException, IOException JavaDoc {
3349
3350        thisResource = true;
3351        return propfindMethod(httpURL.getPath(), depth);
3352    }
3353
3354
3355    /**
3356     * Execute PROPFIND method with allprop for the given path.
3357     * Get list of all WebDAV properties on the given resource.
3358     *
3359     * <p>Once used this method, the the status code in the 207
3360     * reponse is need to be set for the method of WebdavResource.
3361     *
3362     * <p>The values of DepthSupport.DEPTH_0, DepthSupport.DEPTH_1,
3363     * DepthSupport.DEPTH_INFINITY is possbile for the depth.
3364     *
3365     * @param path the server relative path of the resource to request
3366     * @param depth
3367     * @return an enumeration of <code>ResponseEntity</code>
3368     * @exception HttpException
3369     * @exception IOException
3370     */

3371    public Enumeration JavaDoc propfindMethod(String JavaDoc path, int depth)
3372        throws HttpException, IOException JavaDoc {
3373
3374        setClient();
3375        // Change the depth for allprop
3376
PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
3377                                                   depth);
3378
3379        method.setDebug(debug);
3380
3381        // Default depth=infinity, type=allprop
3382
generateTransactionHeader(method);
3383        int status = client.executeMethod(method);
3384
3385        // Set status code for this resource.
3386
if (thisResource == true) {
3387            setStatusCode(status);
3388        }
3389        // Also accept OK sent by buggy servers.
3390
if (status != HttpStatus.SC_MULTI_STATUS
3391            && status != HttpStatus.SC_OK) {
3392            HttpException ex = new HttpException();
3393            ex.setReasonCode(status);
3394            throw ex;
3395        }
3396        thisResource = false;
3397
3398        return method.getResponses();
3399    }
3400
3401
3402
3403    /**
3404     * Execute PROPFIND method with by propname for this resource.
3405     * Get list of named WebDAV properties on this resource.
3406     *
3407     * <p>Once used this method, the the status code in the 207
3408     * reponse is need to be set for the method of WebdavResource.
3409     *
3410     * <p>The values of DepthSupport.DEPTH_0, DepthSupport.DEPTH_1
3411     * DepthSupport.DEPTH_INFINITY is possbile for the depth.
3412     *
3413     * @param depth The depth.
3414     * @param properties The named properties.
3415     * @return an enumeration of <code>ResponseEntity</code>
3416     * @exception HttpException
3417     * @exception IOException
3418     */

3419    public Enumeration JavaDoc propfindMethod(int depth, Vector JavaDoc properties)
3420        throws HttpException, IOException JavaDoc {
3421
3422        thisResource = true;
3423        return propfindMethod(httpURL.getPath(), depth, properties);
3424    }
3425
3426
3427    /**
3428     * Execute PROPFIND method with by propname for the given path.
3429     * Get list of named WebDAV properties on the given resource.
3430     *
3431     * <p>Once used this method, the the status code in the 207
3432     * reponse is need to be set for the method of WebdavResource.
3433     *
3434     * <p>The values of DepthSupport.DEPTH_0, DepthSupport.DEPTH_1
3435     * DepthSupport.DEPTH_INFINITY is possbile for the depth.
3436     *
3437     * @param path the server relative path of the resource to request
3438     * @param depth The depth.
3439     * @param properties The named properties.
3440     * @return an enumeration of <code>ResponseEntity</code>
3441     * @exception HttpException
3442     * @exception IOException
3443     */

3444    public Enumeration JavaDoc propfindMethod(String JavaDoc path, int depth,
3445                                      Vector JavaDoc properties)
3446        throws HttpException, IOException JavaDoc {
3447
3448        setClient();
3449        // Change the depth for prop
3450
PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
3451                                                   depth,
3452                                                   properties.elements());
3453
3454        method.setDebug(debug);
3455        method.setFollowRedirects(this.followRedirects);
3456        generateTransactionHeader(method);
3457        int status = client.executeMethod(method);
3458
3459        // Set status code for this resource.
3460
if (thisResource == true) {
3461            // Set the status code.
3462
setStatusCode(method.getStatusLine().getStatusCode());
3463        }
3464        // Also accept OK sent by buggy servers.
3465
if (status != HttpStatus.SC_MULTI_STATUS
3466            && status != HttpStatus.SC_OK) {
3467            HttpException ex = new HttpException();
3468            ex.setReasonCode(status);
3469            throw ex;
3470        }
3471        thisResource = false;
3472
3473        return method.getResponses();
3474    }
3475
3476
3477    /**
3478     * Execute PROPFIND method for this WebdavResource.
3479     * Get list of given WebDAV properties on this WebDAV resource.
3480     *
3481     * @param propertyName the WebDAV property to find.
3482     * @return Enumeration list of WebDAV properties on a resource.
3483     * @exception HttpException
3484     * @exception IOException
3485     */

3486    public Enumeration JavaDoc propfindMethod(String JavaDoc propertyName)
3487        throws HttpException, IOException JavaDoc {
3488
3489        Vector JavaDoc property = new Vector JavaDoc();
3490        property.addElement(propertyName);
3491
3492        thisResource = true;
3493        return propfindMethod(httpURL.getPath(), property);
3494    }
3495
3496
3497    /**
3498     * Execute PROPFIND method for the given WebdavResource path.
3499     * Get list of given WebDAV properties on this WebDAV resource.
3500     *
3501     * @param path the server relative path of the resource to request
3502     * @param propertyName the WebDAV property to find.
3503     * @return Enumeration list of WebDAV properties on a resource.
3504     * @exception HttpException
3505     * @exception IOException
3506     */

3507    public Enumeration JavaDoc propfindMethod(String JavaDoc path, String JavaDoc propertyName)
3508        throws HttpException, IOException JavaDoc {
3509
3510        Vector JavaDoc property = new Vector JavaDoc();
3511        property.addElement(propertyName);
3512
3513        thisResource = false;
3514        return propfindMethod(path, property);
3515    }
3516
3517
3518    /**
3519     * Execute PROPFIND method for this WebdavResource.
3520     * Get list of given WebDAV properties on this WebDAV resource.
3521     *
3522     * @param properties the WebDAV properties to find.
3523     * @return Enumeration list of WebDAV properties on a resource.
3524     * @exception HttpException
3525     * @exception IOException
3526     */

3527    public Enumeration JavaDoc propfindMethod(Vector JavaDoc properties)
3528        throws HttpException, IOException JavaDoc {
3529
3530        thisResource = true;
3531        return propfindMethod(httpURL.getPath(), properties);
3532    }
3533
3534
3535    /**
3536     * Execute PROPFIND method for the given path and properties.
3537     * Get list of given WebDAV properties on the given resource.
3538     *
3539     * @param path the server relative path of the resource to request
3540     * @param properties the WebDAV properties to find.
3541     * @return Enumeration list of WebDAV properties on a resource.
3542     * @exception HttpException
3543     * @exception IOException
3544     */

3545    public Enumeration JavaDoc propfindMethod(String JavaDoc path, Vector JavaDoc properties)
3546        throws HttpException, IOException JavaDoc {
3547
3548        setClient();
3549        // Default depth=0, type=by_name
3550
PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
3551                                                   DepthSupport.DEPTH_0,
3552                                                   properties.elements());
3553        method.setDebug(debug);
3554        method.setFollowRedirects(this.followRedirects);
3555        generateTransactionHeader(method);
3556        int status = client.executeMethod(method);
3557
3558        // Also accept OK sent by buggy servers.
3559
if (status != HttpStatus.SC_MULTI_STATUS
3560            && status != HttpStatus.SC_OK) {
3561            HttpException ex = new HttpException();
3562            ex.setReasonCode(status);
3563            throw ex;
3564        }
3565
3566        // It contains the results.
3567
Vector JavaDoc results = new Vector JavaDoc();
3568
3569        Enumeration JavaDoc responses = method.getResponses();
3570        if (responses.hasMoreElements()) {
3571            ResponseEntity response =
3572                (ResponseEntity) responses.nextElement();
3573            String JavaDoc href = response.getHref();
3574
3575            // Set status code for this resource.
3576
if ((thisResource == true) && (response.getStatusCode() > 0))
3577                setStatusCode(response.getStatusCode());
3578            thisResource = false;
3579
3580            Enumeration JavaDoc responseProperties =
3581                method.getResponseProperties(href);
3582            while (responseProperties.hasMoreElements()) {
3583                Property property =
3584                    (Property) responseProperties.nextElement();
3585                results.addElement(property.getPropertyAsString());
3586            }
3587        }
3588
3589        return results.elements();
3590    }
3591
3592
3593    /**
3594     * Execute PROPATCH method for this WebdavResource.
3595     *
3596     * @param propertyName the name of the property to set
3597     * @param propertyValue the value of the property to set
3598     * @return true if the method is succeeded.
3599     * @exception HttpException
3600     * @exception IOException
3601     * @deprecated it could be removed after the major version changes
3602     */

3603    public boolean proppatchMethod(String JavaDoc propertyName, String JavaDoc propertyValue)
3604        throws HttpException, IOException JavaDoc {
3605
3606        boolean result = proppatchMethod(httpURL.getPath(),
3607                                         propertyName, propertyValue, true);
3608        if (result) refresh();
3609
3610        return result;
3611    }
3612
3613
3614    /**
3615     * Execute PROPATCH method for this resource with the given property.
3616     *
3617     * @param propertyName the property name string (in "DAV:" namespace)
3618     * @param propertyValue the property value string
3619     * If the proppatch action is being removed, the value is null or any.
3620     * @param action true if it's being set, false if it's being removed
3621     * @return true if the method is succeeded.
3622     * @exception HttpException
3623     * @exception IOException
3624     */

3625    public boolean proppatchMethod(String JavaDoc propertyName, String JavaDoc propertyValue,
3626                                   boolean action) throws HttpException, IOException JavaDoc {
3627
3628        boolean result = proppatchMethod(httpURL.getPath(),
3629                                         propertyName, propertyValue, action);
3630        if (result) refresh();
3631
3632        return result;
3633    }
3634
3635
3636    /**
3637     * Execute PROPATCH method for this WebdavResource.
3638     *
3639     * @param propertyName the name of the property to set
3640     * @param propertyValue the value of the property to set
3641     * @return true if the method is succeeded.
3642     * @exception HttpException
3643     * @exception IOException
3644     * @deprecated it could be removed after the major version changes
3645     */

3646    public boolean proppatchMethod(PropertyName propertyName,
3647                                   String JavaDoc propertyValue)
3648        throws HttpException, IOException JavaDoc {
3649
3650        boolean result = proppatchMethod(httpURL.getPath(),
3651                                         propertyName, propertyValue, true);
3652        if (result) refresh();
3653
3654        return result;
3655    }
3656
3657
3658    /**
3659     * Execute PROPATCH method for this resource with the given property.
3660     *
3661     * @param propertyName the name of the property to set
3662     * @param propertyValue the value of the property to set
3663     * If the proppatch action is being removed, the value is null or any.
3664     * @param action true if it's being set, false if it's being removed
3665     * @return true if the method is succeeded
3666     * @exception HttpException
3667     * @exception IOException
3668     */

3669    public boolean proppatchMethod(PropertyName propertyName,
3670                                   String JavaDoc propertyValue, boolean action)
3671        throws HttpException, IOException JavaDoc {
3672
3673        boolean result = proppatchMethod(httpURL.getPath(),
3674                                         propertyName, propertyValue, action);
3675        if (result) refresh();
3676
3677        return result;
3678    }
3679
3680
3681    /**
3682     * Execute PROPATCH method for the given WebdavResource.
3683     *
3684     * @param path the server relative path of the resource to act on
3685     * @param propertyName the property name in "DAV:" namespace
3686     * @param propertyValue the property value string
3687     * @return true if the method is succeeded
3688     * @exception HttpException
3689     * @exception IOException
3690     * @deprecated it could be removed after the major version changes
3691     */

3692    public boolean proppatchMethod(String JavaDoc path, String JavaDoc propertyName,
3693                                   String JavaDoc propertyValue) throws HttpException, IOException JavaDoc {
3694
3695        Hashtable JavaDoc property = new Hashtable JavaDoc();
3696        property.put(propertyName, propertyValue);
3697        return proppatchMethod(path, property, true);
3698    }
3699
3700
3701    /**
3702     * Execute PROPATCH method for the specified resource with the given
3703     * property.
3704     *
3705     * @param path the server relative path of the resource to act on
3706     * @param propertyName the property name string (in "DAV:" namespace)
3707     * @param propertyValue the property value string
3708     * If the proppatch action is being removed, the value is null or any.
3709     * @param action true if it's to be set, false if it's to be removed
3710     * @return true if the method is succeeded
3711     * @exception HttpException
3712     * @exception IOException
3713     */

3714    public boolean proppatchMethod(String JavaDoc path, String JavaDoc propertyName,
3715                                   String JavaDoc propertyValue, boolean action)
3716        throws HttpException, IOException JavaDoc {
3717
3718        Hashtable JavaDoc property = new Hashtable JavaDoc();
3719        property.put(propertyName, propertyValue);
3720        return proppatchMethod(path, property, action);
3721    }
3722
3723
3724    /**
3725     * Execute PROPATCH method for the given WebdavResource.
3726     *
3727     * @param path the server relative path of the resource to act on
3728     * @param propertyName the property name.
3729     * @param propertyValue the property value.
3730     * @return true if the method is succeeded.
3731     * @exception HttpException
3732     * @exception IOException
3733     * @deprecated it could be removed after the major version changes
3734     */

3735    public boolean proppatchMethod(String JavaDoc path, PropertyName propertyName,
3736                                   String JavaDoc propertyValue) throws HttpException, IOException JavaDoc {
3737
3738        Hashtable JavaDoc property = new Hashtable JavaDoc();
3739        property.put(propertyName, propertyValue);
3740
3741        return proppatchMethod(path, property, true);
3742    }
3743
3744
3745    /**
3746     * Execute PROPATCH method for the given resource with the given
3747     * properties.
3748     *
3749     * @param path the server relative path of the resource to act on
3750     * @param propertyName the property name
3751     * @param propertyValue the property value string
3752     * If the proppatch action is being removed, the value is null or any.
3753     * @param action true if it's to be set, false if it's to be removed
3754     * @return true if the method is succeeded
3755     * @exception HttpException
3756     * @exception IOException
3757     */

3758    public boolean proppatchMethod(String JavaDoc path, PropertyName propertyName,
3759                                   String JavaDoc propertyValue, boolean action)
3760        throws HttpException, IOException JavaDoc {
3761
3762        Hashtable JavaDoc property = new Hashtable JavaDoc();
3763        property.put(propertyName, propertyValue);
3764        return proppatchMethod(path, property, action);
3765    }
3766
3767
3768    /**
3769     * Execute PROPATCH method for this WebdavResource.
3770     *
3771     * @param properties name and value pairs to set
3772     * (name can be a String or PropertyName)
3773     * @return true if the method is succeeded.
3774     * @exception HttpException
3775     * @exception IOException
3776     * @deprecated it could be removed after the major version changes
3777     */

3778    public boolean proppatchMethod(Hashtable JavaDoc properties)
3779        throws HttpException, IOException JavaDoc {
3780
3781        boolean result = proppatchMethod(httpURL.getPath(), properties, true);
3782        if (result) refresh();
3783
3784        return result;
3785    }
3786
3787
3788    /**
3789     * Execute PROPATCH method for this resource with the given properties.
3790     *
3791     * @param properties the name(= <code>String</code> or <code>PropertyName
3792     * </code> and value(= <code>String</code>) pairs for proppatch action
3793     * If the proppatch action is being removed, the value is null or any.
3794     * @param action true if it's being set, false if it's being removed
3795     * @return true if the method is succeeded.
3796     * @exception HttpException
3797     * @exception IOException
3798     */

3799    public boolean proppatchMethod(Hashtable JavaDoc properties, boolean action)
3800        throws HttpException, IOException JavaDoc {
3801
3802        boolean result = proppatchMethod(httpURL.getPath(), properties, action);
3803        if (result) refresh();
3804
3805        return result;
3806    }
3807
3808
3809    /**
3810     * Execute PROPATCH method for the given WebdavResource.
3811     *
3812     * @param path the server relative path of the resource to act on
3813     * @param properties name and value pairs to set
3814     * (name can be a String or PropertyName)
3815     * @return true if the method is succeeded.
3816     * @exception HttpException
3817     * @exception IOException
3818     * @deprecated it could be removed after the major version changes
3819     */

3820    public boolean proppatchMethod(String JavaDoc path, Hashtable JavaDoc properties)
3821        throws HttpException, IOException JavaDoc {
3822
3823        return proppatchMethod(path, properties, true);
3824    }
3825
3826
3827    /**
3828     * Execute PROPATCH method for the specified resource with the given
3829     * properties.
3830     *
3831     * @param path the server relative path of the resource to act on
3832     * @param properties the name(= <code>String</code> or <code>PropertyName
3833     * </code> and value(= <code>String</code>) pairs for proppatch action
3834     * If the proppatch action is being removed, the value is null or any.
3835     * @param action true if it's being set, false if it's being removed
3836     * @return true if the method is succeeded.
3837     * @exception HttpException
3838     * @exception IOException
3839     */

3840    public boolean proppatchMethod(String JavaDoc path, Hashtable JavaDoc properties,
3841                                   boolean action) throws HttpException, IOException JavaDoc {
3842
3843        setClient();
3844        PropPatchMethod method = new PropPatchMethod(URIUtil.encodePath(path));
3845        method.setDebug(debug);
3846        method.setFollowRedirects(this.followRedirects);
3847
3848        generateIfHeader(method);
3849        Enumeration JavaDoc names = properties.keys();
3850        boolean hasSomething = false;
3851        if (names.hasMoreElements()) {
3852            hasSomething = true;
3853        }
3854        while (names.hasMoreElements()) {
3855            Object JavaDoc item = names.nextElement();
3856            if (item instanceof String JavaDoc) {
3857                String JavaDoc name = (String JavaDoc) item;
3858                String JavaDoc value = (String JavaDoc) properties.get(item);
3859                if (action) {
3860                    method.addPropertyToSet(name, value);
3861                } else {
3862                    method.addPropertyToRemove(name);
3863                }
3864            } else if (item instanceof PropertyName) {
3865                String JavaDoc name = ((PropertyName) item).getLocalName();
3866                String JavaDoc namespaceURI = ((PropertyName) item).getNamespaceURI();
3867                String JavaDoc value = (String JavaDoc) properties.get(item);
3868                if (action) {
3869                    method.addPropertyToSet(name, value, null, namespaceURI);
3870                } else {
3871                    method.addPropertyToRemove(name, null, namespaceURI);
3872                }
3873            } else {
3874                // unknown type, debug or ignore it
3875
}
3876        }
3877        if (hasSomething) {
3878            generateTransactionHeader(method);
3879            int statusCode = client.executeMethod(method);
3880            // Possbile Status Codes => SC_OK
3881
// WebdavStatus.SC_FORBIDDEN, SC_CONFLICT, SC_LOCKED, 507
3882
setStatusCode(statusCode);
3883            if (statusCode >= 200 && statusCode < 300) {
3884                return true;
3885            }
3886        }
3887        return false;
3888    }
3889
3890
3891    /**
3892     * Execute the HEAD method for this WebdavResource.
3893     *
3894     * @return true if the method is succeeded.
3895     * @exception HttpException
3896     * @exception IOException
3897     */

3898    public boolean headMethod()
3899        throws HttpException, IOException JavaDoc {
3900
3901        return headMethod(httpURL.getPathQuery());
3902    }
3903
3904
3905    /**
3906     * Execute the HEAD method for the given path.
3907     *
3908     * @param path the server relative path of the resource to request
3909     * @return true if the method is succeeded.
3910     * @exception HttpException
3911     * @exception IOException
3912     */

3913    public boolean headMethod(String JavaDoc path)
3914        throws HttpException, IOException JavaDoc {
3915
3916        setClient();
3917        HeadMethod method = new HeadMethod(URIUtil.encodePathQuery(path));
3918
3919        generateTransactionHeader(method);
3920        int statusCode = client.executeMethod(method);
3921
3922        setStatusCode(statusCode);
3923        return (statusCode >= 200 && statusCode < 300) ? true : false;
3924    }
3925
3926
3927    /**
3928     * Execute the DELETE method for this WebdavResource.
3929     *
3930     * @return true if the method is succeeded.
3931     * @exception HttpException
3932     * @exception IOException
3933     */

3934    public boolean deleteMethod()
3935        throws HttpException, IOException JavaDoc {
3936
3937        boolean result = deleteMethod(httpURL.getPath());
3938        if (result) {
3939            setExistence(false);
3940        }
3941
3942        return result;
3943    }
3944
3945
3946    /**
3947     * Execute the DELETE method for the given path.
3948     *
3949     * @param path the server relative path of the resource to delete
3950     * @return true if the method is succeeded.
3951     * @exception HttpException
3952     * @exception IOException
3953     */

3954    public boolean deleteMethod(String JavaDoc path)
3955        throws HttpException, IOException JavaDoc {
3956
3957        setClient();
3958        DeleteMethod method = new DeleteMethod(URIUtil.encodePath(path));
3959        method.setDebug(debug);
3960        method.setFollowRedirects(this.followRedirects);
3961
3962        generateIfHeader(method);
3963        generateTransactionHeader(method);
3964        int statusCode = client.executeMethod(method);
3965
3966        setStatusCode(statusCode);
3967        return (statusCode >= 200 && statusCode < 300) ? true : false;
3968    }
3969
3970
3971    /**
3972     * Execute the MOVE method for this WebdavReource.
3973     *
3974     * @param destination the destination to move to as a server relative path
3975     * @return true if the method is succeeded.
3976     * @exception HttpException
3977     * @exception IOException
3978     */

3979    public boolean moveMethod(String JavaDoc destination)
3980        throws HttpException, IOException JavaDoc {
3981
3982        boolean result = moveMethod(httpURL.getPath(), destination);
3983        if (result) {
3984            httpURL.setPath(destination);
3985            refresh();
3986        }
3987
3988        return result;
3989    }
3990
3991
3992    /**
3993     * Execute the MOVE method for the given source and destination.
3994     *
3995     * @param source the source resource as a server relativ path
3996     * @param destination the destination to move to as a server relative path
3997     * @return true if the method is succeeded.
3998     * @exception HttpException
3999     * @exception IOException
4000     */

4001    public boolean moveMethod(String JavaDoc source, String JavaDoc destination)
4002        throws HttpException, IOException JavaDoc {
4003
4004        setClient();
4005        MoveMethod method = new MoveMethod(URIUtil.encodePath(source),
4006                                           URIUtil.encodePath(destination));
4007        method.setDebug(debug);
4008        method.setFollowRedirects(this.followRedirects);
4009        generateIfHeader(method);
4010        method.setOverwrite(overwrite);
4011        generateTransactionHeader(method);
4012        int statusCode = client.executeMethod(method);
4013
4014        // Possbile MOVE Status Codes => SC_CREATED, SC_NO_CONTENT
4015
// WebdavStatus.SC_FORBIDDEN, SC_CONFLICT, SC_PRECONDITION_FAILED,
4016
// SC_LOCKED, SC_BAD_GATEWAY
4017
setStatusCode(statusCode);
4018        return (statusCode >= 200 && statusCode < 300) ? true : false;
4019    }
4020
4021
4022    /**
4023     * Execute the COPY method for the given destination path.
4024     *
4025     * @param destination the destination as a server relative path
4026     * @return true if the method is succeeded.
4027     * @exception HttpException
4028     * @exception IOException
4029     */

4030    public boolean copyMethod(String JavaDoc destination)
4031        throws HttpException, IOException JavaDoc {
4032
4033        boolean result = copyMethod(httpURL.getPath(), destination);
4034        if (result) refresh();
4035
4036        return result;
4037    }
4038
4039
4040    /**
4041     * Execute the COPY method the given source and destination.
4042     *
4043     * @param source the source resource as a server relative path
4044     * @param destination the destination as a server relative path
4045     * @return true if the method is succeeded.
4046     * @exception HttpException
4047     * @exception IOException
4048     */

4049    public boolean copyMethod(String JavaDoc source, String JavaDoc destination)
4050        throws HttpException, IOException JavaDoc {
4051
4052        setClient();
4053        CopyMethod method = new CopyMethod(URIUtil.encodePath(source),
4054                                           URIUtil.encodePath(destination));
4055        method.setDebug(debug);
4056        method.setFollowRedirects(this.followRedirects);
4057
4058        generateIfHeader(method);
4059        method.setOverwrite(overwrite);
4060        generateTransactionHeader(method);
4061        int statusCode = client.executeMethod(method);
4062
4063        // Possbile COPY Status Codes => SC_CREATED, SC_NO_CONTENT
4064
// WebdavStatus.SC_FORBIDDEN, SC_CONFLICT, SC_PRECONDITION_FAILED,
4065
// SC_LOCKED, SC_BAD_GATEWAY, SC_INSUFFICIENT_STORAGE
4066
setStatusCode(statusCode);
4067        return (statusCode >= 200 && statusCode < 300) ? true : false;
4068    }
4069
4070
4071
4072    /**
4073     * Execute the MKCOL method for this WebdavResource.
4074     *
4075     * @return true if the method is succeeded.
4076     * @exception HttpException
4077     * @exception IOException
4078     */

4079    public boolean mkcolMethod()
4080        throws HttpException, IOException JavaDoc {
4081
4082        boolean result = mkcolMethod(httpURL.getPath());
4083        if (result) refresh();
4084
4085        return result;
4086    }
4087
4088
4089    /**
4090     * Execute the MKCOL method for the given path.
4091     *
4092     * @param path the server relative path at which to create a new collection
4093     * resource
4094     * @return true if the method is succeeded.
4095     * @exception HttpException
4096     * @exception IOException
4097     */

4098    public boolean mkcolMethod(String JavaDoc path)
4099        throws HttpException, IOException JavaDoc {
4100
4101        setClient();
4102        MkcolMethod method = new MkcolMethod(URIUtil.encodePath(path));
4103
4104        generateIfHeader(method);
4105        generateTransactionHeader(method);
4106        int statusCode = client.executeMethod(method);
4107
4108        // Possbile MKCOL Status Codes => SC_CREATED
4109
// WebdavStatus.SC_FORBIDDEN, SC_METHOD_NOT_ALLOWED, SC_CONFLICT,
4110
// SC_LOCKED, SC_UNSUPPORTED_MEDIA_TYPE, SC_INSUFFICIENT_STORAGE
4111
setStatusCode(statusCode);
4112        return (statusCode >= 200 && statusCode < 300) ? true : false;
4113    }
4114
4115
4116    /**
4117     * Execute the LOCK method for this WebdavResource. This method tries to
4118     * acquire an exclusive write lock with a timeout of 120 seconds.
4119     *
4120     * @return true if the method is succeeded.
4121     * @exception HttpException
4122     * @exception IOException
4123     */

4124    public boolean lockMethod()
4125        throws HttpException, IOException JavaDoc {
4126
4127        String JavaDoc owner = (httpURL.getUser() != null) ?
4128            httpURL.getUser() : defaultOwner;
4129
4130        boolean result = lockMethod(httpURL.getPath(), owner, 120);
4131        if (result) refresh();
4132
4133        return result;
4134    }
4135
4136
4137
4138    /**
4139     * Execute the LOCK method for this WebdavResource. This method tries to
4140     * acquire an exclusive write lock with the given timeout value.
4141     *
4142     * @param owner the owner string.
4143     * @param timeout the timeout
4144     * @return true if the method is succeeded.
4145     * @exception HttpException
4146     * @exception IOException
4147     */

4148    public boolean lockMethod(String JavaDoc owner, int timeout)
4149        throws HttpException, IOException JavaDoc {
4150
4151        boolean result = lockMethod(httpURL.getPath(), owner, timeout);
4152        if (result) refresh();
4153
4154        return result;
4155    }
4156
4157
4158    /**
4159     * Execute the LOCK method for the given path. This method tries to acquire
4160     * an exclusive write lock with a timeout of 120 seconds.
4161     *
4162     * @param path the server relative path of the resource to lock
4163     * @return true if the method is succeeded.
4164     * @exception HttpException
4165     * @exception IOException
4166     */

4167    public boolean lockMethod(String JavaDoc path)
4168        throws HttpException, IOException JavaDoc {
4169
4170        String JavaDoc owner = (httpURL.getUser() != null) ?
4171            httpURL.getUser() : defaultOwner;
4172
4173        return lockMethod(path, owner, 120);
4174    }
4175
4176
4177    /**
4178     * Execute the LOCK method for the given path. This method tries to acquire
4179     * an exclusive write lock with the given timeout value.
4180     *
4181     * @param path the server relative path of the resource to lock
4182     * @param owner The owner string.
4183     * @param timeout the timeout value.
4184     * @return true if the method is succeeded.
4185     * @exception HttpException
4186     * @exception IOException
4187     */

4188    public boolean lockMethod(String JavaDoc path, String JavaDoc owner, int timeout)
4189        throws HttpException, IOException JavaDoc {
4190
4191        return lockMethod(path, owner, timeout, LockMethod.SCOPE_EXCLUSIVE);
4192    }
4193
4194    /**
4195     * Execute the LOCK method for the given path. This method tries to acquire
4196     * an exclusive write lock with the given timeout value.
4197     *
4198     * @param path the server relative path of the resource to lock
4199     * @param owner The owner string.
4200     * @param timeout the timeout value.
4201     * @param locktype, the scope of lock.
4202     * @return true if the method is succeeded.
4203     * @exception HttpException
4204     * @exception IOException
4205     */

4206    public boolean lockMethod(String JavaDoc path, String JavaDoc owner, int timeout, short lockType)
4207        throws HttpException, IOException JavaDoc {
4208
4209        return lockMethod(path, owner, timeout, lockType, DepthSupport.DEPTH_INFINITY);
4210    }
4211    
4212
4213    /**
4214     * Execute the LOCK method for the given path. This method tries to acquire
4215     * an exclusive write lock with the given timeout value.
4216     *
4217     * @param path the server relative path of the resource to lock
4218     * @param owner The owner string.
4219     * @param timeout the timeout value.
4220     * @param locktype, the scope of lock.
4221     * @return true if the method is succeeded.
4222     * @exception HttpException
4223     * @exception IOException
4224     */

4225    public boolean lockMethod(String JavaDoc path, String JavaDoc owner, int timeout, short lockType, int depth)
4226        throws HttpException, IOException JavaDoc {
4227
4228        setClient();
4229
4230        if (owner == null) {
4231            owner = (httpURL.getUser() != null) ? httpURL.getUser() : defaultOwner;
4232        }
4233
4234        // default lock type setting
4235
LockMethod method = new LockMethod(URIUtil.encodePath(path), owner,
4236                                           lockType, timeout);
4237        method.setDebug(debug);
4238        method.setFollowRedirects(this.followRedirects);
4239        method.setDepth(depth);
4240
4241        generateIfHeader(method);
4242        generateTransactionHeader(method);
4243        int statusCode = client.executeMethod(method);
4244        String JavaDoc lock = method.getLockToken();
4245        WebdavState state = (WebdavState) client.getState();
4246        if (state != null) {
4247            state.addLock(path, lock);
4248        }
4249        this.owner = method.getOwner();
4250
4251        // Possbile LOCK Status Codes => SC_OK
4252
// WebdavStatus.SC_SC_PRECONDITION_FAILED, SC_LOCKED
4253
setStatusCode(statusCode, lock);
4254
4255        return (statusCode >= 200 && statusCode < 300) ? true : false;
4256    }
4257
4258
4259    /**
4260     * Execute the LOCK method for this WebdavResource.
4261     *
4262     * @see LockMethod
4263     * @deprecated The timeout value MUST NOT be greater than 2^32-1.
4264     */

4265    public boolean lockMethod(String JavaDoc owner, short timeout)
4266        throws HttpException, IOException JavaDoc {
4267
4268        return lockMethod(owner, (int) timeout);
4269    }
4270
4271
4272    /**
4273     * Execute the LOCK method for the given path.
4274     *
4275     * @see LockMethod
4276     * @deprecated The timeout value MUST NOT be greater than 2^32-1.
4277     */

4278    public boolean lockMethod(String JavaDoc path, String JavaDoc owner, short timeout)
4279        throws HttpException, IOException JavaDoc {
4280
4281        return lockMethod(path, owner, (int) timeout);
4282    }
4283
4284    /**
4285     * Begins a new transaction.
4286     * The transaction handle returned by the WebDAV server will be remembered and included
4287     * as a header of subsequent requests until either {@link #commitTransaction()} or {@link #abortTransaction()}
4288     * are called. You can retrieve it using {@link #getTransactionHandle()}.
4289     *
4290     * @param owner the owner of this transaction
4291     * @param timeout timeout in milleseconds
4292     * @return <code>true</code> if the transaction has been successfully started, <code>false</code> otherwise
4293     * @throws IOException if anything goes wrong
4294     * @see #commitTransaction()
4295     * @see #abortTransaction()
4296     * @see #getTransactionHandle()
4297     */

4298    public boolean startTransaction(String JavaDoc owner, int timeout) throws IOException JavaDoc {
4299        String JavaDoc path = httpURL.getPath();
4300        
4301        setClient();
4302
4303        if (owner == null) {
4304            owner = (httpURL.getUser() != null) ? httpURL.getUser() : defaultOwner;
4305        }
4306
4307        // default lock type setting
4308
LockMethod method = new LockMethod(path, owner, timeout, true);
4309        method.setDebug(debug);
4310        method.setFollowRedirects(this.followRedirects);
4311
4312        generateIfHeader(method);
4313        int statusCode = client.executeMethod(method);
4314        String JavaDoc txHandle = method.getLockToken();
4315        WebdavState state = (WebdavState) client.getState();
4316        if (state != null) {
4317            state.setTransactionHandle(txHandle);
4318        }
4319        this.owner = method.getOwner();
4320
4321        // Possbile LOCK Status Codes => SC_OK
4322
// WebdavStatus.SC_SC_PRECONDITION_FAILED, SC_LOCKED
4323
setStatusCode(statusCode, txHandle);
4324
4325        return (statusCode >= 200 && statusCode < 300) ? true : false;
4326    }
4327
4328    /**
4329     * Returns the transaction handle set by {@link #startTransaction(String, int)}.
4330     *
4331     * @return the current transaction handle or <code>null</code> if the client does not operate inside a transaction
4332     * @throws IOException if anything goes wrong
4333     * @see #startTransaction(String, int)
4334     */

4335    public String JavaDoc getTransactionHandle() throws IOException JavaDoc {
4336        setClient();
4337
4338        // Get the lock for the given path.
4339
WebdavState state = (WebdavState) client.getState();
4340        if (state == null) return null;
4341        String JavaDoc txHandle = state.getTransactionHandle();
4342        return txHandle;
4343    }
4344    
4345    /**
4346     * Commits the transaction started by {@link #startTransaction(String, int)} and resets the transaction handle.
4347     *
4348     * @return <code>true</code> if the transaction has been successfully committed, <code>false</code> otherwise
4349     * @throws IOException if anything goes wrong
4350     * @see #startTransaction(String, int)
4351     * @see #abortTransaction()
4352     * @see #getTransactionHandle()
4353     */

4354    public boolean commitTransaction() throws IOException JavaDoc {
4355        String JavaDoc path = httpURL.getPath();
4356        return endTransaction(path, UnlockMethod.COMMIT_TRANSACTION);
4357    }
4358
4359    /**
4360     * Aborts - i.e. rolls back all changes of - the transaction started by {@link #startTransaction(String, int)} and resets the transaction handle.
4361     *
4362     * @return <code>true</code> if the transaction has been successfully committed, <code>false</code> otherwise
4363     * @throws IOException if anything goes wrong
4364     * @see #startTransaction(String, int)
4365     * @see #abortTransaction()
4366     * @see #getTransactionHandle()
4367     */

4368    public boolean abortTransaction() throws IOException JavaDoc {
4369        String JavaDoc path = httpURL.getPath();
4370        return endTransaction(path, UnlockMethod.ABORT_TRANSACTION);
4371    }
4372
4373    protected boolean endTransaction(String JavaDoc path, int transactionStatus) throws IOException JavaDoc {
4374        setClient();
4375
4376        // Get the lock for the given path.
4377
WebdavState state = (WebdavState) client.getState();
4378        if (state == null) return false;
4379        String JavaDoc txHandle = state.getTransactionHandle();
4380        if (txHandle == null) return false;
4381        UnlockMethod method = new UnlockMethod(path, txHandle, transactionStatus);
4382        method.setDebug(debug);
4383        method.setFollowRedirects(this.followRedirects);
4384
4385        generateIfHeader(method);
4386        int statusCode = client.executeMethod(method);
4387
4388        setStatusCode(statusCode);
4389        if (statusCode >= 200 && statusCode < 300) {
4390            state.setTransactionHandle(null);
4391            return true;
4392        }
4393        return false;
4394    }
4395
4396    /**
4397     * Execute the Unlock method for this WebdavResource.
4398     *
4399     * @return true if the method is succeeded.
4400     * @exception HttpException
4401     * @exception IOException
4402     */

4403    public boolean unlockMethod() throws HttpException, IOException JavaDoc {
4404
4405        String JavaDoc owner = (httpURL.getUser() != null) ?
4406            httpURL.getUser() : defaultOwner;
4407
4408        boolean result = unlockMethod(httpURL.getPath(), owner);
4409        if (result) refresh();
4410
4411        return result;
4412    }
4413
4414
4415    /**
4416     * Execute the Unlock method for the given path.
4417     *
4418     * @param path the server relative path of the resource to unlock
4419     * @return true if the method is succeeded.
4420     * @exception HttpException
4421     * @exception IOException
4422     */

4423    public boolean unlockMethod(String JavaDoc path)
4424        throws HttpException, IOException JavaDoc {
4425
4426        String JavaDoc owner = (httpURL.getUser() != null) ?
4427            httpURL.getUser() : defaultOwner;
4428
4429        return unlockMethod(path, owner);
4430    }
4431
4432
4433    /**
4434     * Execute the Unlock method for the given path.
4435     *
4436     * @param path the server relative path of the resource to unlock
4437     * @return true if the method is succeeded.
4438     * @exception HttpException
4439     * @exception IOException
4440     */

4441    public boolean unlockMethod(String JavaDoc path, String JavaDoc owner)
4442        throws HttpException, IOException JavaDoc {
4443
4444        setClient();
4445
4446        if (owner == null) {
4447            owner = (httpURL.getUser() != null) ? httpURL.getUser() : defaultOwner;
4448        }
4449
4450        // Get the lock for the given path.
4451
WebdavState state = (WebdavState) client.getState();
4452        // Discover the locktoken from the given lock owner
4453

4454        state = discoverLock(owner, path, state);
4455        String JavaDoc lock = state.getLock(path);
4456        if (lock == null) return false;
4457        // unlock for the given path.
4458
UnlockMethod method = new UnlockMethod(URIUtil.encodePath(path));
4459        method.setDebug(debug);
4460        method.setFollowRedirects(this.followRedirects);
4461
4462        generateIfHeader(method);
4463        generateTransactionHeader(method);
4464        method.setLockToken(lock);
4465        int statusCode = client.executeMethod(method);
4466
4467        setStatusCode(statusCode);
4468        if (statusCode >= 200 && statusCode < 300) {
4469            state.removeLocks(path);
4470            return true;
4471        }
4472
4473        return false;
4474    }
4475
4476
4477    /**
4478     * Discover and refresh lock tokens.
4479     *
4480     * @exception HttpException
4481     * @exception IOException
4482     */

4483    public void discoverOwnLocks()
4484    throws HttpException, IOException JavaDoc {
4485
4486        setClient();
4487        String JavaDoc owner = (httpURL.getUser() != null) ?
4488            httpURL.getUser() : defaultOwner;
4489
4490        WebdavState state = (WebdavState) client.getState();
4491        state = discoverLock(owner, httpURL.getPath(), state);
4492        client.setState(state);
4493    }
4494
4495
4496    /**
4497     * Discover and refresh lock tokens for a specific owner.
4498     *
4499     * @param owner the owner who's locks are to be discovered.
4500     * @exception HttpException
4501     * @exception IOException
4502     */

4503    public void discoverOwnLocks(String JavaDoc owner)
4504    throws HttpException, IOException JavaDoc {
4505
4506        setClient();
4507
4508        WebdavState state = (WebdavState) client.getState();
4509        state = discoverLock(owner, httpURL.getPath(), state);
4510        client.setState(state);
4511    }
4512
4513
4514    /**
4515     * Discover the given owner and locktoken and set the locktoken
4516     *
4517     * @param owner the activelock owner
4518     * @param path the server relative path of the resource to request
4519     * @param state the state to save the locktoken
4520     * @return state probably having lock information renewly
4521     */

4522    protected WebdavState discoverLock(String JavaDoc owner, String JavaDoc path,
4523                                       WebdavState state) {
4524        try {
4525            lockDiscovery=lockDiscoveryPropertyFindMethod(path);
4526        } catch (Exception JavaDoc e) {
4527            return state;
4528        }
4529
4530
4531        if (lockDiscovery == null) return state;
4532        Lock[] activeLocks = lockDiscovery.getActiveLocks();
4533
4534        if (activeLocks == null) return state;
4535        for (int i = 0; i < activeLocks.length; i++) {
4536            String JavaDoc activeLockOwner = activeLocks[i].getOwner();
4537            if (activeLockOwner.equals(owner)) {
4538                String JavaDoc locktoken = activeLocks[i].getLockToken();
4539                state.addLock(path, locktoken);
4540            }
4541        }
4542        return state;
4543    }
4544
4545
4546    /**
4547     * Update this resource to the specified target
4548     *
4549     * @param target the path of the history element to update this resource
4550     * from
4551     * @return true if the method has succeeded
4552     * @exception HttpException
4553     * @exception IOException
4554     */

4555    public boolean updateMethod(String JavaDoc target)
4556        throws HttpException, IOException JavaDoc {
4557
4558        return updateMethod(httpURL.getPath(), target);
4559    }
4560
4561
4562    /**
4563     * Update the specified resource to the specified target
4564     *
4565     * @param path the server relative path of the resource to update
4566     * @param target path of the target to update from (history resource)
4567     * @return true if the method has succeeded
4568     * @exception HttpException
4569     * @exception IOException
4570     */

4571    public boolean updateMethod(String JavaDoc path, String JavaDoc target)
4572        throws HttpException, IOException JavaDoc {
4573
4574        setClient();
4575        UpdateMethod method = new UpdateMethod(URIUtil.encodePath(path),
4576                                               URIUtil.encodePath(target));
4577        method.setDebug(debug);
4578        method.setFollowRedirects(this.followRedirects);
4579
4580        generateIfHeader(method);
4581        generateTransactionHeader(method);
4582        int statusCode = client.executeMethod(method);
4583
4584        setStatusCode(statusCode);
4585
4586        return (statusCode >= 200 && statusCode < 300) ? true : false;
4587    }
4588
4589
4590    public boolean versionControlMethod(String JavaDoc path)
4591        throws HttpException, IOException JavaDoc {
4592
4593        setClient();
4594
4595        VersionControlMethod method = new VersionControlMethod(
4596                                            URIUtil.encodePath(path));
4597        method.setDebug(debug);
4598        method.setFollowRedirects(this.followRedirects);
4599        generateIfHeader(method);
4600        generateTransactionHeader(method);
4601        int statusCode = client.executeMethod(method);
4602
4603        setStatusCode(statusCode);
4604
4605        return (statusCode >= 200 && statusCode < 300) ? true : false;
4606    }
4607
4608
4609    public boolean versionControlMethod(String JavaDoc path, String JavaDoc target)
4610        throws HttpException, IOException JavaDoc {
4611
4612        setClient();
4613
4614        VersionControlMethod method = new VersionControlMethod(
4615                                     URIUtil.encodePath(path),
4616                                     URIUtil.encodePath(target));
4617        method.setDebug(debug);
4618        method.setFollowRedirects(this.followRedirects);
4619
4620        generateIfHeader(method);
4621        generateTransactionHeader(method);
4622        int statusCode = client.executeMethod(method);
4623
4624        setStatusCode(statusCode);
4625
4626        return (statusCode >= 200 && statusCode < 300) ? true : false;
4627    }
4628
4629
4630    /**
4631     * Execute the MKWORKSPACE method for this WebdavResource.
4632     *
4633     * @return true if the method is succeeded.
4634     * @exception HttpException
4635     * @exception IOException
4636     */

4637    public boolean mkWorkspaceMethod()
4638        throws HttpException, IOException JavaDoc {
4639
4640        boolean result = mkWorkspaceMethod(httpURL.getPath());
4641        if (result) refresh();
4642
4643        return result;
4644    }
4645
4646
4647    /**
4648     * Execute the MKCOL method for the given path.
4649     *
4650     * @param path the server relative path at which to create a new workspace
4651     * resource
4652     * @return true if the method is succeeded.
4653     * @exception HttpException
4654     * @exception IOException
4655     */

4656    public boolean mkWorkspaceMethod(String JavaDoc path)
4657        throws HttpException, IOException JavaDoc {
4658
4659        setClient();
4660        MkWorkspaceMethod method =
4661            new MkWorkspaceMethod(URIUtil.encodePath(path));
4662        method.setDebug(debug);
4663        method.setFollowRedirects(this.followRedirects);
4664        generateIfHeader(method);
4665        generateTransactionHeader(method);
4666        int statusCode = client.executeMethod(method);
4667
4668        // Possbile MKCOL Status Codes => SC_CREATED
4669
// WebdavStatus.SC_FORBIDDEN, SC_METHOD_NOT_ALLOWED, SC_CONFLICT,
4670
// SC_LOCKED, SC_UNSUPPORTED_MEDIA_TYPE, SC_INSUFFICIENT_STORAGE
4671

4672        setStatusCode(statusCode);
4673
4674        return (statusCode >= 200 && statusCode < 300) ? true : false;
4675    }
4676
4677
4678    // -------------------------------------------------------- Basic Methods
4679

4680
4681    /**
4682     * Compare to the WebdavResource object.
4683     *
4684     * @param another the other WebdavResource object
4685     * @return the value 0 if the argument is equal.
4686     */

4687    public int compareToWebdavResource(WebdavResource another) {
4688
4689        try {
4690            HttpURL anotherUrl = another.getHttpURL();
4691
4692            String JavaDoc thisHost = httpURL.getHost();
4693            String JavaDoc anotherHost= anotherUrl.getHost();
4694            if (!thisHost.equalsIgnoreCase(anotherHost))
4695                return thisHost.compareTo(anotherHost);
4696
4697            int thisPort = httpURL.getPort();
4698            int anotherPort= anotherUrl.getPort();
4699            if (thisPort != anotherPort)
4700                return (thisPort < anotherPort) ? -1 : 1;
4701
4702            boolean thisCollection = isCollection();
4703            boolean anotherCollection = another.isCollection();
4704            if (thisCollection && !anotherCollection)
4705                return -1;
4706            if (anotherCollection && !thisCollection)
4707                return 1;
4708
4709            String JavaDoc thisPath = httpURL.getPathQuery();
4710            String JavaDoc anotherPath= anotherUrl.getPathQuery();
4711            return thisPath.compareTo(anotherPath);
4712        } catch (Exception JavaDoc e) {
4713            // FIXME: not to return 0.
4714
}
4715
4716        return 0;
4717    }
4718
4719
4720    /**
4721     * Compare to the given another object.
4722     *
4723     * @param another the other WebdavResource object
4724     * @return the value 0 if another is equal.
4725     */

4726    public int compareTo(Object JavaDoc another) {
4727
4728        if ((another != null) && (another instanceof WebdavResource)) {
4729            return compareToWebdavResource((WebdavResource) another);
4730        }
4731
4732        String JavaDoc thisUrl = toString();
4733        String JavaDoc anotherUrl = another.toString();
4734
4735        return thisUrl.compareTo(anotherUrl);
4736    }
4737
4738
4739    /**
4740     * Test the object.
4741     *
4742     * @param obj the other object
4743     * @return true if it's equal.
4744     */

4745    public boolean equals(Object JavaDoc obj) {
4746
4747        if ((obj != null) && (obj instanceof WebdavResource)) {
4748            return compareTo(obj) == 0;
4749        }
4750        return false;
4751    }
4752
4753
4754    /**
4755     * Return the http URL string.
4756     *
4757     * @return the http URL string.
4758     */

4759    public String JavaDoc toString() {
4760        return httpURL.toString();
4761    }
4762
4763
4764    /**
4765     * Execute the CHECKIN method for this WebdavResource.
4766     *
4767     * @return true if the method is succeeded.
4768     * @exception HttpException
4769     * @exception IOException
4770     */

4771    public boolean checkinMethod()
4772        throws HttpException, IOException JavaDoc {
4773
4774        return checkinMethod(httpURL.getPath());
4775    }
4776
4777
4778    /**
4779     * Execute the CHECKIN method for the given path.
4780     *
4781     * @param path the server relative path of the resource to check in
4782     * @return true if the method is succeeded.
4783     * @exception HttpException
4784     * @exception IOException
4785     */

4786    public boolean checkinMethod(String JavaDoc path)
4787        throws HttpException, IOException JavaDoc {
4788
4789        setClient();
4790        CheckinMethod method = new CheckinMethod(URIUtil.encodePath(path));
4791        method.setDebug(debug);
4792        method.setFollowRedirects(this.followRedirects);
4793
4794        generateIfHeader(method);
4795        generateTransactionHeader(method);
4796        int statusCode = client.executeMethod(method);
4797
4798        setStatusCode(statusCode);
4799
4800        return (statusCode >= 200 && statusCode < 300) ? true : false;
4801    }
4802
4803
4804    /**
4805     * Execute the CHECKOUT method for this WebdavResource.
4806     *
4807     * @return true if the method is succeeded.
4808     * @exception HttpException
4809     * @exception IOException
4810     */

4811    public boolean checkoutMethod()
4812        throws HttpException, IOException JavaDoc {
4813
4814        return checkoutMethod(httpURL.getPath());
4815    }
4816
4817
4818    /**
4819     * Execute the CHECKOUT method for the given path.
4820     *
4821     * @param path the server relative path of the resource to check out
4822     * @return true if the method is succeeded.
4823     * @exception HttpException
4824     * @exception IOException
4825     */

4826    public boolean checkoutMethod(String JavaDoc path)
4827        throws HttpException, IOException JavaDoc {
4828
4829        setClient();
4830        CheckoutMethod method = new CheckoutMethod(URIUtil.encodePath(path));
4831        method.setDebug(debug);
4832        method.setFollowRedirects(this.followRedirects);
4833
4834        generateIfHeader(method);
4835        generateTransactionHeader(method);
4836        int statusCode = client.executeMethod(method);
4837
4838        setStatusCode(statusCode);
4839
4840        return (statusCode >= 200 && statusCode < 300) ? true : false;
4841    }
4842
4843
4844    /**
4845     * Execute the CHECKOUT method for this WebdavResource.
4846     *
4847     * @return true if the method is succeeded.
4848     * @exception HttpException
4849     * @exception IOException
4850     */

4851    public boolean uncheckoutMethod()
4852        throws HttpException, IOException JavaDoc {
4853
4854        return uncheckoutMethod(httpURL.getPath());
4855    }
4856
4857
4858
4859
4860    /**
4861     * Execute the CHECKOUT method for the given path.
4862     *
4863     * @param path the server relative path of the resource to act on
4864     * @return true if the method is succeeded.
4865     * @exception HttpException
4866     * @exception IOException
4867     */

4868    public boolean uncheckoutMethod(String JavaDoc path)
4869        throws HttpException, IOException JavaDoc {
4870
4871        setClient();
4872        UncheckoutMethod method =
4873            new UncheckoutMethod(URIUtil.encodePath(path));
4874        method.setDebug(debug);
4875        method.setFollowRedirects(this.followRedirects);
4876
4877        generateIfHeader(method);
4878        generateTransactionHeader(method);
4879        int statusCode = client.executeMethod(method);
4880
4881        setStatusCode(statusCode);
4882
4883        return (statusCode >= 200 && statusCode < 300) ? true : false;
4884    }
4885
4886    /**
4887     * Create a new WebdavResource object (as a seperate method so that it can
4888     * be overridden by subclasses.
4889     *
4890     * @param client HttpClient to be used by this webdavresource.
4891     * @return A new WebdavResource object.
4892     */

4893    protected WebdavResource createWebdavResource(HttpClient client) {
4894        WebdavResource resource = new WebdavResource(client);
4895        resource.setProxy(proxyHost, proxyPort);
4896        resource.setProxyCredentials(proxyCredentials);
4897        return resource;
4898    }
4899
4900    /**
4901     * Process a property, setting various member variables depending
4902     * on what the property is.
4903     *
4904     * @param property The property to process.
4905     */

4906    protected void processProperty(Property property) {
4907        if (property.getLocalName().equals(DISPLAYNAME)) {
4908            displayName = property.getPropertyAsString();
4909        }
4910        else if (property.getLocalName().equals(GETCONTENTLENGTH)) {
4911            String JavaDoc getContentLength = property.getPropertyAsString();
4912            setGetContentLength(getContentLength);
4913        }
4914        else if (property.getLocalName().equals(RESOURCETYPE)) {
4915            ResourceTypeProperty resourceType =
4916                (ResourceTypeProperty) property;
4917            setResourceType(resourceType);
4918        }
4919        else if (property.getLocalName().equals(GETCONTENTTYPE)) {
4920            String JavaDoc getContentType = property.getPropertyAsString();
4921            setGetContentType(getContentType);
4922        }
4923        else if (property.getLocalName().equals(GETLASTMODIFIED)) {
4924            String JavaDoc getLastModified = property.getPropertyAsString();
4925            setGetLastModified(getLastModified);
4926        }
4927        else if (property.getLocalName().equals(CREATIONDATE)) {
4928            String JavaDoc creationDate = property.getPropertyAsString();
4929            setCreationDate(creationDate);
4930        }
4931        else if (property.getLocalName().equals(GETETAG)) {
4932            String JavaDoc getEtag = property.getPropertyAsString();
4933            setGetEtag(getEtag);
4934        }
4935        else if (property.getLocalName().equals(ISHIDDEN)) {
4936            String JavaDoc isHidden = property.getPropertyAsString();
4937            setIsHidden(isHidden);
4938        }
4939        else if (property.getLocalName().equals(ISCOLLECTION)) {
4940            String JavaDoc isCollection = property.getPropertyAsString();
4941            setIsCollection(isCollection);
4942        }
4943        else if (property.getLocalName().equals(SUPPORTEDLOCK)) {
4944            String JavaDoc supportedLock = property.getPropertyAsString();
4945            setSupportedLock(supportedLock);
4946        }
4947        else if (property.getLocalName().equals(LOCKDISCOVERY)) {
4948            LockDiscoveryProperty lockDiscovery =
4949                (LockDiscoveryProperty) property;
4950            setLockDiscovery(lockDiscovery);
4951        }
4952    }
4953
4954
4955    /**
4956     * Execute REPORT method.
4957     * This method is for the special Access Control Reports:
4958     * - acl-principal-prop-set (not supported yet)
4959     * - principal-match (not supported yet)
4960     * - principal-property-search
4961     * - principal-search-property-set (not supported yet)
4962     *
4963     * @param path the server relative path of the resource to request
4964     * @param properties The named properties.
4965     * @return an enumeration of <code>ResponseEntity</code>
4966     * @exception HttpException
4967     * @exception IOException
4968     */

4969    public Enumeration JavaDoc aclReportMethod(
4970        String JavaDoc path,
4971        Collection JavaDoc properties,
4972        int reportType)
4973        throws HttpException, IOException JavaDoc {
4974
4975        setClient();
4976        AclReportMethod method =
4977            new AclReportMethod(
4978                URIUtil.encodePath(path),
4979                properties,
4980                DepthSupport.DEPTH_INFINITY,
4981                reportType);
4982
4983        method.setDebug(debug);
4984        method.setFollowRedirects(this.followRedirects);
4985        generateTransactionHeader(method);
4986        int status = client.executeMethod(method);
4987
4988        // Set status code for this resource.
4989
if (thisResource == true) {
4990            // Set the status code.
4991
setStatusCode(method.getStatusLine().getStatusCode());
4992        }
4993
4994        //slide/tamino delivers status code OK.
4995
//can be removed when the server sends MULTI_STATUS
4996
if (status != HttpStatus.SC_MULTI_STATUS && status != HttpStatus.SC_OK) {
4997            HttpException ex = new HttpException();
4998            ex.setReasonCode(status);
4999            throw ex;
5000        }
5001        thisResource = false;
5002
5003        return method.getResponses();
5004    }
5005
5006
5007    /**
5008     * Execute the BIND method for this WebdavResource, given
5009     * an existing path to bind with.
5010     *
5011     * @param newBinding the new binding as a server relative path
5012     * @return true if the method is succeeded.
5013     * @exception HttpException
5014     * @exception IOException
5015     * @see #setOverwrite(boolean)
5016     */

5017    public boolean bindMethod(String JavaDoc newBinding)
5018        throws HttpException, IOException JavaDoc {
5019        return bindMethod(httpURL.getPath(), newBinding);
5020    }
5021
5022    /**
5023     * Execute the BIND method given the new path to bind to an existing path.
5024     *
5025     * @param existingBinding the existing binding as a server relative path
5026     * @param newBinding the new binding as a server relative path
5027     * @return true if the method is succeeded.
5028     * @exception HttpException
5029     * @exception IOException
5030     * @see #setOverwrite(boolean)
5031     */

5032    public boolean bindMethod(String JavaDoc existingBinding, String JavaDoc newBinding)
5033        throws HttpException, IOException JavaDoc {
5034
5035        setClient();
5036        BindMethod method =
5037            new BindMethod(URIUtil.encodePath(existingBinding),
5038                           URIUtil.encodePath(newBinding));
5039        method.setDebug(debug);
5040        method.setOverwrite(overwrite);
5041        generateTransactionHeader(method);
5042        int statusCode = client.executeMethod(method);
5043
5044        // Possbile BIND Status Codes => SC_CREATED, SC_NO_CONTENT
5045
// SC_FORBIDDEN, SC_CONFLICT, SC_PRECONDITION_FAILED,
5046
// SC_LOCKED, SC_BAD_GATEWAY, SC_INSUFFICIENT_STORAGE,
5047
// SC_LOOP_DETECTED
5048
setStatusCode(statusCode);
5049        return statusCode >= 200 && statusCode < 300;
5050    }
5051
5052    /**
5053     * Execute the UNBIND method for this WebdavResource.
5054     *
5055     * @return true if the method is succeeded.
5056     * @exception HttpException
5057     * @exception IOException
5058     */

5059    public boolean unbindMethod() throws HttpException, IOException JavaDoc {
5060        boolean result = unbindMethod(httpURL.getPath());
5061        if (result) {
5062            setExistence(false);
5063        }
5064
5065        return result;
5066    }
5067
5068    /**
5069     * Execute the UNBIND method given the resource to Unbind.
5070     *
5071     * @param binding the server relative path of the resource to unbind
5072     * @return true if the method is succeeded.
5073     * @exception HttpException
5074     * @exception IOException
5075     */

5076    public boolean unbindMethod(String JavaDoc binding)
5077        throws HttpException, IOException JavaDoc {
5078
5079        setClient();
5080        UnbindMethod method =
5081            new UnbindMethod(URIUtil.encodePath(binding));
5082        method.setDebug(debug);
5083        generateTransactionHeader(method);
5084        int statusCode = client.executeMethod(method);
5085
5086        // Possbile BIND Status Codes => SC_CREATED, SC_NOT_FOUND
5087
// WebdavStatus.SC_FORBIDDEN, SC_CONFLICT, SC_PRECONDITION_FAILED,
5088
// SC_LOCKED, SC_BAD_GATEWAY
5089
setStatusCode(statusCode);
5090        return statusCode >= 200 && statusCode < 300;
5091    }
5092
5093    /**
5094     * Execute the Rebind method for this WebdavResource given the new
5095     * Resource to bind with.
5096     * The REBIND method removes a binding to a resource from one collection,
5097     * and adds a binding to that resource into another collection. It is
5098     * effectively an atomic form of a MOVE request.
5099     *
5100     * @param newBinding the new binding as a server relative path
5101     * @return true if the method is succeeded.
5102     * @exception HttpException
5103     * @exception IOException
5104     * @see #setOverwrite(boolean)
5105     */

5106    public boolean rebindMethod(String JavaDoc newBinding)
5107        throws HttpException, IOException JavaDoc {
5108        boolean result = rebindMethod(httpURL.getPath(), newBinding);
5109        if (result) {
5110            httpURL.setPath(newBinding);
5111            refresh();
5112        }
5113
5114        return result;
5115    }
5116
5117    /**
5118     * Execute the Rebind method given a resource to rebind and the new
5119     * Resource to bind with.
5120     * The REBIND method removes a binding to a resource from one collection,
5121     * and adds a binding to that resource into another collection. It is
5122     * effectively an atomic form of a MOVE request
5123     *
5124     * @param existingBinding the existing binding as a server relative path
5125     * @param newBinding the new binding as a server relative path
5126     * @return true if the method is succeeded.
5127     * @exception HttpException
5128     * @exception IOException
5129     * @see #setOverwrite(boolean)
5130     */

5131    public boolean rebindMethod(String JavaDoc existingBinding, String JavaDoc newBinding)
5132        throws HttpException, IOException JavaDoc {
5133
5134        setClient();
5135        RebindMethod method =
5136            new RebindMethod(URIUtil.encodePath(existingBinding),
5137                             URIUtil.encodePath(newBinding));
5138        method.setDebug(debug);
5139        method.setOverwrite(overwrite);
5140        generateTransactionHeader(method);
5141        int statusCode = client.executeMethod(method);
5142
5143        // Possbile BIND Status Codes => SC_CREATED, SC_NO_CONTENT
5144
// WebdavStatus.SC_FORBIDDEN, SC_CONFLICT, SC_PRECONDITION_FAILED,
5145
// SC_LOCKED, SC_BAD_GATEWAY, SC_INSUFFICIENT_STORAGE,
5146
// SC_LOOP_DETECTED
5147
setStatusCode(statusCode);
5148        return statusCode >= 200 && statusCode < 300;
5149    }
5150
5151    /**
5152     * Subscribes for notifications for modifications of WebDAV resources.
5153     *
5154     * @param path URL path of the resource that is to be subscribed
5155     * @param notificationType
5156     * @param callback the URL to be registered for notification, may be
5157     * <code>null</code> if no callback shall be registered.
5158     * @param notificationDelay
5159     * @param depth the depth of the subscription (for valid values see
5160     * {@link DepthSupport})
5161     * @param lifetime duration of that subscription in seconds (Note: the
5162     * server may change this and return an other one;
5163     * see {@link Subscription#getLifetime()}.
5164     *
5165     * @return a {@link Subscription} or <code>null</code> if an error occurs
5166     * @throws HttpException
5167     * @throws IOException
5168     */

5169    public Subscription subscribeMethod(String JavaDoc path,
5170          String JavaDoc notificationType,
5171          String JavaDoc callback,
5172          long notificationDelay,
5173          int depth,
5174          long lifetime)
5175       throws HttpException, IOException JavaDoc
5176    {
5177       setClient();
5178       
5179       SubscribeMethod method = new SubscribeMethod(path);
5180       method.setDebug(debug);
5181       method.setFollowRedirects(this.followRedirects);
5182
5183       method.setCallback(callback);
5184       method.setDepth(depth);
5185       method.setSubsciptionLifetime(lifetime);
5186       method.setNotificationType(notificationType);
5187       method.setNotificationDelay(notificationDelay);
5188       generateTransactionHeader(method);
5189       
5190       int statusCode = client.executeMethod(method);
5191       
5192       if (statusCode == HttpStatus.SC_OK) {
5193          return new Subscription(
5194                      path,
5195                      method.getResponsedSubscriptionId(),
5196                      method.getCallback(),
5197                      method.getResponsedSubscriptionLifetime(),
5198                      method.getResponsedContentLocation(),
5199                      method.getNotificationType()
5200                );
5201       } else {
5202          return null;
5203       }
5204    }
5205    
5206    /**
5207     * Refreshes a subscription.
5208     *
5209     * @return <code>true</code> on success.
5210     */

5211    public boolean subscribeMethod(String JavaDoc path, int subscriptionId)
5212       throws HttpException, IOException JavaDoc
5213    {
5214       setClient();
5215       
5216       SubscribeMethod method = new SubscribeMethod(path);
5217       method.setDebug(debug);
5218       method.setFollowRedirects(this.followRedirects);
5219       
5220       method.setSubscriptionId(subscriptionId);
5221       generateTransactionHeader(method);
5222       
5223       int statusCode = client.executeMethod(method);
5224       
5225       if (statusCode == HttpStatus.SC_OK) {
5226          return true;
5227       } else {
5228          return false;
5229       }
5230    }
5231    
5232    /**
5233     * Refreshes a subscription.
5234     *
5235     * @param subscription The subscription to be refreshed.
5236     * @return <code>true</code> on success
5237     */

5238    public boolean subscribeMethod(Subscription subscription)
5239       throws HttpException, IOException JavaDoc
5240    {
5241       return subscribeMethod(subscription.getPath(), subscription.getId());
5242    }
5243    
5244    /**
5245     * Cancels a subscription.
5246     * @param path URL path for that was subscribed
5247     * @return <code>true</code> on success
5248     */

5249    public boolean unsubscribeMethod(String JavaDoc path, int subscriptionId)
5250       throws HttpException, IOException JavaDoc
5251    {
5252       setClient();
5253       
5254       UnsubscribeMethod method = new UnsubscribeMethod(path);
5255       method.setDebug(debug);
5256       method.setFollowRedirects(this.followRedirects);
5257       
5258       method.addSubscriptionId(subscriptionId);
5259       generateTransactionHeader(method);
5260       
5261       int statusCode = client.executeMethod(method);
5262       
5263       if (statusCode == HttpStatus.SC_OK) {
5264          return true;
5265       } else {
5266          return false;
5267       }
5268    }
5269    /**
5270     * Cancels a subscription.
5271     * @param subscription
5272     * @return <code>true</code> on success
5273     */

5274    public boolean unsubscribeMethod(Subscription subscription)
5275       throws HttpException, IOException JavaDoc
5276    {
5277       return unsubscribeMethod(subscription.getPath(),subscription.getId());
5278    }
5279    
5280    /**
5281     * Asks the server whether events for a given subscription are fired.
5282     * @param contentLocation URL path returned by the SUBSCRIBE methods
5283     * Content-Location header
5284     * @param subscriptionId id of the subscription
5285     * @return <code>true</code> if an event was fired
5286     */

5287    public boolean pollMethod(String JavaDoc contentLocation, int subscriptionId)
5288       throws HttpException, IOException JavaDoc
5289    {
5290       setClient();
5291       
5292       PollMethod method = new PollMethod(contentLocation);
5293       method.setDebug(debug);
5294       method.setFollowRedirects(this.followRedirects);
5295       
5296       method.addSubscriptionId(subscriptionId);
5297       generateTransactionHeader(method);
5298       
5299       int statusCode = client.executeMethod(method);
5300       
5301       if (statusCode == HttpStatus.SC_MULTI_STATUS) {
5302          return method.getSubscriptionsWithEvents().size() > 0;
5303       } else {
5304          return false;
5305       }
5306    }
5307    /**
5308     * Asks the server whether events for a given subscription are fired.
5309     * @param subscription the subscription to ask for
5310     * @return <code>true</code> if an event was fired
5311     */

5312    public boolean pollMethod(Subscription subscription)
5313       throws HttpException, IOException JavaDoc
5314    {
5315       return pollMethod(subscription.getContentLocation(), subscription.getId());
5316    }
5317
5318    
5319    
5320    private static String JavaDoc getName(String JavaDoc uri) {
5321        String JavaDoc escapedName = URIUtil.getName(
5322            uri.endsWith("/") ? uri.substring(0, uri.length() - 1): uri);
5323        try {
5324            return URIUtil.decode(escapedName);
5325        } catch (URIException e) {
5326            return escapedName;
5327        }
5328    }
5329
5330    /**
5331     * Unescape octets for some characters that a server might (but should not)
5332     * have escaped. These are: "-", "_", ".", "!", "~", "*", "'", "(", ")"
5333     * Look at section 2.3 of RFC 2396.
5334     */

5335    private static String JavaDoc decodeMarks(String JavaDoc input) {
5336        char[] sequence = input.toCharArray();
5337        StringBuffer JavaDoc decoded = new StringBuffer JavaDoc(sequence.length);
5338        for (int i = 0; i < sequence.length; i++) {
5339            if (sequence[i] == '%' && i < sequence.length - 2) {
5340                switch (sequence[i + 1]) {
5341                case '2':
5342                    switch (sequence[i + 2]) {
5343                    case 'd':
5344                    case 'D':
5345                        decoded.append('-');
5346                        i += 2;
5347                        continue;
5348                    case 'e':
5349                    case 'E':
5350                        decoded.append('.');
5351                        i += 2;
5352                        continue;
5353                    case '1':
5354                        decoded.append('!');
5355                        i += 2;
5356                        continue;
5357                    case 'a':
5358                    case 'A':
5359                        decoded.append('*');
5360                        i += 2;
5361                        continue;
5362                    case '7':
5363                        decoded.append('\'');
5364                        i += 2;
5365                        continue;
5366                    case '8':
5367                        decoded.append('(');
5368                        i += 2;
5369                        continue;
5370                    case '9':
5371                        decoded.append(')');
5372                        i += 2;
5373                        continue;
5374                    }
5375                    break;
5376                case '5':
5377                    switch (sequence[i + 2]) {
5378                    case 'f':
5379                    case 'F':
5380                        decoded.append('_');
5381                        i += 2;
5382                        continue;
5383                    }
5384                    break;
5385                case '7':
5386                    switch (sequence[i + 2]) {
5387                    case 'e':
5388                    case 'E':
5389                        decoded.append('~');
5390                        i += 2;
5391                        continue;
5392                    }
5393                    break;
5394                }
5395            }
5396            decoded.append(sequence[i]);
5397        }
5398        return decoded.toString();
5399    }
5400}
5401
Popular Tags