1
0
mirror of https://github.com/etesync/android synced 2024-11-22 16:08:13 +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:label="@string/app_name"
android:theme="@style/AppTheme" > android:theme="@style/AppTheme" >
<service <service
android:name="at.bitfire.davdroid.syncadapter.AccountAuthenticatorService" android:name=".syncadapter.AccountAuthenticatorService"
android:exported="false" > android:exported="false" >
<intent-filter> <intent-filter>
<action android:name="android.accounts.AccountAuthenticator" /> <action android:name="android.accounts.AccountAuthenticator" />
@ -33,7 +33,7 @@
android:resource="@xml/account_authenticator" /> android:resource="@xml/account_authenticator" />
</service> </service>
<service <service
android:name="at.bitfire.davdroid.syncadapter.ContactsSyncAdapterService" android:name=".syncadapter.ContactsSyncAdapterService"
android:exported="true" android:exported="true"
android:process=":sync" > android:process=":sync" >
<intent-filter> <intent-filter>
@ -48,7 +48,7 @@
android:resource="@xml/contacts" /> android:resource="@xml/contacts" />
</service> </service>
<service <service
android:name="at.bitfire.davdroid.syncadapter.CalendarsSyncAdapterService" android:name=".syncadapter.CalendarsSyncAdapterService"
android:exported="true" android:exported="true"
android:process=":sync" > android:process=":sync" >
<intent-filter> <intent-filter>
@ -61,7 +61,7 @@
</service> </service>
<activity <activity
android:name="at.bitfire.davdroid.MainActivity" android:name=".MainActivity"
android:label="@string/app_name" > android:label="@string/app_name" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -69,7 +69,7 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name="at.bitfire.davdroid.syncadapter.AddAccountActivity" android:name=".syncadapter.AddAccountActivity"
android:excludeFromRecents="true" > android:excludeFromRecents="true" >
</activity> </activity>
</application> </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.data.ParserException;
import net.fortuna.ical4j.model.Date; import net.fortuna.ical4j.model.Date;
import net.fortuna.ical4j.model.ValidationException; import net.fortuna.ical4j.model.ValidationException;
import net.fortuna.ical4j.util.CompatibilityHints;
import net.fortuna.ical4j.vcard.GroupRegistry; import net.fortuna.ical4j.vcard.GroupRegistry;
import net.fortuna.ical4j.vcard.ParameterFactoryRegistry; import net.fortuna.ical4j.vcard.ParameterFactoryRegistry;
import net.fortuna.ical4j.vcard.Property; 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.Url;
import net.fortuna.ical4j.vcard.property.Version; import net.fortuna.ical4j.vcard.property.Version;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import android.util.Log; import android.util.Log;
@ -115,6 +117,8 @@ public class Contact extends Resource {
propertyFactoryRegistry.register("X-" + PhoneticFirstName.PROPERTY_NAME, new PhoneticFirstName.Factory()); propertyFactoryRegistry.register("X-" + PhoneticFirstName.PROPERTY_NAME, new PhoneticFirstName.Factory());
propertyFactoryRegistry.register("X-" + PhoneticMiddleName.PROPERTY_NAME, new PhoneticMiddleName.Factory()); propertyFactoryRegistry.register("X-" + PhoneticMiddleName.PROPERTY_NAME, new PhoneticMiddleName.Factory());
propertyFactoryRegistry.register("X-" + PhoneticLastName.PROPERTY_NAME, new PhoneticLastName.Factory()); propertyFactoryRegistry.register("X-" + PhoneticLastName.PROPERTY_NAME, new PhoneticLastName.Factory());
//Log.d(TAG, IOUtils.toString(is));
VCardBuilder builder = new VCardBuilder( VCardBuilder builder = new VCardBuilder(
new InputStreamReader(is), new InputStreamReader(is),
@ -218,7 +222,6 @@ public class Contact extends Resource {
if (photo != null) if (photo != null)
properties.add(new Photo(photo, new Type("image/jpeg"))); properties.add(new Photo(photo, new Type("image/jpeg")));
Log.d(TAG, new Photo(photo, new Type("image/jpeg")).toString());
if (birthDay != null) if (birthDay != null)
properties.add(new BDay(birthDay)); properties.add(new BDay(birthDay));

View File

@ -30,6 +30,7 @@ import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister; import org.simpleframework.xml.core.Persister;
import android.util.Log; import android.util.Log;
import at.bitfire.davdroid.Utils;
public class WebDavCollection extends WebDavResource { public class WebDavCollection extends WebDavResource {
private static final String TAG = "davdroid.WebDavCollection"; private static final String TAG = "davdroid.WebDavCollection";
@ -95,8 +96,10 @@ public class WebDavCollection extends WebDavResource {
multiget.prop.calendarData = new DavProp.DavPropCalendarData(); multiget.prop.calendarData = new DavProp.DavPropCalendarData();
multiget.hrefs = new ArrayList<DavHref>(names.length); multiget.hrefs = new ArrayList<DavHref>(names.length);
for (String name : names) for (String name : names) {
multiget.hrefs.add(new DavHref(location.resolve(name).getPath())); 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(); Serializer serializer = new Persister();
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
@ -158,7 +161,7 @@ public class WebDavCollection extends WebDavResource {
for (DavResponse singleResponse : multistatus.response) { for (DavResponse singleResponse : multistatus.response) {
URI href; URI href;
try { try {
href = location.resolve(singleResponse.getHref().href); href = Utils.resolveURI(location, singleResponse.getHref().href);
} catch(IllegalArgumentException ex) { } catch(IllegalArgumentException ex) {
Log.w(TAG, "Ignoring illegal member URI in multi-status response", ex); Log.w(TAG, "Ignoring illegal member URI in multi-status response", ex);
continue; continue;
@ -166,7 +169,7 @@ public class WebDavCollection extends WebDavResource {
// about which resource is this response? // about which resource is this response?
WebDavResource referenced = null; WebDavResource referenced = null;
if (sameURL(location, href)) { // -> ourselves if (Utils.isSameURL(location, href)) { // -> ourselves
referenced = this; referenced = this;
} else { // -> about a member } 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.methods.HttpPut;
import org.apache.http.client.params.ClientPNames; import org.apache.http.client.params.ClientPNames;
import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.EnglishReasonPhraseCatalog;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames; import org.apache.http.params.CoreProtocolPNames;
import android.util.Log; import android.util.Log;
import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.Utils;
@ToString @ToString
@ -99,14 +99,13 @@ public class WebDavResource {
} }
public WebDavResource(WebDavCollection parent, String member) { public WebDavResource(WebDavCollection parent, String member) {
location = parent.location.resolve(member); location = Utils.resolveURI(parent.location, member);
client = parent.client; client = parent.client;
} }
public WebDavResource(WebDavCollection parent, String member, String ETag) { public WebDavResource(WebDavCollection parent, String member, String ETag) {
location = parent.location.resolve(member); this(parent, member);
properties.put(Property.ETAG, ETag); properties.put(Property.ETAG, ETag);
client = parent.client;
} }
protected void checkResponse(HttpResponse response) throws HttpException { protected void checkResponse(HttpResponse response) throws HttpException {
@ -116,13 +115,10 @@ public class WebDavResource {
protected void checkResponse(StatusLine statusLine) throws HttpException { protected void checkResponse(StatusLine statusLine) throws HttpException {
int code = statusLine.getStatusCode(); int code = statusLine.getStatusCode();
if (code/100 == 1 || code/100 == 2) if (code/100 == 1 || code/100 == 2) // everything OK
return; return;
// handle known codes String reason = code + " " + statusLine.getReasonPhrase();
EnglishReasonPhraseCatalog catalog = EnglishReasonPhraseCatalog.INSTANCE;
String reason = catalog.getReason(code, null);
switch (code) { switch (code) {
case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_UNAUTHORIZED:
throw new AuthenticationException(reason); throw new AuthenticationException(reason);
@ -167,7 +163,7 @@ public class WebDavResource {
String[] names = StringUtils.split(location.getPath(), "/"); String[] names = StringUtils.split(location.getPath(), "/");
return names[names.length - 1]; return names[names.length - 1];
} }
/* property methods */ /* property methods */