Package de.xima.fc.webdav
Class WebDavHelper
- java.lang.Object
-
- de.xima.fc.webdav.WebDavHelper
-
public final class WebDavHelper extends Object
Helper from the originalSardineFactory- Since:
- 7.1.0
- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcreateChildDirectoriesIfMissing(com.github.sardine.Sardine sardine, String baseUrl, UnaryOperator<String> sanitizer, Iterable<String> pathSegments)Starting at the given base URL, append the given path segments and creates all child directories if they do not exist yet.static StringcreateChildDirectoriesIfMissing(com.github.sardine.Sardine sardine, String baseUrl, UnaryOperator<String> sanitizer, String... childPathSegments)Starting at the given base URL, creates all child directories if they do not exist yet.static UnaryOperator<String>createSanitizer()Creates the sanitizer for cleaning path segments in WebDAV URLs.static booleanexistsResource(com.github.sardine.Sardine sardine, String resourceUrl)static List<com.github.sardine.DavResource>listAll(com.github.sardine.Sardine sardine, String url)Get a list of all directories in theWebDavAccess.getServerUrl(), recursively (including all children of children etc.)static List<com.github.sardine.DavResource>listAll(WebDavAccess webdav)Get a list of all directories in theWebDavAccess.getServerUrl(), recursively (including all children of children etc.)static List<com.github.sardine.DavResource>listDir(com.github.sardine.Sardine sardine, String url)Lists all immediate children of the given URL.static List<com.github.sardine.DavResource>listDir(WebDavAccess webdav)Lists all immediate children of the given URL.static AutoClosableSardinenewSardine(WebDavAccess webdav)static voiduploadData(com.github.sardine.Sardine sardine, String targetUrl, UnaryOperator<String> sanitizer, String fileName, byte[] data)Uploads a file to a WebDAV server.static StringuploadData(com.github.sardine.Sardine sardine, String targetUrl, UnaryOperator<String> sanitizer, String fileName, File data)Uploads a file to a WebDAV server.static StringuploadData(com.github.sardine.Sardine sardine, String targetUrl, UnaryOperator<String> sanitizer, String fileName, InputStream data)Uploads a file to a WebDAV server.
-
-
-
Method Detail
-
createChildDirectoriesIfMissing
public static String createChildDirectoriesIfMissing(com.github.sardine.Sardine sardine, String baseUrl, UnaryOperator<String> sanitizer, Iterable<String> pathSegments) throws IOException, InvalidUriPathSegmentNameException
Starting at the given base URL, append the given path segments and creates all child directories if they do not exist yet. All path segments are interpreted as literal text and may not contain path navigation or sub paths (e.g./,.or..).- Parameters:
sardine- Sardine instance to use.baseUrl- Base URL to start at.sanitizer- Optional sanitizer applied to each segment before encoding.pathSegments- Child directories to create if missing.- Returns:
- The combined URL to the last child directory.
- Throws:
IOException- When a directory could not be created, e.g. when the network is not available.InvalidUriPathSegmentNameException- When a segment cannot be encoded.
-
createChildDirectoriesIfMissing
public static String createChildDirectoriesIfMissing(com.github.sardine.Sardine sardine, String baseUrl, UnaryOperator<String> sanitizer, String... childPathSegments) throws IOException
Starting at the given base URL, creates all child directories if they do not exist yet. Directories from the base URL are NOT created if they do not exist. Also, the base URL is considered to be the root, attempts by the given child path segments to navigate outside the base dir are ignored.- Parameters:
sardine- Sardine instance to use.baseUrl- Base URL to start at.sanitizer- Optional sanitizer applied to each segment before encoding.childPathSegments- Child directories to create if missing.- Returns:
- The combined URL to the last child directory.
- Throws:
IOException- When a directory could not be created, e.g. when the network is not available.
-
createSanitizer
public static UnaryOperator<String> createSanitizer()
Creates the sanitizer for cleaning path segments in WebDAV URLs. Users may define aXfcConfigKeys.Application.WEBDAV_SANITIZE_REGEXPapplication property with a custom regexp rule.- Returns:
- The sanitizer to use for path segments.
-
existsResource
public static boolean existsResource(com.github.sardine.Sardine sardine, String resourceUrl) throws IOException- Parameters:
sardine- Sardine instance to use.resourceUrl- URL with the path to check.- Returns:
truewhen the resource at the given URL exists,falseotherwise.- Throws:
IOException- When the resource could not be checked, such as when the network is down.
-
listAll
public static List<com.github.sardine.DavResource> listAll(com.github.sardine.Sardine sardine, String url) throws IOException
Get a list of all directories in theWebDavAccess.getServerUrl(), recursively (including all children of children etc.)- Parameters:
sardine- The sardine instance to use.url- URL to list.- Returns:
- a list of
DavResource - Throws:
IOException- When the resources could not be listed, e.g. due to a network error.
-
listAll
public static List<com.github.sardine.DavResource> listAll(WebDavAccess webdav) throws IOException
Get a list of all directories in theWebDavAccess.getServerUrl(), recursively (including all children of children etc.)- Parameters:
webdav- The connection to use.- Returns:
- a list of
DavResource - Throws:
IOException- When the resources could not be listed, e.g. due to a network error.
-
listDir
public static List<com.github.sardine.DavResource> listDir(com.github.sardine.Sardine sardine, String url) throws IOException
Lists all immediate children of the given URL.- Parameters:
sardine- The sardine instance to use.url- URL to list.- Returns:
- A list of
DavResourcethat represent the children of the given URL. - Throws:
IOException- When the resources could not be listed, e.g. due to a network error.
-
listDir
public static List<com.github.sardine.DavResource> listDir(WebDavAccess webdav) throws IOException
Lists all immediate children of the given URL.- Parameters:
webdav- The connection to use.- Returns:
- A list of
DavResourcethat represent the children of the given URL. - Throws:
IOException- When the resources could not be listed, e.g. due to a network error.
-
newSardine
public static AutoClosableSardine newSardine(WebDavAccess webdav)
- Parameters:
webdav-WebDavAccessentity with connection details.- Returns:
- A new
Sardineinstance for interacting with the WebDAV server from the given connection details.
-
uploadData
public static void uploadData(com.github.sardine.Sardine sardine, String targetUrl, UnaryOperator<String> sanitizer, String fileName, byte[] data) throws IOExceptionUploads a file to a WebDAV server.- Parameters:
sardine- Sardine instance to use.targetUrl- Directory where to store the file.sanitizer- Optional sanitizer applied to the file name before encoding.fileName- Name of the file.data- Data of the file.- Throws:
IOException- When the file could not be uploaded, e.g. due to a network failure.
-
uploadData
public static String uploadData(com.github.sardine.Sardine sardine, String targetUrl, UnaryOperator<String> sanitizer, String fileName, File data) throws IOException
Uploads a file to a WebDAV server.- Parameters:
sardine- Sardine instance to use.targetUrl- Directory where to store the file.sanitizer- Optional sanitizer applied to the file name before encoding.fileName- Name of the file.data- Data of the file.- Returns:
- The URL of the uploaded resource.
- Throws:
IOException- When the file could not be uploaded, e.g. due to a network failure.
-
uploadData
public static String uploadData(com.github.sardine.Sardine sardine, String targetUrl, UnaryOperator<String> sanitizer, String fileName, InputStream data) throws IOException
Uploads a file to a WebDAV server.- Parameters:
sardine- Sardine instance to use.targetUrl- Directory where to store the file.sanitizer- Optional sanitizer applied to the file name before encoding.fileName- Name of the file.data- Data of the file.- Returns:
- The URL of the uploaded resource.
- Throws:
IOException- When the file could not be uploaded, e.g. due to a network failure.
-
-