dw.net
Class WebDAVClient
dw.net.WebDAVClient
The WebDAVClient class supports the WebDAV methods GET, PUT, MKCOL, MOVE,
COPY, PROPFIND,OPTIONS and DELETE.
Note: when this class is used with sensitive data, be careful in persisting sensitive information to disk.
The client can be used as shown in the following example:
var webdavClient : WebDAVClient = new WebDAVClient("http://mywebdav.server.com","myusername", "mypassword"); var getString : String = webdavClient.get("myData.xml","UTF-8"); var message : String; if (webdavClient.succeeded()) { message = webDavClient.statusText; } else { // error handling message="An error occured with status code "+webdavClient.statusCode; } var data : XML = new XML(getString);The WebDAV client supports the following authentication schemes:
- Basic authentication
- Digest authentication
Constants
DEFAULT_ENCODING
:
String = "UTF-8"
The default encoding character set.
DEFAULT_GET_FILE_SIZE
:
Number = 5242880
The default size for
get()
returning a File is 5MB.
DEFAULT_GET_STRING_SIZE
:
Number = 2097152
The default size for
get()
returning a String is 2MB.
DEPTH_0
:
Number = 0
The depth of searching a WebDAV destination using the PROPFIND method -
if that depth is given to the PROPFIND method as an input parameter the
destination will be searched only on the level of the given path and a
list of all containing files on that level will be returned [is not
supported by every server].
DEPTH_1
:
Number = 1
The depth of searching a WebDAV destination using the PROPFIND method -
if that depth is given to the PROPFIND method as an input parameter the
destination will be searched until one level under the given path and a
list of all containing files in that two levels [/path and one level
underneath] will be returned [is not supported by every server].
DEPTH_INIFINITY
:
Number = 2147483647
The depth of searching a WebDAV destination using the PROPFIND method -
if that depth is given to the PROPFIND method as an input parameter the
destination will be fully searched and a list of all containing files
will be returned [is not supported by every server].
MAX_GET_FILE_SIZE
:
Number = 209715200
The maximum size for
get()
returning a File is forty times
the default size for getting a file. The largest file allowed is 200MB.
MAX_GET_STRING_SIZE
:
Number = 10485760
The maximum size for
get()
returning a String is five
times the default size for getting a String. The largest String allowed
is 10MB.Properties
statusCode
:
Number
(Read Only)
The status code after the execution of a method.
statusText
:
String
(Read Only)
The status text after the execution of a method.
Constructor Summary
WebDAVClient(rootUrl
:
String, username
:
String, password
:
String)
Creates a new client for the use at a server which requires authentication.
WebDAVClient(rootUrl
:
String)
Creates a new client for the use at a server which does not require authentication.
Method Summary
addRequestHeader(headerName
:
String, headerValue
:
String)
:
void
Adds a request header to the next WebDAV call.
close()
:
void
Closes the current connection to the server.
copy(origin
:
String, destination
:
String)
:
boolean
Copies a file on the server from one place
rootUrl
/origin
to the other rootUrl
/destination
.
copy(origin
:
String, destination
:
String, overwrite
:
boolean)
:
boolean
Copies a file on the server from one place
rootUrl
/origin
to the other rootUrl
/destination
.
copy(origin
:
String, destination
:
String, overwrite
:
boolean, shallow
:
boolean)
:
boolean
Copies a file on the server from one place
rootUrl
/origin
to the other rootUrl
/destination
.
del(path
:
String)
:
boolean
Deletes a file or directory from the remote server that can be found under
rootUrl
/path
.
get(path
:
String)
:
String
Reads the content of a remote file or directory that can be found under
rootUrl
/path
and returns a string representation of the data found in the DEFAULT_ENCODING encoding.
get(path
:
String, encoding
:
String)
:
String
Reads the content of a remote file or directory that can be found under
rootUrl
/path
and returns a string representation of the data found in the given encoding
.
get(path
:
String, encoding
:
String, maxGetSize
:
Number)
:
String
Reads the content of a remote file or directory that can be found under
rootUrl
/path
and returns a string representation of the data found in the given encoding
.
get(path
:
String, file
:
File)
:
boolean
Reads the content of a remote file or directory that can be found under
rootUrl
/path
in DEFAULT_ENCODING encoding and writes a File in the system's standard encoding, which is "UTF-8".
get(path
:
String, file
:
File, maxFileSize
:
Number)
:
boolean
Reads the content of a remote file or directory that can be found under
rootUrl
/path
in DEFAULT_ENCODING encoding and writes a File in the system's standard encoding, which is "UTF-8".
get(path
:
String, file
:
File, encoding
:
String, maxFileSize
:
Number)
:
boolean
Reads the content of a remote file or directory that can be found under
rootUrl
/path
in the passed encoding and writes a File in the system standard encoding, which is "UTF-8".
getAllResponseHeaders()
:
HashMap
Returns a HashMap of all response headers.
getBinary(path
:
String, file
:
File)
:
boolean
Reads the content of a remote binary file that can be found under
rootUrl
/path
and creates a local copy in File.
getBinary(path
:
String, file
:
File, maxFileSize
:
Number)
:
boolean
Reads the content of a remote binary file that can be found under
rootUrl
/path
and creates a local copy in File.
getResponseHeader(header
:
String)
:
String
Returns a specified response header - multiple headers are separated by CRLF.
getStatusCode()
:
Number
Returns the status code after the execution of a method.
getStatusText()
:
String
Returns the status text after the execution of a method.
mkcol(path
:
String)
:
boolean
Creates a directory on the remote server on the location
rootUrl
/path
.
move(origin
:
String, destination
:
String)
:
boolean
Moves a file on the server from one place
rootUrl
+ "/" +origin
to the other rootUrl
/destination
.
move(origin
:
String, destination
:
String, overwrite
:
boolean)
:
boolean
Moves a file on the server from one place
rootUrl
/origin
to the other rootUrl
/destination
Can also be used to rename a remote file.
options(path
:
String)
:
String[]
Returns a list of methods which can be executed on the server location
rootUrl
/path
.
propfind(path
:
String)
:
WebDAVFileInfo[]
Get file listing of a remote location.
propfind(path
:
String, depth
:
Number)
:
WebDAVFileInfo[]
Get file listing of a remote location.
put(path
:
String, content
:
String)
:
boolean
Puts content encoded with DEFAULT_ENCODING into a remote located file at
rootUrl
/path
.
put(path
:
String, content
:
String, encoding
:
String)
:
boolean
Puts content encoded with the passed encoding into a remote located file at
rootUrl
/path
.
put(path
:
String, file
:
File)
:
boolean
Puts content out of a passed local file into a remote located file at
rootUrl
/path
.
succeeded()
:
boolean
Returns true if the last executed WebDAV method was executed successfully - otherwise false.
Methods inherited from class
Object
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
Constructor Detail
WebDAVClient
Creates a new client for the use at a server which requires
authentication.
The client supports the following authentication schemes:
- Basic authentication scheme
- Digest authentication scheme
Parameters:
rootUrl
-
the url of the server one wants to connect to. All commands will be executed by the client relative to that url.
username
-
username of the user for server authentication.
password
-
password of the user for server authentication.
WebDAVClient
public WebDAVClient(rootUrl
:
String)
Creates a new client for the use at a server which does not require
authentication.
Parameters:
rootUrl
-
the url of the server one wants to connect to. All commands will be executed by the client relative to that url.
Method Detail
addRequestHeader
Adds a request header to the next WebDAV call.
Parameters:
headerName
-
name of the header.
headerValue
-
value of the header.
copy
Copies a file on the server from one place
rootUrl
/origin
to the other rootUrl
/destination
. If
destination
already exists it gets overwritten. Returns
true if succeeded, otherwise false.
Parameters:
origin
-
The origin where a file is located, relative to the
rootUrl
stated when instantiating the client.
destination
-
The destination where the file should be copied to, relative to the
rootUrl
stated when instantiating the client.
Returns:
true if succeeded, otherwise false.
copy
Copies a file on the server from one place
rootUrl
/origin
to the other rootUrl
/destination
. If
the passed parameter overwrite
is true and
destination
already exists it gets overwritten. Returns
true if succeeded, otherwise false.
Parameters:
origin
-
The origin where a file is located, relative to the
rootUrl
stated when instantiating the client.
destination
-
The destination where the file should be copied to, relative to the
rootUrl
stated when instantiating the client.
overwrite
-
A flag which determines whether the destination gets overwritten if it exists before copying.
Returns:
true if succeeded, otherwise false.
copy
Copies a file on the server from one place
rootUrl
/origin
to the other rootUrl
/destination
. If
the passed parameter overwrite
is true and
destination
already exists it gets overwritten. If the
passed parameter shallow
is true a flat copy mechanism is
used.
Returns true if succeeded, otherwise false.
Parameters:
origin
-
The origin where a file is located, relative to the
rootUrl
stated when instantiating the client.
destination
-
The destination where the file should be copied to, relative to the
rootUrl
stated when instantiating the client.
overwrite
-
A flag which determines whether the destination gets overwritten if it exits before copying
shallow
-
A flag which determines how to copy the given data.
Returns:
true if succeeded, otherwise false.
del
del(path
:
String)
:
boolean
Deletes a file or directory from the remote server that can be found
under
rootUrl
/path
. Returns true if
succeeded, otherwise false.
Parameters:
path
-
The path of the file or collection to delete, relative to the
rootUrl
stated when instantiating the client.
Returns:
true if succeeded, otherwise false.
get
Reads the content of a remote file or directory that can be found under
rootUrl
/path
and returns a string
representation of the data found in the DEFAULT_ENCODING encoding. If the
remote location is a directory the result depends on the server
configuration, some return an HTML formatted directory listing. Returns
at most DEFAULT_GET_STRING_SIZE bytes.
Parameters:
path
-
The path of the collection or file one wants to get, relative to the
rootUrl
stated when instantiating the client.
Returns:
returns the String representation of the data found on the given path.
get
Reads the content of a remote file or directory that can be found under
rootUrl
/path
and returns a string
representation of the data found in the given encoding
. If
the remote location is a directory the result depends on the server
configuration, some return an HTML formatted directory listing. Returns
at most DEFAULT_GET_STRING_SIZE bytes.
Parameters:
path
-
The path of the collection or file one wants to get - relative to the
rootUrl
stated when instantiating the client.
encoding
-
The encoding of the resulting String.
Returns:
returns the String representation of the data found on the given path in the given encoding.
get
Reads the content of a remote file or directory that can be found under
rootUrl
/path
and returns a string
representation of the data found in the given encoding
. If
the remote location is a directory the result depends on the server
configuration, some return an HTML formatted directory listing. Returns
at most maxGetSize bytes.
Parameters:
path
-
The path of the collection or file one wants to get - relative to the
rootUrl
stated when instantiating the client.
encoding
-
The encoding of the resulting String.
maxGetSize
-
The maximum size of data in bytes. Not to exceed MAX_GET_STRING_SIZE.
Returns:
returns the String representation of the data found on the given path in the given encoding.
get
Reads the content of a remote file or directory that can be found under
rootUrl
/path
in DEFAULT_ENCODING
encoding and writes a File in the system's standard
encoding, which is "UTF-8". If the remote location is a directory the
result depends on the server configuration, some return an HTML formatted
directory listing. Receives at most DEFAULT_GET_FILE_SIZE bytes which
determines the file size of the local file. Returns true if succeeded
otherwise false.
Parameters:
path
-
The path of the collection or file one wants to get - relative to the
rootUrl
stated when instantiating the client.
file
-
The file to save the received data in.
Returns:
returns true if succeeded, otherwise false.
get
Reads the content of a remote file or directory that can be found under
rootUrl
/path
in DEFAULT_ENCODING
encoding and writes a File in the system's standard
encoding, which is "UTF-8". If the remote location is a directory the
result depends on the server configuration, some return an HTML formatted
directory listing. Receives at most maxFileSize bytes which determines
the file size of the local file. Returns true if succeeded, otherwise
false.
Parameters:
path
-
The path of the collection or file one wants to get - relative to the
rootUrl
stated when instantiating the client.
file
-
The file to save the received data in.
maxFileSize
-
The maximum size of bytes to stream into the file. Not to exceed MAX_GET_FILE_SIZE.
Returns:
returns true if succeeded, otherwise false.
get
Reads the content of a remote file or directory that can be found under
rootUrl
/path
in the passed encoding and
writes a File in the system standard encoding, which is
"UTF-8". If the remote location is a directory the result depends on the
server configuration, some return an HTML formatted directory listing.
Receives at most maxFileSize bytes which determines the file size of the
local file. Returns true if succeeded, otherwise false.
Parameters:
path
-
The path of the collection or file one wants to get - relative to the
rootUrl
stated when instantiating the client.
file
-
The file to save the received data in.
encoding
-
The encoding to use when reading the remote file.
maxFileSize
-
The maximum number of bytes to stream into the file. Not to exceed MAX_GET_FILE_SIZE.
Returns:
returns true if succeeded, otherwise false.
getAllResponseHeaders
getAllResponseHeaders()
:
HashMap
Returns a HashMap of all response headers.
Returns:
all headers in a HashMap.
getBinary
Reads the content of a remote binary file that can be found under
rootUrl
/path
and creates a local copy
in File. If the remote location is a directory the result
depends on the server configuration, some return an HTML formatted
directory listing. Copies at most DEFAULT_GET_FILE_SIZE bytes. Returns
true if succeeded, otherwise false.
Parameters:
path
-
The path relative to
rootUrl
on the remote server including the file name.
file
-
The local file where the received binary data should be stored.
Returns:
true if succeeded, otherwise false.
getBinary
Reads the content of a remote binary file that can be found under
rootUrl
/path
and creates a local copy
in File. If the remote location is a directory the result
depends on the server configuration, some return an HTML formatted
directory listing. Copies at most maxFileSize bytes. Returns true if
succeeded, otherwise false.
Parameters:
path
-
The path relative to
rootUrl
on the remote server including the file name.
file
-
The file local file where the received binary data should be stored.
maxFileSize
-
The maximum number of bytes to stream into the file. Not to exceed MAX_GET_FILE_SIZE.
Returns:
true if succeeded, otherwise false.
getResponseHeader
Returns a specified response header - multiple headers are separated by
CRLF.
Parameters:
header
-
The name of the header.
Returns:
The header - in case of multiple headers separated by CRLF.
getStatusCode
getStatusCode()
:
Number
Returns the status code after the execution of a method.
Returns:
the
statusCode
.
getStatusText
getStatusText()
:
String
Returns the status text after the execution of a method.
Returns:
the
statusText
.
mkcol
mkcol(path
:
String)
:
boolean
Creates a directory on the remote server on the location
rootUrl
/path
.
Parameters:
path
-
The path relative to the
rootUrl
stated when instantiating the client where the new collection should be created.
Returns:
true if succeeded, otherwise false.
move
Moves a file on the server from one place
rootUrl
+ "/" +origin
to the other rootUrl
/destination
. If
destination
already exists it gets overwritten. Can also
be used to rename a remote file. Returns true if succeeded, otherwise
false.
Parameters:
origin
-
The origin where a file is located, relative to the
rootUrl
stated when instantiating the client.
destination
-
The destination where the file should be moved to, relative to the
rootUrl
stated when instantiating the client.
Returns:
true if succeeded, otherwise false.
move
Moves a file on the server from one place
rootUrl
/origin
to the other rootUrl
/destination
Can
also be used to rename a remote file. If overwrite
is true
and destination
already exists it gets overwritten.
Returns true if succeeded, otherwise false.
Parameters:
origin
-
The origin where a file is located, relative to the
rootUrl
stated when instantiating the client.
destination
-
The destination where the file should be moved to, relative to the
rootUrl
stated when instantiating the client.
overwrite
-
A flag which determines whether the destination gets overwritten if it exists before moving.
Returns:
true if succeeded, otherwise false.
options
Returns a list of methods which can be executed on the server location
rootUrl
/path
.
Parameters:
path
-
The path relative to the
rootUrl
stated when instantiating the client one wants to get the options for.
Returns:
list of WebDav methods which can be executed on the given path.
propfind
Get file listing of a remote location.
Returns a list of WebDAVFileInfo objects which contain
information about the files and directories located on
rootUrl
/path
and DEPTH_1 (1) level
underneath.
Parameters:
path
-
The path relative to the
rootUrl
stated when instantiating the client where to get information about the containing files from.
Returns:
an Array of WebDAVFileInfo objects which hold information about the files located on the server at the location.
propfind
Get file listing of a remote location.
Returns a list of WebDAVFileInfo objects which contain
information about the files and directories located on
rootUrl
/path
and the passed depth
underneath.
Parameters:
path
-
The path relative to the
rootUrl
stated when instantiating the client where to get information about the containing files from.
depth
-
The level starting from
rootUrl
down to which the file information gets collected.
Returns:
an Array of WebDAVFileInfo objects which hold information about the files located on the server at the location.
put
Puts content encoded with DEFAULT_ENCODING into a remote located file at
rootUrl
/path
. Returns true if
succeeded, otherwise false.
If the content of a local file is to be uploaded, please use method
put(String, File) instead.
Parameters:
path
-
The path to put given content up to, relative to the
rootUrl
stated when instantiating the client.
content
-
The content that has to be pushed on to the server.
Returns:
true if succeeded, otherwise false.
put
Puts content encoded with the passed encoding into a remote located file
at
rootUrl
/path
. Returns true if
succeeded, otherwise false.
If the content of a local file is to be uploaded, please use method
put(String, File) instead.
Parameters:
path
-
The path to put a given content up to, relative to the
rootUrl
stated when instantiating the client.
content
-
The content that has to be pushed on to a remote location.
encoding
-
The encoding in which the data should be stored on the server.
Returns:
true if succeeded, otherwise false.
put
Puts content out of a passed local file into a remote located file
at
rootUrl
/path
. This method performs
a binary file transfer. Returns true if succeeded, otherwise false.
Parameters:
path
-
The path to put given content up to, relative to the
rootUrl
stated when instantiating the client.
file
-
The file to push up to the server.
Returns:
true if succeeded, otherwise false.