KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > webdav > client > WebDAVFileSystem


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.webdav.client;
20
21 import java.io.*;
22 import java.net.*;
23 import java.net.URI JavaDoc;
24 import java.rmi.*;
25 import java.util.*;
26
27 import javax.xml.rpc.*;
28
29 import org.openharmonise.commons.xml.*;
30 import org.openharmonise.commons.xml.namespace.*;
31 import org.openharmonise.vfs.*;
32 import org.openharmonise.vfs.authentication.*;
33 import org.openharmonise.vfs.metadata.*;
34 import org.openharmonise.vfs.metadata.range.*;
35 import org.openharmonise.vfs.search.*;
36 import org.openharmonise.vfs.status.*;
37 import org.openharmonise.webdav.client.methods.*;
38 import org.openharmonise.webdav.client.methods.Lock;
39 import org.openharmonise.webdav.client.methods.bind.*;
40 import org.openharmonise.webdav.client.methods.dasl.*;
41 import org.openharmonise.webdav.client.methods.deltav.*;
42 import org.openharmonise.webdav.client.methods.order.*;
43 import org.openharmonise.webdav.client.value.*;
44 import org.openharmonise.webdav.client.webservice.*;
45 import org.w3c.dom.*;
46
47 import sun.misc.*;
48 import HTTPClient.*;
49
50
51 /**
52  * WebDAV implementation of the VirtualFileSystem.
53  *
54  * @author Matthew Large
55  * @version $Revision: 1.4 $
56  *
57  */

58 public class WebDAVFileSystem extends AbstractVersioningVFS implements AuthorizationHandler {
59     
60     /**
61      * Connection to WebDAV server.
62      */

63     private WebDAVConnection m_conn = null;
64     
65     /**
66      * Virtual file system view.
67      */

68     private VirtualFileSystemView m_vfView = null;
69     
70     /**
71      * Virtual file cache.
72      */

73     private VirtualFileCache m_cache = null;
74     
75     /**
76      * List of virtual files locked whie being populated.
77      */

78     private ArrayList m_aPopulateLockedPaths = new ArrayList();
79
80     /**
81      * Constructs new WebDAV virtual file system.
82      *
83      * @param uri Location for virtual file system
84      */

85     public WebDAVFileSystem(URI JavaDoc uri) {
86         super(uri);
87         this.setup();
88     }
89
90     /**
91      * Constructs new WebDAV virtual file system.
92      *
93      * @param uri Location for virtual file system
94      * @param authInfo Authentication information for accessing virtual file system
95      */

96     public WebDAVFileSystem(URI JavaDoc uri, AuthInfo authInfo) {
97         super(uri, authInfo);
98         this.setup();
99     }
100
101     /**
102      * Constructs new WebDAV virtual file system.
103      *
104      * @param uri Location for virtual file system
105      * @param authStore Authentication store containing information for accessing virtual file system
106      */

107     public WebDAVFileSystem(URI JavaDoc uri, AbstractAuthenticationStore authStore) {
108         super(uri, authStore);
109         this.setup();
110     }
111     
112     /**
113      * Uses the uri to create a connection to the WebDAV server. Creates
114      * the virtual file cache and sets up the authentication information.
115      *
116      */

117     private void setup() {
118         URI JavaDoc uri = this.getURI();
119         try {
120             m_conn = new WebDAVConnection( this,uri.getScheme(), uri.getHost(), uri.getPort() );
121             
122         } catch (ProtocolNotSuppException e) {
123             e.printStackTrace();
124         }
125         
126         this.m_cache = new VirtualFileCache();
127         AuthorizationInfo.setAuthHandler(this);
128     }
129
130     /* (non-Javadoc)
131      * @see com.simulacramedia.contentmanager.vfs.AbstractVersioningVFS#checkoutImplVirtualFile(java.lang.String)
132      */

133     public StatusData checkoutVirtualFile(String JavaDoc sFullPath) {
134         VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
135         retnStatus.setMethodName(VirtualFile.METHOD_CHECKOUT);
136         
137         String JavaDoc sPath = this.getInitialPath() + sFullPath;
138         
139         VirtualFile vfFile = this.getVirtualFile(sFullPath).getResource();
140
141         if(vfFile.isDirectory()) {
142             sPath = sPath + "/";
143         }
144         Checkout method = new Checkout(sPath);
145         
146         if(vfFile.isLocked()) {
147             String JavaDoc sTokenPath = WebDAVConnection.URLEncode( vfFile.getFullPath() );
148             if(vfFile.isDirectory()) {
149                 sTokenPath = sTokenPath + "/";
150             }
151             method.addHeader("If", "<" + sTokenPath + "> (<" + vfFile.getLockToken() + ">)");
152         }
153         try {
154             WebDAVResponse response = this.m_conn.execute(method);
155
156             retnStatus.setHTTPStatus(response.getStatusCode());
157             
158             if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
159                 retnStatus.setHTTPStatus(response.getStatusCode());
160                 this.fireErrorEvent("FileNotCheckedOut", "The file " + sFullPath + " cannot be checked out.");
161             } else {
162                 if(vfFile.getState().equals(VirtualFile.STATE_HISTORICAL)) {
163                     this.m_cache.removeFile(((VersionedVirtualFile)vfFile).getLiveVersionPath());
164                 } else if(vfFile.getState().equals(VirtualFile.STATE_LIVE)) {
165                     String JavaDoc sCheckedOutPath = response.getHeader("Location");
166                     if(sCheckedOutPath==null || sCheckedOutPath.equals("")) {
167                         retnStatus.setStatusCode(StatusData.STATUS_RESOURCE_NOT_FOUND);
168                         retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
169                     } else {
170                         this.setFilePendingVersionPath((VersionedVirtualFile) vfFile, sCheckedOutPath);
171                     }
172                 } else {
173                     retnStatus.setStatusCode(StatusData.STATUS_INVALID_RESOURCE_STATE);
174                     retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
175                 }
176             }
177             
178         } catch (IOException e) {
179             e.printStackTrace();
180             retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
181             retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
182             this.fireErrorEvent("FileNotCheckedOut", "The file " + sFullPath + " cannot be checked out.");
183         } catch (ModuleException e) {
184             e.printStackTrace();
185             retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
186             retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
187             this.fireErrorEvent("FileNotCheckedOut", "The file " + sFullPath + " cannot be checked out.");
188         }
189
190         return retnStatus;
191     }
192
193     /* (non-Javadoc)
194      * @see com.simulacramedia.contentmanager.vfs.AbstractVersioningVFS#uncheckoutImplVirtualFile(java.lang.String)
195      */

196     public StatusData uncheckoutVirtualFile(String JavaDoc sPath) {
197
198         return null;
199     }
200
201     /* (non-Javadoc)
202      * @see com.simulacramedia.contentmanager.vfs.AbstractVersioningVFS#checkinImplVirtualFile(java.lang.String)
203      */

204     public StatusData checkinVirtualFile(String JavaDoc sFullPath) {
205         VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
206         retnStatus.setMethodName(VirtualFile.METHOD_CHECKIN);
207         
208         VersionedVirtualFile vfFile = (VersionedVirtualFile) this.getVirtualFile(sFullPath).getResource();
209         if(vfFile.getState().equals(VirtualFile.STATE_PENDING)) {
210             if(vfFile.isChanged()) {
211                 this.synchroniseFile(vfFile);
212             }
213             vfFile = (VersionedVirtualFile) this.getVirtualFile(sFullPath).getResource();
214             if(vfFile.getLiveVersionPath()==null) {
215                 String JavaDoc sPath = this.getInitialPath() + sFullPath;
216                 if(vfFile.isDirectory()) {
217                     sPath = sPath + "/";
218                 }
219         
220                 VersionControl method = new VersionControl(sPath);
221         
222                 if(vfFile.isLocked()) {
223                     String JavaDoc sTokenPath = WebDAVConnection.URLEncode( vfFile.getFullPath() );
224                     if(vfFile.isDirectory()) {
225                         sTokenPath = sTokenPath + "/";
226                     }
227                     method.addHeader("If", "<" + sTokenPath + "> (<" + vfFile.getLockToken() + ">)");
228                 }
229                 try {
230                     WebDAVResponse response = this.m_conn.execute(method);
231                     retnStatus.setHTTPStatus(response.getStatusCode());
232                     
233                     if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
234                         this.fireErrorEvent("FileNotCheckedin", "The file " + sPath + " cannot be checked in.");
235                     } else {
236                         StatusData unlockStatus = this.unlockVirtualFile(sFullPath);
237                         retnStatus.addStatusData(unlockStatus);
238                         this.m_cache.removeFile(sFullPath);
239                         if(vfFile.getLiveVersionPath()!=null) {
240                             this.m_cache.removeFile(vfFile.getLiveVersionPath());
241                         }
242                     }
243                 } catch (IOException e) {
244                     e.printStackTrace();
245                     retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
246                     retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
247                     this.fireErrorEvent("FileNotCheckedin", "The file " + sPath + " cannot be checked in.");
248                 } catch (ModuleException e) {
249                     e.printStackTrace();
250                     retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
251                     retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
252                     this.fireErrorEvent("FileNotCheckedin", "The file " + sPath + " cannot be checked in.");
253                 }
254             } else {
255                 String JavaDoc sPath = this.getInitialPath() + sFullPath;
256                 String JavaDoc sLivePath = vfFile.getLiveVersionPath();
257         
258                 Checkin method = new Checkin(sPath);
259                 if(vfFile.isLocked()) {
260                     String JavaDoc sTokenPath = WebDAVConnection.URLEncode( vfFile.getFullPath() );
261                     if(vfFile.isDirectory()) {
262                         sTokenPath = sTokenPath + "/";
263                     }
264                     method.addHeader("If", "<" + sTokenPath + "> (<" + vfFile.getLockToken() + ">)");
265                 }
266                 try {
267                     WebDAVResponse response = this.m_conn.execute(method);
268                     retnStatus.setHTTPStatus(response.getStatusCode());
269         
270                     if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
271                         this.fireErrorEvent("FileNotCheckedin", "The file " + sPath + " cannot be checked in.");
272                     } else {
273                         StatusData unlockStatus = this.unlockVirtualFile(sLivePath);
274                         retnStatus.addStatusData(unlockStatus);
275                         this.m_cache.removeFile(sFullPath);
276                         this.m_cache.removeFile(vfFile.getLiveVersionPath());
277                     }
278                 } catch (IOException e) {
279                     e.printStackTrace();
280                     retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
281                     retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
282                     this.fireErrorEvent("FileNotCheckedin", "The file " + sPath + " cannot be checked in.");
283                 } catch (ModuleException e) {
284                     e.printStackTrace();
285                     retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
286                     retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
287                     this.fireErrorEvent("FileNotCheckedin", "The file " + sPath + " cannot be checked in.");
288                 }
289                 
290                 
291             }
292         } else {
293             retnStatus.setStatusCode(StatusData.STATUS_INVALID_RESOURCE_STATE);
294             retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
295         }
296         return retnStatus;
297     }
298
299     /* (non-Javadoc)
300      * @see com.simulacramedia.contentmanager.vfs.AbstractVersioningVFS#tagImplVirtualFile(java.lang.String)
301      */

302     public StatusData tagVirtualFile(String JavaDoc sPath, String JavaDoc sTag) {
303         VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
304         retnStatus.setMethodName(VirtualFile.METHOD_TAG);
305         
306         sPath = this.getInitialPath() + sPath;
307         
308         Label method = new Label(sPath);
309         method.setLabel(sTag);
310         try {
311             WebDAVResponse response = this.m_conn.execute(method);
312             retnStatus.setHTTPStatus(response.getStatusCode());
313         
314             if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
315                 this.fireErrorEvent("FileNotTagged", "The file " + sPath + " cannot be tagged.");
316             }
317         } catch (IOException e) {
318             e.printStackTrace();
319             retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
320             retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
321             this.fireErrorEvent("FileNotTagged", "The file " + sPath + " cannot be tagged.");
322         } catch (ModuleException e) {
323             e.printStackTrace();
324             retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
325             retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
326             this.fireErrorEvent("FileNotTagged", "The file " + sPath + " cannot be tagged.");
327         }
328
329         return retnStatus;
330     }
331
332     /* (non-Javadoc)
333      * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#getImplOptions()
334      */

335     public List getOptions() {
336         return null;
337     }
338
339     /* (non-Javadoc)
340      * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#getImplVirtualFile(java.lang.String)
341      */

342     public ResourceStatusWrapper getVirtualFile(String JavaDoc sPath) {
343         ArrayList aProps = new ArrayList();
344         PropFindProperty prop = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "resourcetype" );
345         aProps.add(prop);
346         prop = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "lockdiscovery" );
347         aProps.add(prop);
348         prop = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "creationdate" );
349         aProps.add(prop);
350         prop = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "getlastmodified" );
351         aProps.add(prop);
352         prop = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "getcontenttype" );
353         aProps.add(prop);
354         prop = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "checked-in" );
355         aProps.add(prop);
356         prop = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "checked-out" );
357         aProps.add(prop);
358         prop = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "checkout-set" );
359         aProps.add(prop);
360         prop = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "successor-set" );
361         aProps.add(prop);
362         prop = new PropFindProperty( NamespaceType.OHRM.getURI(), "title" );
363         aProps.add(prop);
364         prop = new PropFindProperty( NamespaceType.OHRM.getURI(), "harmonise-id" );
365         aProps.add(prop);
366         
367         return this.getVirtualFile(sPath, aProps);
368     }
369
370     /**
371      * This method will return either the Virtual File that was
372      * requested by the path or a new blank file initialised to that path.
373      *
374      * @param sPath Full path to the requested file
375      * @param aProps Properties to be populated in the file
376      * @return
377      */

378     public ResourceStatusWrapper getVirtualFile(String JavaDoc sPath, List aProps) {
379         VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
380         retnStatus.setMethodName(VirtualFile.METHOD_GET);
381         VirtualFile vfFile = null;
382         
383         String JavaDoc sRealPath = this.getInitialPath() + sPath;
384         
385         if( this.m_cache.hasFile(sPath) ) {
386             vfFile = this.m_cache.getFile(sPath);
387         } else {
388             PropFind method = new PropFind(sRealPath);
389             method.setDepth( PropFind.DEPTH_1 );
390             
391             Iterator itor = aProps.iterator();
392             while (itor.hasNext()) {
393                 PropFindProperty element = (PropFindProperty) itor.next();
394                 method.addProperty(element.getNamespaceURI(), element.getName());
395             }
396             
397             try {
398                 WebDAVResponse response = this.m_conn.execute(method);
399                 retnStatus.setHTTPStatus(response.getStatusCode());
400                 if(response==null) {
401                     response = this.m_conn.execute(method);
402                 }
403                 vfFile = this.getVirtualFile(response, sRealPath);
404         
405                 if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
406                     this.fireErrorEvent("FileNotFound", "The file " + sPath + " cannot be found.");
407                 }
408             } catch (IOException e) {
409                 retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
410                 retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
411                 this.fireErrorEvent("FileNotFound", "The file " + sPath + " cannot be found.");
412                 e.printStackTrace();
413             } catch (ModuleException e) {
414                 retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
415                 retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
416                 this.fireErrorEvent("FileNotFound", "The file " + sPath + " cannot be found.");
417                 e.printStackTrace();
418             }
419         }
420         
421         if(vfFile==null) {
422             this.fireErrorEvent("FileNotFound", "The file " + sPath + " cannot be found.");
423         } else {
424             
425         }
426
427         return new ResourceStatusWrapper(vfFile, retnStatus);
428     }
429     
430     protected void fullyPopulateFileMetadata(VirtualFile vfFile) {
431         
432         String JavaDoc sRealPath = this.getInitialPath() + vfFile.getFullPath();
433
434
435         if(vfFile.isDirectory()) {
436             sRealPath = sRealPath + "/";
437         }
438         PropFind method = new PropFind(sRealPath);
439         method.setDepth( PropFind.DEPTH_0 );
440         try {
441             WebDAVResponse response = this.m_conn.execute(method);
442             this.getVirtualFile(response, vfFile, sRealPath);
443         
444             if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
445                 this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
446             }
447             
448             this.setFileMetadataPopulated(vfFile, true);
449         } catch (IOException e) {
450             this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
451             e.printStackTrace();
452             this.setFileMetadataPopulated(vfFile, false);
453         } catch (ModuleException e) {
454             this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
455             e.printStackTrace();
456             this.setFileMetadataPopulated(vfFile, false);
457         }
458     }
459     
460     /**
461      * Populates the allowed file methods for a given file.
462      *
463      * @param vfFile Virtual file to populate
464      */

465     private void populateFileAllowedMethods(VirtualFile vfFile) {
466         String JavaDoc sRealPath = this.getInitialPath() + vfFile.getFullPath();
467         if(vfFile.isDirectory()) {
468             sRealPath = sRealPath + "/";
469         }
470         try {
471             this.clearFileAllowedMethods(vfFile);
472         } catch(Exception JavaDoc e) {
473             e.printStackTrace(System.err);
474         } finally {
475             try {
476                 HTTPResponse response = this.m_conn.Options(sRealPath);
477                 String JavaDoc sAllowValue = response.getHeader("Allow");
478                 if(sAllowValue!=null) {
479                     StringTokenizer sTok = new StringTokenizer(sAllowValue, ",");
480                     while(sTok.hasMoreTokens()) {
481                         String JavaDoc sValue = sTok.nextToken().trim();
482                         if(sValue.equals("PUT")) {
483                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_SYNC);
484                         } else if(sValue.equals("DELETE")) {
485                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_DELETE);
486                         } else if(sValue.equals("MOVE")) {
487                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_MOVE);
488                         } else if(sValue.equals("COPY")) {
489                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_COPY);
490                         } else if(sValue.equals("MKCOL")) {
491                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_MKDIR);
492                         } else if(sValue.equals("PROPPATCH")) {
493                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_SYNC);
494                         } else if(sValue.equals("LOCK")) {
495                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_LOCK);
496                         } else if(sValue.equals("UNLOCK")) {
497                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_UNLOCK);
498                         } else if(sValue.equals("BIND")) {
499                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_SHORTCUT);
500                         } else if(sValue.equals("ORDERPATCH")) {
501                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_SYNC);
502                         } else if(sValue.equals("CHECKIN")) {
503                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_CHECKIN);
504                         } else if(sValue.equals("CHECKOUT")) {
505                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_CHECKOUT);
506                         } else if(sValue.equals("VERSION-CONTROL")) {
507                             this.addFileAllowedMethod(vfFile, VirtualFile.METHOD_CHECKIN);
508                         }
509                     }
510                 }
511             
512             } catch (IOException e) {
513                 e.printStackTrace();
514             } catch (ModuleException e) {
515                 e.printStackTrace();
516             }
517         }
518     }
519     
520     protected void fullyPopulateFileChildren(VirtualFile vfFile) {
521         
522         String JavaDoc sRealPath = this.getInitialPath() + vfFile.getFullPath();
523
524         PropFind method = new PropFind(sRealPath);
525         method.setDepth( PropFind.DEPTH_1 );
526         method.addProperty( PropFind.WEBDAV_NAMESPACE, "resourcetype" );
527         method.addProperty( PropFind.WEBDAV_NAMESPACE, "lockdiscovery" );
528         method.addProperty( PropFind.WEBDAV_NAMESPACE, "creationdate" );
529         method.addProperty( PropFind.WEBDAV_NAMESPACE, "getlastmodified" );
530         method.addProperty( PropFind.WEBDAV_NAMESPACE, "getcontenttype" );
531         method.addProperty( PropFind.WEBDAV_NAMESPACE, "checked-in" );
532         method.addProperty( PropFind.WEBDAV_NAMESPACE, "checked-out" );
533         method.addProperty( PropFind.WEBDAV_NAMESPACE, "checkout-set" );
534         method.addProperty( PropFind.WEBDAV_NAMESPACE, "successor-set" );
535         method.addProperty( NamespaceType.OHRM.getURI(), "title" );
536         method.addProperty( NamespaceType.OHRM.getURI(), "harmonise-id" );
537         try {
538             WebDAVResponse response = this.m_conn.execute(method);
539             this.getVirtualFile(response, vfFile, sRealPath);
540         
541             if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
542                 this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
543             }
544
545             this.setFileChildrenPopulated(vfFile, true);
546         } catch (IOException e) {
547             this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
548             e.printStackTrace();
549         } catch (ModuleException e) {
550             this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
551             e.printStackTrace();
552         }
553     }
554     
555     /**
556      * This method will return either the Virtual File that was
557      * requested by the path or a new blank file initialised to that path.
558      *
559      * @param response Response from WebDAV server
560      * @param sRequestedPath Full path to the requested file
561      * @return
562      */

563     private VirtualFile getVirtualFile(WebDAVResponse response, String JavaDoc sRequestedPath) {
564         return this.getVirtualFile(response, null, sRequestedPath);
565     }
566     
567     /**
568      * This method will return either the Virtual File that was
569      * requested by the path or a new blank file initialised to that path.
570      *
571      * @param response Response from WebDAV server
572      * @param vfFile Virtual file to be populated
573      * @param sRequestedPath Full path to the requested file
574      * @return
575      */

576     private VirtualFile getVirtualFile(WebDAVResponse response, VirtualFile vfFile, String JavaDoc sRequestedPath) {
577         
578         try {
579             if( response.getStatusCode()==207 ) {
580                 if(vfFile==null) {
581                     vfFile = new VersionedVirtualFile();
582                     vfFile.setVFS(this);
583                 }
584                 
585                 MultiStatusResponse multiResponse = null;
586                 
587                 List list = response.getMultiStatusResponses();
588                 Iterator itor = list.iterator();
589                 while(itor.hasNext()) {
590                     multiResponse = (MultiStatusResponse)itor.next();
591                     String JavaDoc sURI = multiResponse.getURI();
592                     if(sURI.endsWith("/")) {
593                         sURI = sURI.substring(0, sURI.length()-1);
594                     }
595                     if( sURI.equals(sRequestedPath) ) {
596                         break;
597                     }
598                 }
599                 
600                 if( multiResponse.getStatus()==200 ) {
601                     Element elRoot = multiResponse.getResponseXML();
602                     this.populateVirtualFile(elRoot, vfFile);
603                     if( !this.m_cache.hasFile( vfFile.getFullPath() ) || this.m_cache.getFile(vfFile.getFullPath())!=vfFile) {
604                         this.m_cache.addFile(vfFile);
605                     }
606                 }
607                 
608                 if( response.getMultiStatusResponses().size()>1 ) {
609                     for(int i=0; i<response.getMultiStatusResponses().size(); i++) {
610                         MultiStatusResponse tempMultiResponse = (MultiStatusResponse)response.getMultiStatusResponses().get(i);
611                         String JavaDoc sURI = tempMultiResponse.getURI();
612                         if(sURI.endsWith("/")) {
613                             sURI = sURI.substring(0, sURI.length()-1);
614                         }
615                         if( !sURI.equals(sRequestedPath) ) {
616                             VirtualFile vfTempFile = null;
617                         
618                             String JavaDoc sRealPath = tempMultiResponse.getURI().substring( this.getInitialPath().length()+1 );
619                             if(sRealPath.length()>0 && !sRealPath.startsWith("/")) {
620                                 sRealPath = "/" + sRealPath;
621                             }
622                         
623                             if( this.m_cache.hasFile( sRealPath )) {
624                                 vfTempFile = this.m_cache.getFile( sRealPath );
625                             } else {
626                                 vfTempFile = new VersionedVirtualFile();
627                                 vfTempFile.setVFS(this);
628                             }
629                         
630                             if( tempMultiResponse.getStatus()==200 ) {
631                                 Element elRoot = tempMultiResponse.getResponseXML();
632                                 this.populateVirtualFile(elRoot, vfTempFile);
633                                 
634                                 if( ! vfFile.hasChild(vfTempFile.getFullPath()) ) {
635                                     vfFile.addChild( vfTempFile.getFullPath() );
636                                 }
637                                 if( !this.m_cache.hasFile( sRealPath )) {
638                                     this.m_cache.addFile(vfTempFile);
639                                 }
640                             }
641                         }
642                     }
643                     this.setFileChildrenPopulated(vfFile, true);
644                 }
645             }
646         } catch (IOException e) {
647             e.printStackTrace();
648         } catch (ModuleException e) {
649             e.printStackTrace();
650         }
651         
652         return vfFile;
653     }
654
655     /**
656      * Populates a virtual file from the given XML.
657      *
658      * @param elRoot Root element of result from WebDAV server
659      * @param vfFile Virtual file to be populated
660      */

661     protected void populateVirtualFile(Element elRoot, VirtualFile vfFile) {
662         if(!vfFile.isPopulateLocked()) {
663             vfFile.setPopulateLocked(true);
664             try {
665                 if( elRoot.getLocalName().equals("response") ) {
666                     this.setFileMetadataPopulated(vfFile, true);
667                     
668                     try {
669                     
670                         Element elHREF = XMLUtils.getFirstNamedChild(elRoot, "href");
671                         String JavaDoc sDecodedPath = WebDAVConnection.URLDencode( ((String JavaDoc)elHREF.getFirstChild().getNodeValue()).substring(this.m_sInitialPath.length()) );
672                         vfFile.setFullPath( sDecodedPath );
673                         if(!this.m_aPopulateLockedPaths.contains(vfFile.getFullPath())) {
674                             this.m_aPopulateLockedPaths.add(vfFile.getFullPath());
675                         
676                             boolean bCheckedIn = false;
677                             boolean bCheckedOut = false;
678                             boolean bPredecessors = false;
679                             boolean bSuccessors = false;
680                             String JavaDoc sCheckedInPath = null;
681                             String JavaDoc sCheckedOutPath = null;
682                             String JavaDoc sSuccessorPath = null;
683                             ArrayList aPredecessors = new ArrayList();
684                         
685                             NodeList nlPropStats = elRoot.getElementsByTagNameNS(PropFind.WEBDAV_NAMESPACE, "propstat");
686                             for (int k = 0; k < nlPropStats.getLength(); k++) {
687                                 Element elPropStat = (Element) nlPropStats.item(k);
688                                 Element elStatus = XMLUtils.getFirstNamedChild(elPropStat, "status");
689                                 String JavaDoc sStatus = elStatus.getFirstChild().getNodeValue();
690                                 if(sStatus.indexOf("200 OK")>-1) {
691                                     Element elProp = XMLUtils.getFirstNamedChild(elPropStat, "prop");
692                                     NodeList nl = elProp.getChildNodes();
693                                     for(int i=0; i<nl.getLength(); i++ ) {
694                                         if( nl.item(i).getNodeType()==Node.ELEMENT_NODE) {
695                                             Element elTemp = (Element)nl.item(i);
696                                             if(elTemp.getLocalName().equals("resourcetype")) {
697                                                 Node colNode = elTemp.getFirstChild();
698                                                 if(colNode!=null && colNode.getNodeType()==Node.ELEMENT_NODE) {
699                                                     Element elColNode = (Element)colNode;
700                                                     if(elColNode.getLocalName().equals("collection")) {
701                                                         vfFile.setIsDirectory(true);
702                                                         if(elColNode.hasAttributeNS(NamespaceType.OHRM.getURI(), "isVirtual") && elColNode.getAttributeNS(NamespaceType.OHRM.getURI(), "isVirtual").equalsIgnoreCase("true")) {
703                                                             vfFile.setIsVirtualDirectory(true);
704                                                         }
705                                                         if(vfFile.isDirectory()) {
706                                                             this.setOrderableDirectory(vfFile, true);
707                                                         }
708                                                     }
709                                                 }
710                                             } else if(elTemp.getLocalName().equals("lockdiscovery")) {
711                                                 this.populateLock(elTemp, vfFile);
712                                             } else if(elTemp.getLocalName().equals("checked-out")) {
713                                                 NodeList nlHREF = elTemp.getElementsByTagNameNS(PropFind.WEBDAV_NAMESPACE, "href");
714                                                 for (int j = 0; j < nlHREF.getLength(); j++) {
715                                                     Element elLocalHREF = (Element) nlHREF.item(j);
716                                                     sCheckedInPath = elLocalHREF.getFirstChild().getNodeValue();
717                                                     bCheckedOut = true;
718                                                 }
719                                             } else if(elTemp.getLocalName().equals("checked-in")) {
720                                                 NodeList nlHREF = elTemp.getElementsByTagNameNS(PropFind.WEBDAV_NAMESPACE, "href");
721                                                 for (int j = 0; j < nlHREF.getLength(); j++) {
722                                                     Element elLocalHREF = (Element) nlHREF.item(j);
723                                                     sCheckedInPath = elLocalHREF.getFirstChild().getNodeValue();
724                                                     bCheckedIn = true;
725                                                 }
726                                             } else if(elTemp.getLocalName().equals("checkout-set")) {
727                                                 NodeList nlHREF = elTemp.getElementsByTagNameNS(PropFind.WEBDAV_NAMESPACE, "href");
728                                                 for (int j = 0; j < nlHREF.getLength(); j++) {
729                                                     Element elLocalHREF = (Element) nlHREF.item(j);
730                                                     sCheckedOutPath = elLocalHREF.getFirstChild().getNodeValue();
731                                                     bCheckedIn = true;
732                                                 }
733                                             } else if(elTemp.getLocalName().equals("predecessor-set")) {
734                                                 NodeList nlHREF = elTemp.getElementsByTagNameNS(PropFind.WEBDAV_NAMESPACE, "href");
735                                                 for (int j = 0; j < nlHREF.getLength(); j++) {
736                                                     Element elLocalHREF = (Element) nlHREF.item(j);
737                                                     String JavaDoc sPath = elLocalHREF.getFirstChild().getNodeValue();
738                                                     if(sPath!=null) {
739                                                         aPredecessors.add(sPath);
740                                                         bPredecessors = true;
741                                                     }
742                                                 }
743                                             } else if(elTemp.getLocalName().equals("successor-set")) {
744                                                 NodeList nlHREF = elTemp.getElementsByTagNameNS(PropFind.WEBDAV_NAMESPACE, "href");
745                                                 for (int j = 0; j < nlHREF.getLength(); j++) {
746                                                     Element elLocalHREF = (Element) nlHREF.item(j);
747                                                     sSuccessorPath = elLocalHREF.getFirstChild().getNodeValue();
748                                                     bSuccessors = true;
749                                                     break;
750                                                 }
751                                             } else {
752                                                 PropertyInstance prop = new PropertyInstance();
753                                                 this.populatePropertyInstance(vfFile, elTemp, prop, true);
754                                             }
755                                         }
756                             
757                                     }
758                                 }
759                             }
760                             
761                             if(bCheckedOut) {
762                                 // Pending file
763
this.setFileState(vfFile, VirtualFile.STATE_PENDING);
764                                 if(((VersionedVirtualFile)vfFile).getLiveVersionPath()==null) {
765                                     this.setFileLiveVersionPath((VersionedVirtualFile) vfFile, sCheckedOutPath);
766                                 }
767                             } else if(bCheckedIn) {
768                                 // Live file
769
this.setFileState(vfFile, VirtualFile.STATE_LIVE);
770                             } else if(bSuccessors && !bCheckedIn) {
771                                 // Historical file
772
this.setFileState(vfFile, VirtualFile.STATE_HISTORICAL);
773                             } else if(!bCheckedOut && !bCheckedIn && !bSuccessors && !bPredecessors) {
774                                 // New file
775
this.setFileState(vfFile, VirtualFile.STATE_PENDING);
776                                 this.setFileLiveVersionPath((VersionedVirtualFile) vfFile, null);
777                             }
778                             
779                             if(bPredecessors) {
780                                 Iterator itor = aPredecessors.iterator();
781                                 while (itor.hasNext()) {
782                                     String JavaDoc element = (String JavaDoc) itor.next();
783                                     this.addHistoricalVersionPath((VersionedVirtualFile) vfFile, element);
784                                 }
785                                 this.setFileHistoryPopulated((VersionedVirtualFile) vfFile, true);
786                             }
787                             
788                             if(sCheckedOutPath!=null) {
789                                 this.setFilePendingVersionPath((VersionedVirtualFile) vfFile, sCheckedOutPath);
790                             }
791                         }
792                     } catch(Exception JavaDoc e) {
793                         e.printStackTrace(System.err);
794                     } finally {
795                         this.setFileMetadataPopulated(vfFile, false);
796                     }
797                 }
798             } catch(Exception JavaDoc e) {
799                 e.printStackTrace(System.err);
800             } finally {
801                 vfFile.setPopulateLocked(false);
802                 this.m_aPopulateLockedPaths.remove(vfFile.getFullPath());
803             }
804         }
805     }
806     
807     /**
808      * Fully populates the lock information from a XML element.
809      *
810      * @param elLock Root element of lock information
811      * @param vfFile Virtual file to be populated
812      */

813     protected void populateLock(Element elLock, VirtualFile vfFile) {
814         NodeList nl = elLock.getChildNodes();
815         for(int i=0; i<nl.getLength(); i++ ) {
816             if( nl.item(i).getNodeType()==Node.ELEMENT_NODE) {
817                 Element elTemp = (Element)nl.item(i);
818                 if(elTemp.getLocalName().equalsIgnoreCase("activelock")) {
819                     NodeList nl2 = elTemp.getChildNodes();
820                     for(int j=0; j<nl2.getLength(); j++ ) {
821                         if( nl2.item(j).getNodeType()==Node.ELEMENT_NODE) {
822                             Element elInnerTemp = (Element)nl2.item(j);
823                             if(elInnerTemp.getLocalName().equalsIgnoreCase("owner")) {
824                                 Node textNode = XMLUtils.getFirstNamedChild(elInnerTemp, "href").getFirstChild();
825                                 if(textNode!=null && textNode.getNodeValue()!=null && !textNode.getNodeValue().equals("")) {
826                                     vfFile.setLockOwner(textNode.getNodeValue());
827                                 } else {
828                                     
829                                 }
830                             } else if(elInnerTemp.getLocalName().equalsIgnoreCase("locktoken")) {
831                                 Node textNode = XMLUtils.getFirstNamedChild(elInnerTemp, "href").getFirstChild();
832                                 if(textNode!=null && textNode.getNodeValue()!=null && !textNode.getNodeValue().equals("")) {
833                                     vfFile.setLockToken(textNode.getNodeValue());
834                                 } else {
835                                     
836                                 }
837                             }
838                         }
839                     }
840                 }
841             }
842         }
843     }
844     
845     /**
846      * Creates a value instance implementation, populates it and adds to
847      * a virtual file.
848      *
849      * @param vfFile Virtual file to add value to
850      * @param prop Property instance to add value to
851      * @param propEl Root element of value XML
852      */

853     private void addValuesToProperty(VirtualFile vfFile, PropertyInstance prop, Element propEl) {
854         Range range = prop.getDefinition().getRange();
855         ValueInstance val = prop.getNewValueInstance();
856         
857         if(prop.getName().equalsIgnoreCase("domain")) {
858             DAVDomainValue.fromXML(prop, propEl);
859         } else if(prop.getName().equalsIgnoreCase("range")) {
860             DAVRangeValue.fromXML(prop, propEl);
861         } else if(range instanceof BooleanRange) {
862             DAVBooleanValue.fromXML(prop, propEl);
863         } else if(range instanceof DateTimeRange) {
864             DAVDateTimeValue.fromXML(prop, propEl);
865         } else if(range instanceof DateRange) {
866             DAVDateValue.fromXML(prop, propEl);
867         } else if(range instanceof DomainRange) {
868             DAVDomainValue.fromXML(prop, propEl);
869         } else if(range instanceof FloatRange) {
870             DAVFloatValue.fromXML(prop, propEl);
871         } else if(range instanceof IntegerRange) {
872             DAVIntegerValue.fromXML(prop, propEl);
873         } else if(range instanceof PropertyRange) {
874             DAVPropertyValue.fromXML(vfFile, prop, propEl);
875         } else if(range instanceof RangeRange) {
876             DAVRangeValue.fromXML(prop, propEl);
877         } else if(range instanceof ResourceRange || range instanceof CollectionRange) {
878             DAVResourceValue.fromXML(prop, propEl);
879         } else if(range instanceof URIRange) {
880             DAVURIValue.fromXML(prop, propEl);
881         } else if(range instanceof ValueRange) {
882             DAVValueValue.fromXML(prop, propEl);
883         } else if(range instanceof StringRange) {
884             DAVStringValue.fromXML(prop, propEl);
885         } else {
886             DAVStringValue.fromXML(prop, propEl);
887         }
888     }
889     
890     /**
891      * Populates a property instance from a XML element.
892      *
893      * @param vfFile Virtual file to add property instance to
894      * @param elProp Root element of property instance XML
895      * @param prop Property instance to be populated
896      * @param bAddToFile true if property instance is to be added to virtual file, false if it is part of a compound property instance
897      */

898     public void populatePropertyInstance(VirtualFile vfFile, Element elProp, PropertyInstance prop, boolean bAddToFile) {
899         String JavaDoc sNamespaceURI = elProp.getNamespaceURI();
900         String JavaDoc sName = elProp.getLocalName();
901         
902         prop.setNamespaceURI(sNamespaceURI);
903         prop.setName(sName);
904         
905         String JavaDoc sDefnHREF = "";
906         
907         if(!sName.equals(vfFile.getFileName())) {
908             if(elProp.hasAttributeNS(NamespaceType.DAV.getURI(), "definition")) {
909                 sDefnHREF = elProp.getAttributeNS(NamespaceType.DAV.getURI(), "definition");
910                 if(elProp.hasAttributeNS(NamespaceType.DAV.getURI(), "definition-version")) {
911                     String JavaDoc sDefnVersion = elProp.getAttributeNS(NamespaceType.DAV.getURI(), "definition-version");
912                     prop.setDefinitionPath(sDefnHREF, sDefnVersion);
913                 }
914             } else if(elProp.hasAttribute("definition")) {
915                 sDefnHREF = elProp.getAttribute("definition");
916                 if(elProp.hasAttribute("definition-version")) {
917                     String JavaDoc sDefnVersion = elProp.getAttribute("definition-version");
918                     prop.setDefinitionPath(sDefnHREF, sDefnVersion);
919                 }
920             }
921         }
922         
923         prop.setVirtualFile(vfFile);
924
925         String JavaDoc sNameForFile = vfFile.getFileName();
926         String JavaDoc sNamePropHref = sDefnHREF;
927         String JavaDoc sNameFileHref = vfFile.getFullPath();
928         if(!sName.equals(vfFile.getFileName()) && (sDefnHREF!=null && !sDefnHREF.equals(vfFile.getFullPath()) ) ) {
929             Property defn = prop.getDefinition();
930             Range range=null;
931             if(defn!=null) {
932                 range = defn.getRange();
933             }
934             this.addValuesToProperty(vfFile, prop, elProp);
935         } else {
936             bAddToFile=false;
937             vfFile.removeProperty(sNamespaceURI, sName);
938             prop.setVirtualFile(null);
939         }
940         
941         if(bAddToFile) {
942             vfFile.addProperty(prop);
943         }
944     }
945     
946     /**
947      * Checks a virtual file for new metedata, populates the new metadata
948      * into the virtual file if any is found.
949      *
950      * @param vfFile Virtual file to be checked
951      */

952     private void checkFileForNewMetadata(VirtualFile vfFile) {
953         String JavaDoc sRealPath = this.getInitialPath() + vfFile.getFullPath();
954
955
956         if(vfFile.isDirectory()) {
957             sRealPath = sRealPath + "/";
958         }
959         PropFind method = new PropFind(sRealPath);
960         method.setDepth( PropFind.DEPTH_0 );
961         try {
962             WebDAVResponse response = this.m_conn.execute(method);
963         
964             if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
965                 this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
966             } else {
967                 MultiStatusResponse multiResponse = null;
968                 
969                 List list = response.getMultiStatusResponses();
970                 Iterator itor = list.iterator();
971                 while(itor.hasNext()) {
972                     multiResponse = (MultiStatusResponse)itor.next();
973                 }
974
975                 if( multiResponse.getStatus()==200 ) {
976                     Element elRoot = multiResponse.getResponseXML();
977                     NodeList nlPropStats = elRoot.getElementsByTagNameNS(PropFind.WEBDAV_NAMESPACE, "propstat");
978                     for (int k = 0; k < nlPropStats.getLength(); k++) {
979                         Element elPropStat = (Element) nlPropStats.item(k);
980                                 Element elStatus = XMLUtils.getFirstNamedChild(elPropStat, "status");
981                                 String JavaDoc sStatus = elStatus.getFirstChild().getNodeValue();
982                                 if(sStatus.indexOf("200 OK")>-1) {
983                                     Element elProp = XMLUtils.getFirstNamedChild(elPropStat, "prop");
984                                     NodeList nl = elProp.getChildNodes();
985                                     for(int i=0; i<nl.getLength(); i++ ) {
986                                         if( nl.item(i).getNodeType()==Node.ELEMENT_NODE) {
987                                             Element elTemp = (Element)nl.item(i);
988                                             PropertyInstance prop = new PropertyInstance();
989                                             if(vfFile.getProperty(elTemp.getNamespaceURI(), elTemp.getLocalName())==null) {
990                                                 this.populatePropertyInstance(vfFile, elTemp, prop, true);
991                                             }
992                                         }
993                                     }
994                                 }
995                         }
996                     }
997                 }
998             
999         } catch (IOException e) {
1000            this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
1001            e.printStackTrace();
1002            this.setFileMetadataPopulated(vfFile, false);
1003        } catch (ModuleException e) {
1004            this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
1005            e.printStackTrace();
1006            this.setFileMetadataPopulated(vfFile, false);
1007        }
1008    }
1009
1010    /* (non-Javadoc)
1011     * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#putImplVirtualFile(java.lang.String, byte[])
1012     */

1013    public ResourceStatusWrapper addVirtualFile(String JavaDoc sPath, VirtualFile content) {
1014        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1015        retnStatus.setMethodName(VirtualFile.METHOD_ADD);
1016        VirtualFile vfFile = null;
1017        
1018        String JavaDoc sFullPath = sPath;
1019        
1020        sPath = this.getInitialPath() + sPath;
1021        
1022        if( this.m_cache.hasFile(sFullPath) ) {
1023            retnStatus.setStatusCode(StatusData.STATUS_RESOURCE_EXISTS);
1024        } else {
1025            Put method = new Put(sPath);
1026            method.setData( content.getContent() );
1027        
1028            String JavaDoc sContentType = this.getVirtualFileSystemView().getContentType(content);
1029            if(sContentType!=null && !sContentType.equals("")) {
1030                method.addHeader("Content-Type", sContentType);
1031            }
1032            try {
1033                WebDAVResponse response = this.m_conn.execute(method);
1034                retnStatus.setHTTPStatus(response.getStatusCode());
1035        
1036                if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1037                    this.fireErrorEvent("FileNotAdded", "The file " + sFullPath + " cannot be added here, this might be because a file already exists here with the same name.");
1038                }
1039                content.setFullPath( sFullPath );
1040                vfFile = content;
1041                vfFile.setVFS(this);
1042                
1043                VirtualFile vfParent = this.getVirtualFile(vfFile.getFilePath()).getResource();
1044                vfParent.refreshChildren(VirtualFile.EVENT_ADDITION, sFullPath);
1045            } catch (IOException e) {
1046                retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1047                retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1048                this.fireErrorEvent("FileNotAdded", "The file " + sFullPath + " cannot be added here, this might be because a file already exists here with the same name.");
1049                e.printStackTrace();
1050            } catch (ModuleException e) {
1051                retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1052                retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1053                this.fireErrorEvent("FileNotAdded", "The file " + sFullPath + " cannot be added here, this might be because a file already exists here with the same name.");
1054                e.printStackTrace();
1055            }
1056        }
1057        
1058        if(vfFile==null) {
1059            this.fireErrorEvent("FileNotAdded", "The file " + sFullPath + " cannot be added here, this might be because a file already exists here with the same name.");
1060        }
1061
1062        // TODO Optimise so that this last getVirtualFile call is not made
1063
// if the PUT returned a none 200 status.
1064
return new ResourceStatusWrapper(this.getVirtualFile(sPath).getResource(), retnStatus);
1065    }
1066
1067    /* (non-Javadoc)
1068     * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#moveImplVirtualFile(java.lang.String, java.lang.String)
1069     */

1070    public StatusData moveVirtualFile(String JavaDoc sFromPath, String JavaDoc sToPath) {
1071        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1072        retnStatus.setMethodName(VirtualFile.METHOD_MOVE);
1073        
1074        String JavaDoc sFromRealPath = this.getInitialPath() + sFromPath;
1075        String JavaDoc sToRealPath = this.getInitialPath() + sToPath;
1076        
1077        Move method = new Move(sFromRealPath, this.m_conn.getProtocol() + "://" + this.m_conn.getHost() + ":" + this.m_conn.getPort() + sToRealPath);
1078        try {
1079            WebDAVResponse response = this.m_conn.execute(method);
1080            retnStatus.setHTTPStatus(response.getStatusCode());
1081            this.m_cache.removeFile(sFromPath);
1082        
1083            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1084                this.fireErrorEvent("FileNotMoved", "The file " + sFromPath + " cannot be moved here, this might be because a file already exists here with the same name.");
1085            }
1086        } catch (IOException e) {
1087            e.printStackTrace();
1088            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1089            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1090            this.fireErrorEvent("FileNotMoved", "The file " + sFromPath + " cannot be moved here, this might be because a file already exists here with the same name.");
1091        } catch (ModuleException e) {
1092            e.printStackTrace();
1093            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1094            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1095            this.fireErrorEvent("FileNotMoved", "The file " + sFromPath + " cannot be moved here, this might be because a file already exists here with the same name.");
1096        } catch (Exception JavaDoc e) {
1097            e.printStackTrace();
1098            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1099            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1100            this.fireErrorEvent("FileNotMoved", "The file " + sFromPath + " cannot be moved here, this might be because a file already exists here with the same name.");
1101        }
1102
1103        return retnStatus;
1104    }
1105
1106    /* (non-Javadoc)
1107     * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#copyImplVirtualFile(java.lang.String, java.lang.String)
1108     */

1109    public StatusData copyVirtualFile(String JavaDoc sFromPath, String JavaDoc sToPath) {
1110        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1111        retnStatus.setMethodName(VirtualFile.METHOD_COPY);
1112        
1113        String JavaDoc sFromRealPath = this.getInitialPath() + sFromPath;
1114        String JavaDoc sToRealPath = this.getInitialPath() + sToPath;
1115        
1116        Copy method = new Copy(sFromRealPath, this.m_conn.getProtocol() + "://" + this.m_conn.getHost() + ":" + this.m_conn.getPort() + sToRealPath);
1117        try {
1118            WebDAVResponse response = this.m_conn.execute(method);
1119            retnStatus.setHTTPStatus(response.getStatusCode());
1120        
1121            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1122                this.fireErrorEvent("FileNotCopied", "The file " + sFromPath + " cannot be copied here, this might be because a file already exists here with the same name.");
1123            } else {
1124                String JavaDoc sRemoveFromPath = this.getParentPath(sFromPath);
1125                String JavaDoc sRemoveToPath = this.getParentPath(sToPath);
1126                this.m_cache.removeFile(sFromPath);
1127                this.m_cache.removeFile( sRemoveFromPath );
1128                if(!sRemoveFromPath.equals(sRemoveToPath)) {
1129                    this.m_cache.removeFile( sRemoveToPath );
1130                }
1131            }
1132        } catch (IOException e) {
1133            e.printStackTrace();
1134            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1135            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1136            this.fireErrorEvent("FileNotCopied", "The file " + sFromPath + " cannot be copied here, this might be because a file already exists here with the same name.");
1137        } catch (ModuleException e) {
1138            e.printStackTrace();
1139            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1140            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1141            this.fireErrorEvent("FileNotCopied", "The file " + sFromPath + " cannot be copied here, this might be because a file already exists here with the same name.");
1142        } catch (Exception JavaDoc e) {
1143            e.printStackTrace();
1144            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1145            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1146            this.fireErrorEvent("FileNotCopied", "The file " + sFromPath + " cannot be copied here, this might be because a file already exists here with the same name.");
1147        }
1148
1149        return retnStatus;
1150    }
1151
1152    /* (non-Javadoc)
1153     * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#deleteImplVirtualFile(java.lang.String)
1154     */

1155    public StatusData deleteVirtualFile(String JavaDoc sPath) {
1156        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1157        retnStatus.setMethodName(VirtualFile.METHOD_DELETE);
1158        
1159        String JavaDoc sRealPath = this.getInitialPath() + sPath;
1160        
1161        VirtualFile vfFile = this.getVirtualFile(sPath).getResource();
1162
1163        if(vfFile.isDirectory()) {
1164            sRealPath = sRealPath + "/";
1165        }
1166        Delete method = new Delete(sRealPath);
1167        
1168        if(vfFile.isLocked()) {
1169            String JavaDoc sTokenPath = WebDAVConnection.URLEncode( vfFile.getFullPath() );
1170            if(vfFile.isDirectory()) {
1171                sTokenPath = sTokenPath + "/";
1172            }
1173            method.addHeader("If", "<" + sTokenPath + "> (<" + vfFile.getLockToken() + ">)");
1174        }
1175        try {
1176            WebDAVResponse response = this.m_conn.execute(method);
1177            retnStatus.setHTTPStatus(response.getStatusCode());
1178        
1179            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1180                this.fireErrorEvent("FileNotDeleted", "The file " + sPath + " cannot be deleted.");
1181            } else {
1182                this.m_cache.removeFile(sPath);
1183            }
1184        } catch (IOException e) {
1185            e.printStackTrace();
1186            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1187            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1188            this.fireErrorEvent("FileNotDeleted", "The file " + sPath + " cannot be deleted.");
1189        } catch (ModuleException e) {
1190            e.printStackTrace();
1191            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1192            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1193            this.fireErrorEvent("FileNotDeleted", "The file " + sPath + " cannot be deleted.");
1194        }
1195
1196        return retnStatus;
1197    }
1198
1199    /* (non-Javadoc)
1200     * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#lockImplVirtualFile(java.lang.String)
1201     */

1202    public StatusData lockVirtualFile(String JavaDoc sPath) {
1203        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1204        retnStatus.setMethodName(VirtualFile.METHOD_LOCK);
1205        
1206        String JavaDoc sRealPath = this.getInitialPath() + sPath;
1207        
1208        Lock method = new Lock(sRealPath);
1209        
1210        method.setOwner( this.getAuthentication().getUsername() );
1211        
1212        try {
1213            WebDAVResponse response = this.m_conn.execute(method);
1214            retnStatus.setHTTPStatus(response.getStatusCode());
1215        
1216            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1217                this.fireErrorEvent("FileNotLocked", "The file " + sPath + " cannot be locked.");
1218            } else {
1219                this.m_cache.getFile(sPath).setLockOwner( this.getAuthentication().getUsername() );
1220                Document xmlDoc = response.getResponseXML();
1221                Element elLock = XMLUtils.getFirstNamedChild(xmlDoc.getDocumentElement(), "lockdiscovery");
1222                
1223                if(elLock!=null) {
1224                    this.populateLock(elLock, this.m_cache.getFile(sPath));
1225                }
1226            }
1227        } catch (IOException e) {
1228            e.printStackTrace();
1229            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1230            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1231            this.fireErrorEvent("FileNotLocked", "The file " + sPath + " cannot be locked.");
1232        } catch (ModuleException e) {
1233            e.printStackTrace();
1234            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1235            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1236            this.fireErrorEvent("FileNotLocked", "The file " + sPath + " cannot be locked.");
1237        }
1238
1239        return retnStatus;
1240    }
1241
1242    /* (non-Javadoc)
1243     * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#unlockImplVirtualFile(java.lang.String)
1244     */

1245    public StatusData unlockVirtualFile(String JavaDoc sPath) {
1246        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1247        retnStatus.setMethodName(VirtualFile.METHOD_UNLOCK);
1248
1249        String JavaDoc sRealPath = this.getInitialPath() + sPath;
1250        
1251        VirtualFile vfFile = this.m_cache.getFile(sPath);
1252        
1253        if(!vfFile.isLocked()) {
1254            return retnStatus;
1255        }
1256        
1257        if(vfFile.isDirectory()) {
1258            sRealPath = sRealPath + "/";
1259        }
1260        Unlock method = new Unlock(sRealPath, vfFile.getLockToken());
1261        
1262        try {
1263            WebDAVResponse response = this.m_conn.execute(method);
1264            retnStatus.setHTTPStatus(response.getStatusCode());
1265        
1266            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1267                this.fireErrorEvent("FileNotUnlocked", "The file " + sPath + " cannot be unlocked.");
1268            } else {
1269                this.m_cache.getFile(sPath).setLockOwner(null);
1270                this.m_cache.getFile(sPath).setLockToken(null);
1271            }
1272        } catch (IOException e) {
1273            e.printStackTrace();
1274            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1275            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1276            this.fireErrorEvent("FileNotUnlocked", "The file " + sPath + " cannot be unlocked.");
1277        } catch (ModuleException e) {
1278            e.printStackTrace();
1279            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1280            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1281            this.fireErrorEvent("FileNotUnlocked", "The file " + sPath + " cannot be unlocked.");
1282        }
1283
1284        return retnStatus;
1285    }
1286
1287    /* (non-Javadoc)
1288     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#createVirtualDirectory(java.lang.String)
1289     */

1290    /* (non-Javadoc)
1291     * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#createImplVirtualDirectory(java.lang.String)
1292     */

1293    public StatusData createVirtualDirectory(String JavaDoc sPath) {
1294        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1295        retnStatus.setMethodName(VirtualFile.METHOD_MKDIR);
1296
1297        String JavaDoc sRealPath = this.getInitialPath() + sPath + "/";
1298        
1299        MkCol method = new MkCol(sRealPath);
1300        
1301        try {
1302            WebDAVResponse response = this.m_conn.execute(method);
1303            retnStatus.setHTTPStatus(response.getStatusCode());
1304        
1305            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1306                this.fireErrorEvent("DirectoryNotCreated", "The directory " + sPath + " cannot be created.");
1307            } else {
1308                String JavaDoc sParentPath = this.getParentPath(sPath);
1309                
1310                VirtualFile vfParent = this.getVirtualFile(sParentPath).getResource();
1311                vfParent.refreshChildren(VirtualFile.EVENT_ADDITION, sPath);
1312            }
1313        } catch (IOException e) {
1314            e.printStackTrace();
1315            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1316            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1317            this.fireErrorEvent("DirectoryNotCreated", "The directory " + sPath + " cannot be created.");
1318        } catch (ModuleException e) {
1319            e.printStackTrace();
1320            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1321            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1322            this.fireErrorEvent("DirectoryNotCreated", "The directory " + sPath + " cannot be created.");
1323        }
1324
1325        return retnStatus;
1326    }
1327
1328    /* (non-Javadoc)
1329     * @see com.simulacramedia.contentmanager.vfs.AbstractVirtualFileSystem#createImplShortcut(java.lang.String, java.lang.String)
1330     */

1331    public StatusData createShortcut(String JavaDoc sPath, String JavaDoc sToPath) {
1332        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1333        retnStatus.setMethodName(VirtualFile.METHOD_SHORTCUT);
1334
1335        String JavaDoc sRealPath = this.getInitialPath() + sPath;
1336        String JavaDoc sRealToPath = this.getInitialPath() + sToPath;
1337        
1338        Bind method = new Bind(sRealPath);
1339        method.setDestination(sRealToPath);
1340        
1341        try {
1342            WebDAVResponse response = this.m_conn.execute(method);
1343            retnStatus.setHTTPStatus(response.getStatusCode());
1344        
1345            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1346                this.fireErrorEvent("ShortcutNotCreted", "The shortcut " + sPath + " cannot be created.");
1347            } else {
1348                this.m_cache.removeFile( this.getParentPath(sRealToPath) );
1349            }
1350        } catch (IOException e) {
1351            e.printStackTrace();
1352            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1353            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1354            this.fireErrorEvent("ShortcutNotCreted", "The shortcut " + sPath + " cannot be created.");
1355        } catch (ModuleException e) {
1356            e.printStackTrace();
1357            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1358            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1359            this.fireErrorEvent("ShortcutNotCreted", "The shortcut " + sPath + " cannot be created.");
1360        }
1361
1362        return retnStatus;
1363    }
1364
1365    /* (non-Javadoc)
1366     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#searchImpl()
1367     */

1368    public ResourceListStatusWrapper search( Query query) {
1369        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1370        retnStatus.setMethodName(VirtualFile.METHOD_SEARCH);
1371        ArrayList aResults = new ArrayList();
1372        
1373        SearchBuilder search = new SearchBuilder(this.getInitialPath());
1374
1375        Search method = new Search("/webdav/");
1376        method.setDepth(Search.DEPTH_INFINITY);
1377        method.setSearchXML(search.buildSearchXML(query));
1378        
1379        try {
1380            WebDAVResponse response = this.m_conn.execute(method);
1381            retnStatus.setHTTPStatus(response.getStatusCode());
1382            
1383            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1384                this.fireErrorEvent("SearchFailed", "The search failed.");
1385            } else {
1386                Element elRoot = response.getResponseXML().getDocumentElement();
1387                
1388                NodeList nl = elRoot.getElementsByTagNameNS(NamespaceType.DAV.getURI(), "href");
1389                for(int i=0; i<nl.getLength(); i++) {
1390                    Node node = nl.item(i);
1391                    if(node.getNodeType()==Node.ELEMENT_NODE) {
1392                        Element elHREF = (Element)node;
1393                        if(elHREF.getChildNodes().getLength()>0) {
1394                            Node childNode = elHREF.getFirstChild();
1395                            if(childNode.getNodeType()==Node.TEXT_NODE) {
1396                                String JavaDoc sHREF = childNode.getNodeValue();
1397                                String JavaDoc sInternalHREF = sHREF.substring( this.getInitialPath().length()+1 );
1398                                if(!sInternalHREF.startsWith("/")) {
1399                                    sInternalHREF = "/" + sInternalHREF;
1400                                }
1401                                if(sInternalHREF.endsWith("/")) {
1402                                    sInternalHREF = sInternalHREF.substring(0, sInternalHREF.lastIndexOf("/"));
1403                                }
1404                                aResults.add(sInternalHREF);
1405                            }
1406                        }
1407                    }
1408                }
1409            }
1410            
1411            
1412        } catch (IOException e) {
1413            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1414            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1415            this.fireErrorEvent("BadSearch", "The search could not be executed.");
1416            e.printStackTrace();
1417        } catch (ModuleException e) {
1418            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1419            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1420            this.fireErrorEvent("BadSearch", "The search could not be executed.");
1421            e.printStackTrace();
1422        }
1423
1424        return new ResourceListStatusWrapper(aResults, retnStatus);
1425    }
1426
1427    /* (non-Javadoc)
1428     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getVirtualFileContent(java.lang.String)
1429     */

1430    public byte[] getVirtualFileContent(String JavaDoc sFullPath) {
1431        byte[] dataRetn = null;
1432
1433        sFullPath = this.getInitialPath() + sFullPath;
1434        
1435        Get method = new Get(sFullPath);
1436        
1437        try {
1438            HTTPResponse httpResponse = this.m_conn.Get(sFullPath);
1439            
1440            if(httpResponse.getStatusCode()<200 || httpResponse.getStatusCode()>=300) {
1441                this.fireErrorEvent("ContentNotRetrieved", "The content for " + sFullPath + " could not be retrieved.");
1442            } else {
1443                InputStream inStream = httpResponse.getInputStream();
1444                ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
1445                
1446                int i = inStream.read();
1447                while(i!=-1) {
1448                    byteOut.write(i);
1449                    i = inStream.read();
1450                }
1451                dataRetn = byteOut.toByteArray();
1452                this.setFileContentPopulated( this.m_cache.getFile(sFullPath), true );
1453            }
1454            
1455// WebDAVResponse response = this.m_conn.execute(method);
1456
// dataRetn = response.getResponseData();
1457
// this.setFileContentPopulated( this.m_cache.getFile(sFullPath), true );
1458
//
1459
// if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1460
// this.fireErrorEvent("ContentNotRetrieved", "The content for " + sFullPath + " could not be retrieved.");
1461
// }
1462
} catch (IOException e) {
1463            e.printStackTrace();
1464            this.fireErrorEvent("ContentNotRetrieved", "The content for " + sFullPath + " could not be retrieved.");
1465        } catch (ModuleException e) {
1466            e.printStackTrace();
1467            this.fireErrorEvent("ContentNotRetrieved", "The content for " + sFullPath + " could not be retrieved.");
1468        }
1469
1470        return dataRetn;
1471    }
1472
1473    /* (non-Javadoc)
1474     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getVirtualFileView()
1475     */

1476    public VirtualFileSystemView getVirtualFileSystemView() {
1477        if( this.m_vfView==null ) {
1478            this.m_vfView = new WebDAVFileSystemView();
1479        }
1480
1481        return this.m_vfView;
1482    }
1483
1484    /* (non-Javadoc)
1485     * @see HTTPClient.AuthorizationHandler#getAuthorization(HTTPClient.AuthorizationInfo, HTTPClient.RoRequest, HTTPClient.RoResponse)
1486     */

1487    public AuthorizationInfo getAuthorization(AuthorizationInfo arg0, RoRequest arg1, RoResponse arg2) throws AuthSchemeNotImplException, IOException {
1488        AuthorizationInfo authRetn = arg0;
1489        
1490        String JavaDoc sUsername = this.getAuthentication().getUsername();
1491        String JavaDoc sPassword = this.getAuthentication().getPassword();
1492        
1493        String JavaDoc sCookie = sUsername.trim() + ":" + sPassword.trim();
1494        
1495        authRetn.setCookie( new BASE64Encoder().encode( sCookie.getBytes() ) );
1496        AuthorizationInfo.addBasicAuthorization(arg0.getHost(), arg0.getPort(), arg0.getRealm(), sUsername, sPassword);
1497        AuthorizationInfo.addBasicAuthorization("localhost", 7000, arg0.getRealm(), sUsername, sPassword);
1498        
1499        return authRetn;
1500    }
1501
1502    /* (non-Javadoc)
1503     * @see HTTPClient.AuthorizationHandler#fixupAuthInfo(HTTPClient.AuthorizationInfo, HTTPClient.RoRequest, HTTPClient.AuthorizationInfo, HTTPClient.RoResponse)
1504     */

1505    public AuthorizationInfo fixupAuthInfo(AuthorizationInfo arg0, RoRequest arg1, AuthorizationInfo arg2, RoResponse arg3) throws AuthSchemeNotImplException, IOException {
1506        AuthorizationInfo authRetn = arg0;
1507        
1508        String JavaDoc sUsername = this.getAuthentication().getUsername();
1509        String JavaDoc sPassword = this.getAuthentication().getPassword();
1510        
1511        String JavaDoc sCookie = sUsername.trim() + ":" + sPassword.trim();
1512        
1513        authRetn.setCookie( new BASE64Encoder().encode( sCookie.getBytes() ) );
1514        AuthorizationInfo.addBasicAuthorization(arg0.getHost(), arg0.getPort(), arg0.getRealm(), sUsername, sPassword);
1515        AuthorizationInfo.addBasicAuthorization("localhost", 7000, arg0.getRealm(), sUsername, sPassword);
1516        
1517        return authRetn;
1518    }
1519    
1520    /**
1521     * Attempts to use a username and password to check if they are
1522     * valid.
1523     *
1524     * @param sPath Path to use to check authentication information
1525     * @param sUsername Username
1526     * @param sPassword Password
1527     * @return true if the authentication information was okay
1528     */

1529    public boolean checkLoginDetails(String JavaDoc sPath, String JavaDoc sUsername, String JavaDoc sPassword) {
1530        boolean bOK = true;
1531        
1532        String JavaDoc sCookie = "BASIC " + sUsername.trim() + ":" + sPassword.trim();
1533        String JavaDoc sValue = new BASE64Encoder().encode( sCookie.getBytes() );
1534        
1535        PropFind method = new PropFind(sPath);
1536        
1537        method.setDepth( PropFind.DEPTH_0 );
1538        method.addProperty( PropFind.WEBDAV_NAMESPACE, "resourcetype" );
1539        try {
1540            AuthorizationInfo.addBasicAuthorization(this.m_conn.getHost(), this.m_conn.getPort(), "OHRM", sUsername, sPassword);
1541            AuthorizationInfo.setAuthHandler(null);
1542            WebDAVResponse response = this.m_conn.execute(method);
1543            AuthorizationInfo.setAuthHandler(this);
1544            AuthorizationInfo.removeAuthorization(this.m_conn.getHost(), this.m_conn.getPort(), "BASIC", "OHRM");
1545            
1546            if(response.getStatusCode()==401 || response.getResponseData()==null) {
1547                bOK=false;
1548            }
1549
1550        } catch (IOException e) {
1551            bOK = false;
1552        } catch (ModuleException e) {
1553            bOK = false;
1554        }
1555        
1556        return bOK;
1557    }
1558    
1559    /**
1560     * Changes the authentication information being used by this virtual
1561     * file system.
1562     *
1563     * @param sUsername New username
1564     * @param sPassword New password
1565     */

1566    public void changeLoginDetails(String JavaDoc sUsername, String JavaDoc sPassword) {
1567        this.getAuthentication().setUsername(sUsername);
1568        this.getAuthentication().setPassword(sPassword);
1569        AuthorizationInfo.removeAuthorization(this.m_conn.getHost(), this.m_conn.getPort(), "BASIC", "OHRM");
1570        AuthorizationInfo.addBasicAuthorization(this.m_conn.getHost(), this.m_conn.getPort(), "OHRM", sUsername, sPassword);
1571        AuthorizationInfo.setAuthHandler(this);
1572    }
1573    
1574    /**
1575     * Creates a HTTP authentication header value from the authentication
1576     * information for this virtual file system.
1577     *
1578     * @return HTTP authentication header value
1579     */

1580    public String JavaDoc getAuthHeaderValue() {
1581        String JavaDoc sUsername = this.getAuthentication().getUsername();
1582        String JavaDoc sPassword = this.getAuthentication().getPassword();
1583        
1584        String JavaDoc sCookie = sUsername.trim() + ":" + sPassword.trim();
1585        
1586        return new BASE64Encoder().encode( sCookie.getBytes() );
1587    }
1588
1589    /* (non-Javadoc)
1590     * @see HTTPClient.AuthorizationHandler#handleAuthHeaders(HTTPClient.Response, HTTPClient.RoRequest, HTTPClient.AuthorizationInfo, HTTPClient.AuthorizationInfo)
1591     */

1592    public void handleAuthHeaders(Response arg0, RoRequest arg1, AuthorizationInfo arg2, AuthorizationInfo arg3) throws IOException {
1593        
1594
1595    }
1596
1597    /* (non-Javadoc)
1598     * @see HTTPClient.AuthorizationHandler#handleAuthTrailers(HTTPClient.Response, HTTPClient.RoRequest, HTTPClient.AuthorizationInfo, HTTPClient.AuthorizationInfo)
1599     */

1600    public void handleAuthTrailers(Response arg0, RoRequest arg1, AuthorizationInfo arg2, AuthorizationInfo arg3) throws IOException {
1601        
1602    }
1603
1604    /* (non-Javadoc)
1605     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#synchroniseFile(com.simulacramedia.vfs.VirtualFile)
1606     */

1607    public StatusData synchroniseFile(VirtualFile vfFile) {
1608        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1609        retnStatus.setMethodName(VirtualFile.METHOD_SYNC);
1610
1611        VersionedVirtualFile vfSyncFile = (VersionedVirtualFile) vfFile;
1612
1613        if (vfSyncFile.isChanged()) {
1614            if(vfSyncFile.getState().equals(VirtualFile.STATE_LIVE) && !vfSyncFile.hasPendingVersion()) {
1615                
1616                StatusData checkoutStatus = this.checkoutVirtualFile(vfSyncFile.getFullPath());
1617                retnStatus.addStatusData(checkoutStatus);
1618                if(checkoutStatus.isOK()) {
1619                    String JavaDoc sPendingPath = vfSyncFile.getPendingVersionPath();
1620                    VersionedVirtualFile vfPendingFile = (VersionedVirtualFile) this.getVirtualFile(sPendingPath).getResource();
1621                    if(vfFile.isContentChanged()) {
1622                        vfPendingFile.setContent(vfSyncFile.getContent());
1623                        StatusData syncContentsStatus = this.syncContents(vfPendingFile);
1624                        retnStatus.addStatusData(syncContentsStatus);
1625                    }
1626                    if(vfFile.isMetadataChanged()) {
1627                        this.fullyPopulateFileMetadata(vfPendingFile);
1628                        Iterator itor = vfSyncFile.getProperties().iterator();
1629                        //TODO Need to change to NOT copy Workflow Props
1630
while (itor.hasNext()) {
1631                            PropertyInstance element = (PropertyInstance) itor.next();
1632                            if(!element.getDefinition().getNamespace().equals(NamespaceType.OHRM_WORKFLOW.getURI())) {
1633                                PropertyInstance newPropInst = new PropertyInstance(element.getNamespaceURI(), element.getName(), element.getValues());
1634                                String JavaDoc sDefnPath = element.getDefinitionPath();
1635                                String JavaDoc sDefnVer = element.getDefinitionVersion();
1636                                if(sDefnPath!=null && sDefnVer!=null) {
1637                                    newPropInst.setDefinitionPath(sDefnPath, sDefnVer);
1638                                }
1639                                vfPendingFile.addProperty(newPropInst);
1640                            }
1641                        }
1642                        this.setFileMetadataPopulated(vfPendingFile, true);
1643                        StatusData syncMetadataStatus = this.syncMetadata(vfPendingFile);
1644                        retnStatus.addStatusData(syncMetadataStatus);
1645                    }
1646                    this.discardFileChanges(vfFile.getFullPath());
1647                    this.discardFileChanges(vfPendingFile.getFullPath());
1648                }
1649            
1650                if(!retnStatus.isOK()) {
1651                    this.clearAllFileProperties(vfFile);
1652                    this.m_cache.removeFile(vfSyncFile.getFullPath());
1653                }
1654            } else if(vfSyncFile.getState().equals(VirtualFile.STATE_PENDING)
1655                        && vfSyncFile.getLiveVersionPath()==null) {
1656
1657                if(vfSyncFile.isContentChanged()) {
1658                    StatusData syncContentsStatus = this.syncContents(vfSyncFile);
1659                    retnStatus.addStatusData(syncContentsStatus);
1660                }
1661                
1662                if(retnStatus.isOK() && vfSyncFile.isMetadataChanged()) {
1663                    StatusData syncMetadataStatus = this.syncMetadata(vfSyncFile);
1664                    retnStatus.addStatusData(syncMetadataStatus);
1665                }
1666            
1667                if(retnStatus.isOK()) {
1668                    this.discardFileChanges(vfSyncFile.getFullPath());
1669                }
1670            } else if( vfSyncFile.getState().equals(VirtualFile.STATE_PENDING) ) {
1671
1672                if(vfSyncFile.isContentChanged()) {
1673                    StatusData syncContentsStatus = this.syncContents(vfSyncFile);
1674                    retnStatus.addStatusData(syncContentsStatus);
1675                }
1676                
1677                if(retnStatus.isOK() && vfSyncFile.isMetadataChanged()) {
1678                    StatusData syncMetadataStatus = this.syncMetadata(vfSyncFile);
1679                    retnStatus.addStatusData(syncMetadataStatus);
1680                }
1681            
1682                if(retnStatus.isOK()) {
1683                    this.discardFileChanges(vfSyncFile.getFullPath());
1684                    this.discardFileChanges(vfSyncFile.getLiveVersionPath());
1685                }
1686            }
1687        }
1688
1689        return retnStatus;
1690    }
1691    
1692    /**
1693     * Submits the contents of a virtual file back to the WebDAV server.
1694     *
1695     * @param vfFile Virtual file to submit contents for
1696     * @return true if the method was successful
1697     */

1698    private StatusData syncContents(VirtualFile vfFile) {
1699        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1700        retnStatus.setMethodName(VirtualFile.METHOD_SYNC);
1701        String JavaDoc sFullPath = vfFile.getFullPath();
1702        
1703        String JavaDoc sPath = this.getInitialPath() + sFullPath;
1704        if(vfFile.isDirectory()) {
1705            sPath = sPath + "/";
1706        }
1707        
1708        Put method = new Put(sPath);
1709        method.setData(vfFile.getContent());
1710        
1711        String JavaDoc sContentType = this.getVirtualFileSystemView().getContentType(vfFile);
1712        if(sContentType!=null && !sContentType.equals("")) {
1713            method.addHeader("Content-Type", sContentType);
1714        }
1715        
1716        if(vfFile.isLocked()) {
1717            String JavaDoc sTokenPath = WebDAVConnection.URLEncode( vfFile.getFullPath() );
1718            if(vfFile.isDirectory()) {
1719                sTokenPath = sTokenPath + "/";
1720            }
1721            method.addHeader("If", "<" + sTokenPath + "> (<" + vfFile.getLockToken() + ">)");
1722        }
1723        
1724        try {
1725            WebDAVResponse response = this.m_conn.execute(method);
1726            retnStatus.setHTTPStatus(response.getStatusCode());
1727        
1728            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1729                this.fireErrorEvent("FileContentsNotSynchronized", "The file " + sFullPath + " cannot have its contents synchronized.");
1730            }
1731            
1732        } catch (IOException e) {
1733            e.printStackTrace();
1734            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1735            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1736            this.fireErrorEvent("FileContentsNotSynchronized", "The file " + sFullPath + " cannot have its contents synchronized.");
1737        } catch (ModuleException e) {
1738            e.printStackTrace();
1739            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1740            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1741            this.fireErrorEvent("FileContentsNotSynchronized", "The file " + sFullPath + " cannot have its contents synchronized.");
1742        }
1743
1744        return retnStatus;
1745    }
1746    
1747    /**
1748     * Submits the metadata of a virtual file back to the WebDAV server.
1749     *
1750     * @param vfFile Virtual file to submit metadata for
1751     * @return true if the method was successful
1752     */

1753    private StatusData syncMetadata(VirtualFile vfFile) {
1754        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1755        retnStatus.setMethodName(VirtualFile.METHOD_SYNC);
1756        String JavaDoc sFullPath = vfFile.getFullPath();
1757        
1758        String JavaDoc sPath = this.getInitialPath() + sFullPath;
1759
1760        if(vfFile.isDirectory()) {
1761            sPath = sPath + "/";
1762        }
1763        PropPatch method = new PropPatch(sPath, vfFile);
1764        
1765        if(vfFile.isLocked()) {
1766            String JavaDoc sTokenPath = WebDAVConnection.URLEncode( vfFile.getFullPath() );
1767            if(vfFile.isDirectory()) {
1768                sTokenPath = sTokenPath + "/";
1769            }
1770            method.addHeader("If", "<" + sTokenPath + "> (<" + vfFile.getLockToken() + ">)");
1771        }
1772        
1773        try {
1774            WebDAVResponse response = this.m_conn.execute(method);
1775            retnStatus.setHTTPStatus(response.getStatusCode());
1776        
1777            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1778                this.fireErrorEvent("FileMetadataNotSynchronized", "The file " + sFullPath + " cannot have its metadata synchronized.");
1779            }
1780            
1781        } catch (IOException e) {
1782            e.printStackTrace();
1783            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1784            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1785            this.fireErrorEvent("FileMetadataNotSynchronized", "The file " + sFullPath + " cannot have its metadata synchronized.");
1786        } catch (ModuleException e) {
1787            e.printStackTrace();
1788            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1789            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1790            this.fireErrorEvent("FileMetadataNotSynchronized", "The file " + sFullPath + " cannot have its metadata synchronized.");
1791        }
1792
1793        return retnStatus;
1794    }
1795
1796    /* (non-Javadoc)
1797     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#sunchroniseAllFiles()
1798     */

1799    public StatusData synchroniseAllFiles() {
1800        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1801        retnStatus.setMethodName(VirtualFile.METHOD_SYNC);
1802
1803        Iterator itor = this.m_cache.getPaths().iterator();
1804        while (itor.hasNext()) {
1805            String JavaDoc sFullPath = (String JavaDoc) itor.next();
1806            VirtualFile vfFile = this.m_cache.getFile(sFullPath);
1807            if (vfFile!=null && vfFile.isChanged()) {
1808                StatusData status = vfFile.sync();
1809                retnStatus.addStatusData(status);
1810            }
1811        }
1812
1813        return retnStatus;
1814    }
1815
1816    /* (non-Javadoc)
1817     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#exists(java.lang.String)
1818     */

1819    public boolean exists(String JavaDoc sFullPath) {
1820        boolean bExists = true;
1821        
1822        return bExists;
1823    }
1824
1825    /* (non-Javadoc)
1826     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#refreshChildren(com.simulacramedia.vfs.VirtualFile)
1827     */

1828    protected void refreshChildren(VirtualFile vfFile) {
1829        Iterator itor = vfFile.getChildren().iterator();
1830        while(itor.hasNext()) {
1831            String JavaDoc sChildPath = (String JavaDoc)itor.next();
1832            VirtualFile vfChild = this.getVirtualFile(sChildPath).getResource();
1833            if(vfChild!=null && !vfChild.isChanged()) {
1834                if(vfChild.isVersionable() && ((VersionedVirtualFile)vfChild).hasPendingVersion()) {
1835                    VersionedVirtualFile vfPending = (VersionedVirtualFile) vfChild.getVFS().getVirtualFile( ((VersionedVirtualFile)vfChild).getPendingVersionPath() ).getResource();
1836                    if(!vfPending.isChanged()) {
1837                        this.m_cache.removeFile(vfPending.getFullPath());
1838                    } else {
1839                        this.checkFileForNewMetadata(vfPending);
1840                    }
1841                }
1842                this.m_cache.removeFile(sChildPath);
1843            } else if(vfChild!=null && vfChild.isChanged()) {
1844                this.checkFileForNewMetadata(vfFile);
1845            } else if(vfChild==null) {
1846                vfFile.removeChild(sChildPath);
1847            }
1848        }
1849    }
1850
1851    /* (non-Javadoc)
1852     * @see com.simulacramedia.vfs.AbstractVersioningVFS#reactivateVertsion(java.lang.String)
1853     */

1854    public StatusData reactivateVersion(String JavaDoc sFullPath) {
1855        return this.checkoutVirtualFile(sFullPath);
1856    }
1857
1858    /* (non-Javadoc)
1859     * @see com.simulacramedia.vfs.AbstractVersioningVFS#fullyPopulateFileHistory(com.simulacramedia.vfs.VirtualFile)
1860     */

1861    protected void fullyPopulateFileHistory(VersionedVirtualFile vfFile) {
1862        String JavaDoc sRealPath = this.getInitialPath() + vfFile.getFullPath();
1863
1864
1865        if(vfFile.isDirectory()) {
1866            sRealPath = sRealPath + "/";
1867        }
1868        PropFind method = new PropFind(sRealPath);
1869        method.setDepth( PropFind.DEPTH_0 );
1870        method.addProperty( PropFind.WEBDAV_NAMESPACE, "predecessor-set" );
1871        
1872        try {
1873            WebDAVResponse response = this.m_conn.execute(method);
1874            this.getVirtualFile(response, vfFile, sRealPath);
1875        
1876            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1877                this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
1878            }
1879            
1880            this.setFileHistoryPopulated(vfFile, true);
1881        } catch (IOException e) {
1882            this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
1883            e.printStackTrace();
1884            this.setFileMetadataPopulated(vfFile, false);
1885        } catch (ModuleException e) {
1886            this.fireErrorEvent("FileNotFound", "The file " + vfFile.getFullPath() + " cannot be found.");
1887            e.printStackTrace();
1888            this.setFileMetadataPopulated(vfFile, false);
1889        }
1890    }
1891
1892    /* (non-Javadoc)
1893     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#orderVirtualFileChildren(java.util.List, com.simulacramedia.vfs.VirtualFile)
1894     */

1895    public StatusData orderVirtualFileChildren(List aPaths, VirtualFile vfDir) {
1896        VFSStatusWebDAV retnStatus = new VFSStatusWebDAV();
1897        retnStatus.setMethodName(VirtualFile.METHOD_ORDER);
1898        
1899        String JavaDoc sPath = this.getInitialPath() + vfDir.getFullPath();
1900
1901
1902        if(vfDir.isDirectory()) {
1903            sPath = sPath + "/";
1904        }
1905        OrderPatch method = new OrderPatch(sPath);
1906        method.setOrderedPaths(aPaths);
1907        try {
1908            WebDAVResponse response = this.m_conn.execute(method);
1909            
1910            retnStatus.setHTTPStatus(response.getStatusCode());
1911        
1912            if(response.getStatusCode()<200 || response.getStatusCode()>=300) {
1913                this.fireErrorEvent("DirectoryMembersNotOrdered", "The directory " + sPath + " could not have its members orderer.");
1914            }
1915        } catch (IOException e) {
1916            e.printStackTrace();
1917            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1918            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1919            this.fireErrorEvent("DirectoryMembersNotOrdered", "The directory " + sPath + " could not have its members orderer.");
1920        } catch (ModuleException e) {
1921            e.printStackTrace();
1922            retnStatus.setStatusCode(StatusData.STATUS_COMMUNICATIONS_FAILURE);
1923            retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1924            this.fireErrorEvent("DirectoryMembersNotOrdered", "The directory " + sPath + " could not have its members orderer.");
1925        }
1926
1927        return retnStatus;
1928    }
1929
1930    /* (non-Javadoc)
1931     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getNewValueInstance(com.simulacramedia.vfs.metadata.PropertyInstance)
1932     */

1933    public ValueInstance getNewValueInstance(PropertyInstance propInst) {
1934        ValueInstance val = null;
1935        
1936        Range range = propInst.getDefinition().getRange();
1937        
1938        if(propInst.getName().equalsIgnoreCase("domain")) {
1939            val = new DAVDomainValue();
1940        } else if(propInst.getName().equalsIgnoreCase("range")) {
1941            val = new DAVRangeValue();
1942        } else if(range instanceof BooleanRange) {
1943            val = new DAVBooleanValue();
1944        } else if(range instanceof DateTimeRange) {
1945            val = new DAVDateTimeValue();
1946        } else if(range instanceof DateRange) {
1947            val = new DAVDateValue();
1948        } else if(range instanceof DomainRange) {
1949            val = new DAVDomainValue();
1950        } else if(range instanceof FloatRange) {
1951            val = new DAVFloatValue();
1952        } else if(range instanceof IntegerRange) {
1953            val = new DAVIntegerValue();
1954        } else if(range instanceof PropertyRange) {
1955            val = new DAVPropertyValue();
1956        } else if(range instanceof RangeRange) {
1957            val = new DAVRangeValue();
1958        } else if(range instanceof ResourceRange || range instanceof CollectionRange) {
1959            val = new DAVResourceValue();
1960        } else if(range instanceof URIRange) {
1961            val = new DAVURIValue();
1962        } else if(range instanceof ValueRange) {
1963            val = new DAVValueValue();
1964        } else if(range instanceof StringRange) {
1965            val = new DAVStringValue();
1966        } else {
1967            val = new DAVStringValue();
1968        }
1969        
1970        return val;
1971    }
1972
1973    /* (non-Javadoc)
1974     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#rejectAllChanges()
1975     */

1976    public boolean rejectAllChanges() {
1977        boolean bError = false;
1978
1979        Iterator itor = this.m_cache.getPaths().iterator();
1980        while (itor.hasNext()) {
1981            String JavaDoc sFullPath = (String JavaDoc) itor.next();
1982            VirtualFile vfFile = this.m_cache.getFile(sFullPath);
1983            if (vfFile!=null && vfFile.isChanged()) {
1984                this.discardFileChanges(sFullPath);
1985            }
1986        }
1987
1988        return !bError;
1989    }
1990
1991    /* (non-Javadoc)
1992     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#fullyPopulateFileAllowedMethods(com.simulacramedia.vfs.VirtualFile)
1993     */

1994    protected void fullyPopulateFileAllowedMethods(VirtualFile vfFile) {
1995        this.populateFileAllowedMethods(vfFile);
1996    }
1997
1998    /* (non-Javadoc)
1999     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#currentUserResourcePath()
2000     */

2001    public String JavaDoc currentUserResourcePath(AuthInfo authInfo) {
2002        String JavaDoc sUserPath = null;
2003        URL endPointURL = null;
2004        try {
2005            URI JavaDoc uri = this.getURI();
2006            String JavaDoc sURL = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/DAVService";
2007            endPointURL = new URL(sURL);
2008            
2009            sUserPath = UserDetailsService.getUserPath(endPointURL, authInfo.getUsername());
2010        } catch (RemoteException e) {
2011            e.printStackTrace();
2012        } catch (ServiceException e) {
2013            e.printStackTrace();
2014        } catch (MalformedURLException e) {
2015            e.printStackTrace();
2016        }
2017        
2018        return sUserPath;
2019    }
2020
2021    /* (non-Javadoc)
2022     * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getChangedVirtualFiles()
2023     */

2024    public List getChangedVirtualFiles() {
2025        List aFiles = new ArrayList();
2026        
2027        Iterator itor = this.m_cache.getPaths().iterator();
2028        while (itor.hasNext()) {
2029            String JavaDoc sFullPath = (String JavaDoc) itor.next();
2030            VirtualFile vfFile = this.m_cache.getFile(sFullPath);
2031            if (vfFile!=null && vfFile.isChanged()) {
2032                aFiles.add(vfFile);
2033            }
2034        }
2035        
2036        return aFiles;
2037    }
2038
2039    /* (non-Javadoc)
2040     * @see org.openharmonise.vfs.AbstractVirtualFileSystem#getPropertyVirtualFile(java.lang.String)
2041     */

2042    public VirtualFile getPropertyVirtualFile(String JavaDoc sPropPath) {
2043        ArrayList aProps = new ArrayList();
2044        PropFindProperty propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "resourcetype" );
2045        aProps.add(propTemp);
2046        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "lockdiscovery" );
2047        aProps.add(propTemp);
2048        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "creationdate" );
2049        aProps.add(propTemp);
2050        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "getlastmodified" );
2051        aProps.add(propTemp);
2052        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "getcontenttype" );
2053        aProps.add(propTemp);
2054        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "checked-in" );
2055        aProps.add(propTemp);
2056        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "checked-out" );
2057        aProps.add(propTemp);
2058        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "checkout-set" );
2059        aProps.add(propTemp);
2060        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "successor-set" );
2061        aProps.add(propTemp);
2062        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "range" );
2063        aProps.add(propTemp);
2064        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "domain" );
2065        aProps.add(propTemp);
2066        propTemp = new PropFindProperty( PropFind.WEBDAV_NAMESPACE, "version-name" );
2067        aProps.add(propTemp);
2068        propTemp = new PropFindProperty( NamespaceType.OHRM.getURI(), "title" );
2069        aProps.add(propTemp);
2070        propTemp = new PropFindProperty( NamespaceType.OHRM.getURI(), "description" );
2071        aProps.add(propTemp);
2072        propTemp = new PropFindProperty( NamespaceType.OHRM.getURI(), "harmonise-id" );
2073        aProps.add(propTemp);
2074        
2075        return getVirtualFile(sPropPath, aProps).getResource();
2076    }
2077
2078    
2079}
2080
Popular Tags