WebDav Java and C# Client Library
WebDav Clients are two similar Java and C# libraries that allow using all WebDav services and features.
The main parts of the projects are:
- Commands - a set of classes that implements all standard WebDav commands.
- Documents - the prototypes of XML response documents.
- Properties - a set of properties supported by the repository. Properties can be singlevalued or multivalued.
- Search - the implementation of search commands.
The following list of commands is available:
- PropFind, Report, Options, Search, OrderPatch commands - multistatus commands, which require an XML-request and normally return 207 status and an XML-response.
- Get, Put commands - commands for transmitting (receiving)the contents of the file from/to server. GET returns 200(Ok) or 206 (Partial Content), PUT returns 201(Created) when successful.
- Copy, Move commands - simple commands that only return 201 status when successful, require a ResourcePath and a DestinationPath in the request parameters.
- MkCol command - creates a node on the server.
- Delete - deletes a node from the server.
- Version Control, Check In, Check Out, UnCheckOut commands - used for enabling and operating with versionable files and folders, return a 200 or 201 (for Check-In command) status.
- Lock, Unlock commands - used for locking and unlocking folders on the server.
The Lock command returns a 200 status with the Lock Token key, which must be used for
unlocking a folder back (UnLock must return 204 ).
- PropPatch command - the command for modifying node properties in the repository.
- Head command - the information and test command, retrieves only headers from the server.
Supported DAV properties:
- Checked In;
- Checked Out;
- Content Length;
- Content Type;
- Creator Display Name;
- Display Name;
- Last Modified;
- Lock Discovery;
- Resource Type;
- Supported Lock;
- Supported Method;
- Supported Query Grammar Set;
- Version Name and others;
For the full properties list please refer to DavProperties.java or DavProperties.cs files.
Supported Search methods:
- XPath Search;
- SQL Search;
- Basic Search;
To execute a
multistatus command you need to complete these steps:
| Java Library | C# Library | |
|---|
| Create an instance of the WebDavContext class with the appropriate Server address, port, servlet path, username and password. | Create an instance of the DavContext class with the appropriate Server address, port, servlet path, username and password. | |
| Initialize a new command with this ServerLocation. | Initialize a new command with this DavContext. | |
| Set the resource path for the command | Set resource path for the command. | |
| Add required properties to the command. | Add required properties to the command. | |
| Execute the command. | Execute the command. | |
Code example:
DavContext context = new DavContext("localhost", 8080,"/jcr-webdav/repository", "admin", "admin" );
PropFindCommand propFind = new PropFindCommand(context);
propFind.setResourcePath("/production");
propFind.addRequiredProperty(DavProperty.DISPLAYNAME);
propFind.addRequiredProperty(DavProperty.GETCONTENTTYPE);
propFind.addRequiredProperty(DavProperty.RESOURCETYPE);
propFind.addRequiredProperty(DavProperty.GETLASTMODIFIED);
propFind.addRequiredProperty(DavProperty.SUPPORTEDLOCK);
int status = propFind.execute();
To execute a
simple command (
Delete, Version Control, Check In, Check Out) you need to complete these steps:
| Java Library | C# Library | |
|---|
| Create an instance of the WebDavContext class with the appropriate Server address, port, servlet path, username and password. | Create an instance of theDavContext class with the appropriate Server address, port, servlet path, username and password. | |
| Initialize a new command with this ServerLocation. | Initialize a new command with this DavContext. | |
| Set resource path for the command | Set resource path for the command. | |
| Execute the command. | Execute the command. | |
Code example:
DavContext context = new DavContext("localhost", 8080, "/jcr-webdav/repository");
VersionControlCommand vccomm = new VersionControlCommand(context);
vccomm.setResourcePath("/production/1/1.zip");
int status = vccomm.execute();
To execute a
Put command you need to complete these steps:
| Java Library | C# Library | |
|---|
| Create an instance of the WebDavContext class with the appropriate Server address, port, servlet path, username and password. | Create an instance of the DavContext class with the appropriate Server address, port, servlet path, username and password. | |
| Initialize a new command with this ServerLocation. | Initialize a new command with this DavContext. | |
| Set resource path for the command | Set resource path for the command. | |
| Prepare the contents of the uploaded file (setRequestDataBuffer(byte []) method) | Prepare the contents of the uploaded file (setRequestData(byte []) method.) | |
| Execute the command. | Execute the command. | |
Code example:
DavContext context = new DavContext("localhost", 8080, "/jcr-webdav/repository");
PutCommand put = new PutCommand(context);
put.setResourcePath("/production/1/1.txt");
byte[] data = put.getBytes("Contents of the file");
put.setRequestBody(data);
int status = put.execute();
To execute a
Copy, Move command you need to complete these steps:
| Java Library | C# Library | |
|---|
| Create an instance of the WebDavContext class with the appropriate Server address, port, servlet path, username and password. | Create an instance of the DavContext class with the appropriate Server address, port, servlet path, username and password. | |
| Initialize a new command with this ServerLocation. | Initialize a new command with this DavContext. | |
| Set resource path for the command | Set resource path for the command. | |
| Set destination path for the command. | Set destination path for the command. | |
| Execute the command. | Execute the command. | |
Code example:
DavContext context = new DavContext("localhost", 8080, "/jcr-webdav/repository");
CopyCommand copy = new CopyCommand(context);
copy.setResourcePath(srcName);
copy.setDestinationPath(destName);
int status = copy.execute();
To execute a
Search command you need to complete these steps:
| Java Library | C# Library | |
|---|
| Create an instance of the WebDavContext class with the appropriate Server address, port, servlet path, username and password. | Create an instance of the DavContext class with the appropriate Server address, port, servlet path, username and password. | |
| Initialize a new command with this ServerLocation. | Initialize a new command with this DavContext. | |
| Set resource path for the command | Set resource path for the command. | |
| Create a new instance of a query (SQLQuery, XPath query, or Basic Search Query). | Create a new instance of a query (SQLQuery, XPath query, or Basic Search Query). | |
| Set the query text. (e.g."select * from nt:file"). | Set the query text. (e.g."select * from nt:file"). | |
| Append the query to the command (setQuery() method) | Append the query to the command (setQuery() method) | |
| Execute the command. | Execute the command. | |
Code example:
DavContext context = new DavContext("localhost", 8080, "/jcr-webdav/repository");
SearchCommand searchcomm = new SearchCommand(context);
searchcomm.setResourcePath("/production");
SQLQuery query = new SQLQuery();
query.setQuery("select * from nt:file");
searchcomm.setQuery(query);
int status = searchcomm.execute();