Class WebDavHelper


  • public final class WebDavHelper
    extends Object
    Helper from the original SardineFactory
    Since:
    7.1.0
    Author:
    XIMA MEDIA GmbH
    • 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.
      • 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:
        true when the resource at the given URL exists, false otherwise.
        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 the WebDavAccess.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 the WebDavAccess.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 DavResource that 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 DavResource that 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 - WebDavAccess entity with connection details.
        Returns:
        A new Sardine instance 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 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.
        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.