Commit 79b4c494 authored by Ricki Hirner's avatar Ricki Hirner

Initial commit

parents
This diff is collapsed.
# dav4android
ical4android is an Android WebDAV (CalDAV/CardDAV) library which has
been developed for [DAVdroid](https://davdroid.bitfire.at).
## License
Copyright (C) 2013 – 2015 bitfire web engineering (Ricki Hirner, Bernhard Stockmann).
This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome
to redistribute it under the conditions of the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.html).
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "0.1-beta"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.squareup.okhttp:okhttp:2.6.0-SNAPSHOT'
provided 'org.projectlombok:lombok:1.16.6'
androidTestCompile 'com.squareup.okhttp:mockwebserver:2.6.0-SNAPSHOT'
}
lombok.addGeneratedAnnotation = false
lombok.anyConstructor.suppressConstructorProperties = true
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/rfc2822/opt/android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
package at.bitfire.dav4android;
public class Constants {
final static int PORT = 2541;
}
package at.bitfire.dav4android;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import junit.framework.TestCase;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import at.bitfire.dav4android.properties.DisplayName;
public class DavResourceTest extends TestCase {
OkHttpClient httpClient = new HttpClient();
MockWebServer mockServer = new MockWebServer();
@Override
public void setUp() throws IOException {
mockServer.start(Constants.PORT);
}
@Override
public void tearDown() throws IOException {
mockServer.shutdown();
}
public void testPropfind() throws XmlPullParserException, IOException, HttpException {
HttpUrl url = mockServer.url("/dav");
mockServer.enqueue(new MockResponse()
.setResponseCode(404));
DavResource dav = new DavResource(httpClient, url);
dav.propfind(DisplayName.NAME);
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.bitfire.dav4android">
<uses-permission android:name="android.permission.INTERNET"/>
<application android:allowBackup="true"
android:label="DAV4Android">
</application>
</manifest>
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.dav4android;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
import java.io.StringWriter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class DavResource {
final public MediaType MEDIA_TYPE_XML = MediaType.parse("text/xml; charset=UTF-8");
final protected OkHttpClient httpClient;
final HttpUrl location;
final PropertyCollection properties = new PropertyCollection();
public void propfind(Property.Name... reqProp) throws XmlPullParserException, IOException, HttpException {
// build XML request body
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlSerializer serializer = factory.newSerializer();
StringWriter writer = new StringWriter();
serializer.setOutput(writer);
serializer.startDocument("UTF-8", false);
serializer.startTag(Property.NS_WEBDAV, "propfind");
serializer.startTag(Property.NS_WEBDAV, "prop");
for (Property.Name prop : reqProp) {
serializer.startTag(prop.namespace, prop.name);
serializer.endTag(prop.namespace, prop.name);
}
serializer.endTag(Property.NS_WEBDAV, "prop");
serializer.endTag(Property.NS_WEBDAV, "propfind");
serializer.endDocument();
Response response = httpClient.newCall(new Request.Builder()
.url(location)
.method("PROPFIND", RequestBody.create(MEDIA_TYPE_XML, writer.toString()))
.build()).execute();
checkResponse(response);
// TODO process body
// response.body().byteStream()
}
protected void checkResponse(Response response) throws HttpException {
int status = response.code();
if (status/100 == 1 || status/100 == 2)
// everything OK
return;
throw new HttpException(status, response.message());
}
}
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.dav4android;
import com.squareup.okhttp.OkHttpClient;
import lombok.extern.slf4j.Slf4j;
public class HttpClient extends OkHttpClient {
public HttpClient() {
super();
// TODO add logging
}
}
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.dav4android;
import lombok.RequiredArgsConstructor;
public class HttpException extends Exception {
public HttpException(int status, String message) {
super(status + " " + message);
}
}
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.dav4android;
import lombok.RequiredArgsConstructor;
public interface Property {
String NS_WEBDAV = "DAV:";
@RequiredArgsConstructor
class Name {
public final String namespace;
public final String name;
}
}
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.dav4android;
import java.util.HashMap;
import java.util.Map;
public class PropertyCollection {
Map<String, Map<String, Property>> properties = null;
Property get(String namespace, String name) {
return null;
}
}
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.dav4android.properties;
import at.bitfire.dav4android.Property;
public class DisplayName implements Property {
public static final Name NAME = new Name(NS_WEBDAV, "displayname");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment