Giter Club home page Giter Club logo

dav4jvm's Introduction

License Tests JitPack KDoc

dav4jvm

dav4jvm is a WebDAV/CalDAV/CardDAV library for JVM (Java/Kotlin). It has been developed for DAVx⁵ initially.

Repository: https://github.com/bitfireAT/dav4jvm/

Generated KDoc: https://bitfireat.github.io/dav4jvm/

For questions, suggestions etc. use Github discussions. We're happy about contributions, but please let us know in the discussions before. Then make the changes in your own repository and send a pull request.

Installation

You can use jitpack.io to include dav4jvm:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.bitfireAT:dav4jvm:<tag or commit>'  // usually the latest commit ID from main branch
    //implementation 'com.github.bitfireAT:dav4jvm:main-SNAPSHOT'  // use it only for testing because it doesn't generate reproducible builds
}

dav4jvm needs a working XmlPullParser (XPP). On Android, the system already comes with XPP and you don't need to include one; on other systems, you may need to import for instance org.ogce:xpp3 to get dav4jvm to work.

Usage

First, you'll need to set up an OkHttp instance. Use BasicDigestAuthHandler to configure the credentials:

val authHandler = BasicDigestAuthHandler(
    domain = null, // Optional, to only authenticate against hosts with this domain.
    username = "user1",
    password = "pass1"
)
val okHttpClient = OkHttpClient.Builder()
    .followRedirects(false)
    .authenticator(authHandler)
    .addNetworkInterceptor(authHandler)
    .build()

Files

Here's an example to create and download a file:

val location = "https://example.com/webdav/hello.txt".toHttpUrl()
val davCollection = DavCollection(account.requireClient(), location)

// Create a text file
davCollection.put("World".toRequestBody(contentType = "text/plain".toMediaType()) { response ->
    // Upload successful!
}

// Download a text file
davCollection.get(accept = "", headers = null) { response ->
    response.body?.string()
    // Download successful!
}

To list a folder's contents, you need to pass in which properties to fetch:

val location = "https://example.com/webdav/".toHttpUrl()
val davCollection = DavCollection(account.requireClient(), location)

davCollection.propfind(depth = 1, DisplayName.NAME, GetLastModified.NAME) { response, relation ->
    // This callback will be called for every file in the folder.
    // Use `response.properties` to access the successfully retrieved properties.
}

Custom properties

If you use custom WebDAV properties, register the corresponding factories with PropertyRegistry.register() before calling other dav4jvm methods.

Useful forks

For specific use-cases, we have a list of forks that cover them:

Contact / License

dav4jvm is licensed under Mozilla Public License, v. 2.0.

dav4jvm's People

Contributors

rfc2822 avatar davigonz avatar arnyminerz avatar tobiaskaminsky avatar zhanghai avatar jacobras avatar siarhei-luskanau avatar

Stargazers

dayatakino avatar W13KM avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.