November 2004
Intermediate to advanced
400 pages
10h 31m
English
You need to modify a WebDAV resource.
Use the putMethod( )
on WebdavResource, and
be sure to lock and unlock the resource before and after
modification. The following example demonstrates the use of
lockMethod( )
, putMethod( ), and
unlockMethod( )
to modify a resource:
importorg.apache.commons.httpclient.Credentials;importorg.apache.commons.httpclient.HttpClient;importorg.apache.commons.httpclient.HttpException;importorg.apache.commons.httpclient.UsernamePasswordCredentials;importorg.apache.webdav.lib.WebdavResource; String url = "http://www.discursive.com/jccook/dav/test.html"; Credentials credentials =newUsernamePasswordCredentials("davuser", "davpass"); // List resources in top directory WebdavResource resource =newWebdavResource(url, credentials); // Lock the Resource for 100 secondsbooleanlocked = resource.lockMethod( "tobrien", 100 );if( locked ) {try{ // Read content as a String String resourceData = resource.getMethodDataAsString( ); // Modify a resource System.out.println( "*** Modifying Resource"); resourceData = resourceData.replaceAll( "test", "modified test" ); resource.putMethod( resourceData ); }finally{ // Unlock the resource resource.unlockMethod( ); } } // Close the resource resource.close( );
lockMethod( ) accepts an owner and a timeout; the
owner is the owner of the lock, and the timeout is the timeout of the
lock in number of seconds. When locking a resource, the
lockMethod( ...
Read now
Unlock full access