1
0
mirror of https://github.com/etesync/android synced 2024-11-26 01:48:34 +00:00

iCal4j update, handle relative URLs with colons

* iCal4j 1.0.5 -> 1.0.5.2, iCal4j-vcard 0.9.5 -> 0.9.6.2
* handle relative URLs with colons in name (see issue 45)
This commit is contained in:
rfc2822 2013-11-01 15:27:48 +01:00
parent ff4fe77fe3
commit fb671a67a4
8 changed files with 45 additions and 31 deletions

View File

@ -22,7 +22,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service
android:name="at.bitfire.davdroid.syncadapter.AccountAuthenticatorService"
android:name=".syncadapter.AccountAuthenticatorService"
android:exported="false" >
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
@ -33,7 +33,7 @@
android:resource="@xml/account_authenticator" />
</service>
<service
android:name="at.bitfire.davdroid.syncadapter.ContactsSyncAdapterService"
android:name=".syncadapter.ContactsSyncAdapterService"
android:exported="true"
android:process=":sync" >
<intent-filter>
@ -48,7 +48,7 @@
android:resource="@xml/contacts" />
</service>
<service
android:name="at.bitfire.davdroid.syncadapter.CalendarsSyncAdapterService"
android:name=".syncadapter.CalendarsSyncAdapterService"
android:exported="true"
android:process=":sync" >
<intent-filter>
@ -61,7 +61,7 @@
</service>
<activity
android:name="at.bitfire.davdroid.MainActivity"
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -69,7 +69,7 @@
</intent-filter>
</activity>
<activity
android:name="at.bitfire.davdroid.syncadapter.AddAccountActivity"
android:name=".syncadapter.AddAccountActivity"
android:excludeFromRecents="true" >
</activity>
</application>

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,23 @@
package at.bitfire.davdroid;
import java.net.URI;
import java.net.URISyntaxException;
public class Utils {
public static boolean isSameURL(URI a, URI b) {
try {
a = new URI(a.getScheme(), null, a.getHost(), a.getPort(), a.getPath(), a.getQuery(), a.getFragment());
b = new URI(b.getScheme(), null, b.getHost(), b.getPort(), b.getPath(), b.getQuery(), b.getFragment());
return a.equals(b);
} catch (URISyntaxException e) {
return false;
}
}
public static URI resolveURI(URI parent, String member) {
if (!member.startsWith("/"))
member = "./" + member;
return parent.resolve(member);
}
}

View File

@ -23,6 +23,7 @@ import lombok.ToString;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.model.Date;
import net.fortuna.ical4j.model.ValidationException;
import net.fortuna.ical4j.util.CompatibilityHints;
import net.fortuna.ical4j.vcard.GroupRegistry;
import net.fortuna.ical4j.vcard.ParameterFactoryRegistry;
import net.fortuna.ical4j.vcard.Property;
@ -44,6 +45,7 @@ import net.fortuna.ical4j.vcard.property.Uid;
import net.fortuna.ical4j.vcard.property.Url;
import net.fortuna.ical4j.vcard.property.Version;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import android.util.Log;
@ -116,6 +118,8 @@ public class Contact extends Resource {
propertyFactoryRegistry.register("X-" + PhoneticMiddleName.PROPERTY_NAME, new PhoneticMiddleName.Factory());
propertyFactoryRegistry.register("X-" + PhoneticLastName.PROPERTY_NAME, new PhoneticLastName.Factory());
//Log.d(TAG, IOUtils.toString(is));
VCardBuilder builder = new VCardBuilder(
new InputStreamReader(is),
new GroupRegistry(),
@ -218,7 +222,6 @@ public class Contact extends Resource {
if (photo != null)
properties.add(new Photo(photo, new Type("image/jpeg")));
Log.d(TAG, new Photo(photo, new Type("image/jpeg")).toString());
if (birthDay != null)
properties.add(new BDay(birthDay));

View File

@ -30,6 +30,7 @@ import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import android.util.Log;
import at.bitfire.davdroid.Utils;
public class WebDavCollection extends WebDavResource {
private static final String TAG = "davdroid.WebDavCollection";
@ -95,8 +96,10 @@ public class WebDavCollection extends WebDavResource {
multiget.prop.calendarData = new DavProp.DavPropCalendarData();
multiget.hrefs = new ArrayList<DavHref>(names.length);
for (String name : names)
multiget.hrefs.add(new DavHref(location.resolve(name).getPath()));
for (String name : names) {
if (!name.startsWith("/")) name = "./" + name; // allow colons in relative URLs (see issue #45)
multiget.hrefs.add(new DavHref(Utils.resolveURI(location, name).getPath()));
}
Serializer serializer = new Persister();
StringWriter writer = new StringWriter();
@ -158,7 +161,7 @@ public class WebDavCollection extends WebDavResource {
for (DavResponse singleResponse : multistatus.response) {
URI href;
try {
href = location.resolve(singleResponse.getHref().href);
href = Utils.resolveURI(location, singleResponse.getHref().href);
} catch(IllegalArgumentException ex) {
Log.w(TAG, "Ignoring illegal member URI in multi-status response", ex);
continue;
@ -166,7 +169,7 @@ public class WebDavCollection extends WebDavResource {
// about which resource is this response?
WebDavResource referenced = null;
if (sameURL(location, href)) { // -> ourselves
if (Utils.isSameURL(location, href)) { // -> ourselves
referenced = this;
} else { // -> about a member
@ -226,15 +229,4 @@ public class WebDavCollection extends WebDavResource {
}
}
}
private boolean sameURL(URI a, URI b) {
try {
a = new URI(a.getScheme(), null, a.getHost(), a.getPort(), a.getPath(), a.getQuery(), a.getFragment());
b = new URI(b.getScheme(), null, b.getHost(), b.getPort(), b.getPath(), b.getQuery(), b.getFragment());
return a.equals(b);
} catch (URISyntaxException e) {
return false;
}
}
}

View File

@ -34,12 +34,12 @@ import org.apache.http.client.methods.HttpOptions;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.EnglishReasonPhraseCatalog;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import android.util.Log;
import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.Utils;
@ToString
@ -99,14 +99,13 @@ public class WebDavResource {
}
public WebDavResource(WebDavCollection parent, String member) {
location = parent.location.resolve(member);
location = Utils.resolveURI(parent.location, member);
client = parent.client;
}
public WebDavResource(WebDavCollection parent, String member, String ETag) {
location = parent.location.resolve(member);
this(parent, member);
properties.put(Property.ETAG, ETag);
client = parent.client;
}
protected void checkResponse(HttpResponse response) throws HttpException {
@ -116,13 +115,10 @@ public class WebDavResource {
protected void checkResponse(StatusLine statusLine) throws HttpException {
int code = statusLine.getStatusCode();
if (code/100 == 1 || code/100 == 2)
if (code/100 == 1 || code/100 == 2) // everything OK
return;
// handle known codes
EnglishReasonPhraseCatalog catalog = EnglishReasonPhraseCatalog.INSTANCE;
String reason = catalog.getReason(code, null);
String reason = code + " " + statusLine.getReasonPhrase();
switch (code) {
case HttpStatus.SC_UNAUTHORIZED:
throw new AuthenticationException(reason);