mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 11:12:22 -05:00
Caldav: first Task (VTODO) implementation step
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1711 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
abd61e9f12
commit
dface8d205
@ -2118,6 +2118,91 @@ public abstract class ExchangeSession {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Contact object
|
||||
*/
|
||||
public abstract class Task extends Item {
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public Task(String folderPath, String itemName, Map<String, String> properties, String etag, String noneMatch) {
|
||||
super(folderPath, itemName.endsWith(".vcf") ? itemName.substring(0, itemName.length() - 3) + "EML" : itemName, etag, noneMatch);
|
||||
this.putAll(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected Task() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert EML extension to ics.
|
||||
*
|
||||
* @return item name
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
String name = super.getName();
|
||||
if (name.endsWith(".EML")) {
|
||||
name = name.substring(0, name.length() - 3) + "ics";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set contact name
|
||||
*
|
||||
* @param name contact name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.itemName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute vtodo uid from name.
|
||||
*
|
||||
* @return uid
|
||||
* @throws URIException on error
|
||||
*/
|
||||
protected String getUid() throws URIException {
|
||||
String uid = getName();
|
||||
int dotIndex = uid.lastIndexOf('.');
|
||||
if (dotIndex > 0) {
|
||||
uid = uid.substring(0, dotIndex);
|
||||
}
|
||||
return URIUtil.encodePath(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return "text/calendar;charset=UTF-8";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getBody() throws HttpException {
|
||||
// build VTODO from task information
|
||||
ICSBufferedWriter writer = new ICSBufferedWriter();
|
||||
writer.writeLine("BEGIN:VCALENDAR");
|
||||
writer.writeLine("VERSION:2.0");
|
||||
writer.writeLine("BEGIN:VTODO");
|
||||
|
||||
writer.appendProperty("UID", getUid());
|
||||
|
||||
writer.appendProperty("SUMMARY", get("subject"));
|
||||
|
||||
writer.appendProperty("LAST-MODIFIED", get("lastmodified"));
|
||||
writer.appendProperty("DTSTAMP", get("dtstamp"));
|
||||
writer.appendProperty("CREATED", get("created"));
|
||||
|
||||
writer.writeLine("END:VTODO");
|
||||
writer.writeLine("END:VCALENDAR");
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar event object.
|
||||
*/
|
||||
|
@ -84,4 +84,38 @@ public class ICSBufferedWriter {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Append single value property
|
||||
*
|
||||
* @param propertyName property name
|
||||
* @param propertyValue property value
|
||||
*/
|
||||
public void appendProperty(String propertyName, String propertyValue) {
|
||||
if ((propertyValue != null) && (propertyValue.length() > 0)) {
|
||||
StringBuilder lineBuffer = new StringBuilder();
|
||||
lineBuffer.append(propertyName);
|
||||
lineBuffer.append(':');
|
||||
appendMultilineEncodedValue(lineBuffer, propertyValue);
|
||||
writeLine(lineBuffer.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Append and encode \n to \\n in value.
|
||||
*
|
||||
* @param buffer line buffer
|
||||
* @param value value
|
||||
*/
|
||||
protected void appendMultilineEncodedValue(StringBuilder buffer, String value) {
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
char c = value.charAt(i);
|
||||
if (c == '\n') {
|
||||
buffer.append("\\n");
|
||||
} else {
|
||||
buffer.append(value.charAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,40 +30,6 @@ public class VCardWriter extends ICSBufferedWriter {
|
||||
writeLine("VERSION:3.0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Append single value property
|
||||
*
|
||||
* @param propertyName property name
|
||||
* @param propertyValue property value
|
||||
*/
|
||||
public void appendProperty(String propertyName, String propertyValue) {
|
||||
if ((propertyValue != null) && (propertyValue.length() > 0)) {
|
||||
StringBuilder lineBuffer = new StringBuilder();
|
||||
lineBuffer.append(propertyName);
|
||||
lineBuffer.append(':');
|
||||
appendMultilineEncodedValue(lineBuffer, propertyValue);
|
||||
writeLine(lineBuffer.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Append and encode \n to \\n in value.
|
||||
*
|
||||
* @param buffer line buffer
|
||||
* @param value value
|
||||
*/
|
||||
protected void appendMultilineEncodedValue(StringBuilder buffer, String value) {
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
char c = value.charAt(i);
|
||||
if (c == '\n') {
|
||||
buffer.append("\\n");
|
||||
} else {
|
||||
buffer.append(value.charAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append compound value
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user