November 2004
Intermediate to advanced
400 pages
10h 31m
English
You need to connect to a WebDAV resource and list the contents of a collection. As with most WebDAV resources, you need to supply authentication information.
Create an instance of WebdavResource, passing in a
URL and a UsernamePasswordCredential object. List
the contents of a WebDAV collection by calling the
listWebdavResources()
method. The following example demonstrates
the use of WebdavResource to list the contents of
a WebDAV collection:
importorg.apache.commons.httpclient.Credentials;importorg.apache.commons.httpclient.HttpClient;importorg.apache.commons.httpclient.HttpException;importorg.apache.commons.httpclient.UsernamePasswordCredentials;importorg.apache.commons.lang.StringUtils;importorg.apache.commons.lang.time.FastDateFormat;importorg.apache.webdav.lib.WebdavResource; HttpClient client =newHttpClient( ); String url = "http://www.discursive.com/jccook/dav/"; Credentials credentials =newUsernamePasswordCredentials("davuser", "davpass"); // List resources in top directory WebdavResource resource =newWebdavResource(url, credentials); WebdavResource[] resources = resource.listWebdavResources( ); System.out.println( "type name size type" + " modified"); System.out.println( "-----------------------------------------" + "---------------------------");for(inti = 0; i < resources.length; i++ ) { WebdavResource item = resources[i]; String type;if( item.isCollection( ) ) { type = "dir"; }else{ type ...
Read now
Unlock full access