am d43252a7: am df4edc80: Merge change 24499 into eclair

Merge commit 'd43252a7b27a5a6966a51e8b35f5003f92c207fa'

* commit 'd43252a7b27a5a6966a51e8b35f5003f92c207fa':
  Modify android.syncml.pim so that no one is going to use.
This commit is contained in:
Daisuke Miyakawa
2009-09-10 09:24:00 -07:00
committed by Android Git Automerger
24 changed files with 43 additions and 2224 deletions

View File

@@ -28,6 +28,7 @@ import java.util.Set;
import java.util.Map.Entry;
import java.util.regex.Pattern;
@Deprecated
public class PropertyNode {
public String propName;

View File

@@ -18,6 +18,7 @@ package android.syncml.pim;
import java.util.List;
@Deprecated
public interface VBuilder {
void start();

View File

@@ -19,6 +19,7 @@ package android.syncml.pim;
import java.util.Collection;
import java.util.List;
@Deprecated
public class VBuilderCollection implements VBuilder {
private final Collection<VBuilder> mVBuilderCollection;

View File

@@ -36,6 +36,7 @@ import java.util.List;
* VNode: standy by a vcard instance.
* PropertyNode: standy by a property line of a card.
*/
@Deprecated
public class VDataBuilder implements VBuilder {
static private String LOG_TAG = "VDATABuilder";

View File

@@ -18,6 +18,7 @@ package android.syncml.pim;
import java.util.ArrayList;
@Deprecated
public class VNode {
public String VName;

View File

@@ -25,6 +25,7 @@ import java.io.UnsupportedEncodingException;
* This interface is used to parse the V format files, such as VCard & VCal
*
*/
@Deprecated
abstract public class VParser {
// Assume that "iso-8859-1" is able to map "all" 8bit characters to some unicode and
// decode the unicode to the original charset. If not, this setting will cause some bug.

View File

@@ -1,56 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.syncml.pim.vcalendar;
import java.util.List;
import java.util.ArrayList;
/**
* Same comment as ContactStruct.
*/
public class CalendarStruct{
public static class EventStruct{
public String description;
public String dtend;
public String dtstart;
public String duration;
public String has_alarm;
public String last_date;
public String rrule;
public String status;
public String title;
public String event_location;
public String uid;
public List<String> reminderList;
public void addReminderList(String method){
if(reminderList == null)
reminderList = new ArrayList<String>();
reminderList.add(method);
}
}
public String timezone;
public List<EventStruct> eventList;
public void addEventList(EventStruct stru){
if(eventList == null)
eventList = new ArrayList<EventStruct>();
eventList.add(stru);
}
}

View File

@@ -1,189 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.syncml.pim.vcalendar;
/**
* vCalendar string composer class
*/
public class VCalComposer {
public final static String VERSION_VCALENDAR10 = "vcalendar1.0";
public final static String VERSION_VCALENDAR20 = "vcalendar2.0";
public final static int VERSION_VCAL10_INT = 1;
public final static int VERSION_VCAL20_INT = 2;
private static String mNewLine = "\r\n";
private String mVersion = null;
public VCalComposer() {
}
/**
* Create a vCalendar String.
* @param struct see more from CalendarStruct class
* @param vcalversion MUST be VERSION_VCAL10 /VERSION_VCAL20
* @return vCalendar string
* @throws VcalException if version is invalid or create failed
*/
public String createVCal(CalendarStruct struct, int vcalversion)
throws VCalException{
StringBuilder returnStr = new StringBuilder();
//Version check
if(vcalversion != 1 && vcalversion != 2)
throw new VCalException("version not match 1.0 or 2.0.");
if (vcalversion == 1)
mVersion = VERSION_VCALENDAR10;
else
mVersion = VERSION_VCALENDAR20;
//Build vCalendar:
returnStr.append("BEGIN:VCALENDAR").append(mNewLine);
if(vcalversion == VERSION_VCAL10_INT)
returnStr.append("VERSION:1.0").append(mNewLine);
else
returnStr.append("VERSION:2.0").append(mNewLine);
returnStr.append("PRODID:vCal ID default").append(mNewLine);
if(!isNull(struct.timezone)){
if(vcalversion == VERSION_VCAL10_INT)
returnStr.append("TZ:").append(struct.timezone).append(mNewLine);
else//down here MUST have
returnStr.append("BEGIN:VTIMEZONE").append(mNewLine).
append("TZID:vCal default").append(mNewLine).
append("BEGIN:STANDARD").append(mNewLine).
append("DTSTART:16010101T000000").append(mNewLine).
append("TZOFFSETFROM:").append(struct.timezone).append(mNewLine).
append("TZOFFSETTO:").append(struct.timezone).append(mNewLine).
append("END:STANDARD").append(mNewLine).
append("END:VTIMEZONE").append(mNewLine);
}
//Build VEVNET
for(int i = 0; i < struct.eventList.size(); i++){
String str = buildEventStr( struct.eventList.get(i) );
returnStr.append(str);
}
//Build VTODO
//TODO
returnStr.append("END:VCALENDAR").append(mNewLine).append(mNewLine);
return returnStr.toString();
}
private String buildEventStr(CalendarStruct.EventStruct stru){
StringBuilder strbuf = new StringBuilder();
strbuf.append("BEGIN:VEVENT").append(mNewLine);
if(!isNull(stru.uid))
strbuf.append("UID:").append(stru.uid).append(mNewLine);
if(!isNull(stru.description))
strbuf.append("DESCRIPTION:").
append(foldingString(stru.description)).append(mNewLine);
if(!isNull(stru.dtend))
strbuf.append("DTEND:").append(stru.dtend).append(mNewLine);
if(!isNull(stru.dtstart))
strbuf.append("DTSTART:").append(stru.dtstart).append(mNewLine);
if(!isNull(stru.duration))
strbuf.append("DUE:").append(stru.duration).append(mNewLine);
if(!isNull(stru.event_location))
strbuf.append("LOCATION:").append(stru.event_location).append(mNewLine);
if(!isNull(stru.last_date))
strbuf.append("COMPLETED:").append(stru.last_date).append(mNewLine);
if(!isNull(stru.rrule))
strbuf.append("RRULE:").append(stru.rrule).append(mNewLine);
if(!isNull(stru.title))
strbuf.append("SUMMARY:").append(stru.title).append(mNewLine);
if(!isNull(stru.status)){
String stat = "TENTATIVE";
switch (Integer.parseInt(stru.status)){
case 0://Calendar.Calendars.STATUS_TENTATIVE
stat = "TENTATIVE";
break;
case 1://Calendar.Calendars.STATUS_CONFIRMED
stat = "CONFIRMED";
break;
case 2://Calendar.Calendars.STATUS_CANCELED
stat = "CANCELLED";
break;
}
strbuf.append("STATUS:").append(stat).append(mNewLine);
}
//Alarm
if(!isNull(stru.has_alarm)
&& stru.reminderList != null
&& stru.reminderList.size() > 0){
if (mVersion.equals(VERSION_VCALENDAR10)){
String prefix = "";
for(String method : stru.reminderList){
switch (Integer.parseInt(method)){
case 0:
prefix = "DALARM";
break;
case 1:
prefix = "AALARM";
break;
case 2:
prefix = "MALARM";
break;
case 3:
default:
prefix = "DALARM";
break;
}
strbuf.append(prefix).append(":default").append(mNewLine);
}
}else {//version 2.0 only support audio-method now.
strbuf.append("BEGIN:VALARM").append(mNewLine).
append("ACTION:AUDIO").append(mNewLine).
append("TRIGGER:-PT10M").append(mNewLine).
append("END:VALARM").append(mNewLine);
}
}
strbuf.append("END:VEVENT").append(mNewLine);
return strbuf.toString();
}
/** Alter str to folding supported format. */
private String foldingString(String str){
return str.replaceAll("\r\n", "\n").replaceAll("\n", "\r\n ");
}
/** is null */
private boolean isNull(String str){
if(str == null || str.trim().equals(""))
return true;
return false;
}
}

View File

@@ -1,41 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.syncml.pim.vcalendar;
public class VCalException extends java.lang.Exception{
// constructors
/**
* Constructs a VCalException object
*/
public VCalException()
{
}
/**
* Constructs a VCalException object
*
* @param message the error message
*/
public VCalException( String message )
{
super( message );
}
}

View File

@@ -1,116 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.syncml.pim.vcalendar;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import android.util.Config;
import android.util.Log;
import android.syncml.pim.VDataBuilder;
import android.syncml.pim.VParser;
public class VCalParser{
private final static String TAG = "VCalParser";
public final static String VERSION_VCALENDAR10 = "vcalendar1.0";
public final static String VERSION_VCALENDAR20 = "vcalendar2.0";
private VParser mParser = null;
private String mVersion = null;
public VCalParser() {
}
public boolean parse(String vcalendarStr, VDataBuilder builder)
throws VCalException {
vcalendarStr = verifyVCal(vcalendarStr);
try{
boolean isSuccess = mParser.parse(
new ByteArrayInputStream(vcalendarStr.getBytes()),
"US-ASCII", builder);
if (!isSuccess) {
if (mVersion.equals(VERSION_VCALENDAR10)) {
if(Config.LOGD)
Log.d(TAG, "Parse failed for vCal 1.0 parser."
+ " Try to use 2.0 parser.");
mVersion = VERSION_VCALENDAR20;
return parse(vcalendarStr, builder);
}else
throw new VCalException("parse failed.(even use 2.0 parser)");
}
}catch (IOException e){
throw new VCalException(e.getMessage());
}
return true;
}
/**
* Verify vCalendar string, and initialize mVersion according to it.
* */
private String verifyVCal(String vcalStr) {
//Version check
judgeVersion(vcalStr);
vcalStr = vcalStr.replaceAll("\r\n", "\n");
String[] strlist = vcalStr.split("\n");
StringBuilder replacedStr = new StringBuilder();
for (int i = 0; i < strlist.length; i++) {
if (strlist[i].indexOf(":") < 0) {
if (strlist[i].length() == 0 && strlist[i + 1].indexOf(":") > 0)
replacedStr.append(strlist[i]).append("\r\n");
else
replacedStr.append(" ").append(strlist[i]).append("\r\n");
} else
replacedStr.append(strlist[i]).append("\r\n");
}
if(Config.LOGD)Log.d(TAG, "After verify:\r\n" + replacedStr.toString());
return replacedStr.toString();
}
/**
* If version not given. Search from vcal string of the VERSION property.
* Then instance mParser to appropriate parser.
*/
private void judgeVersion(String vcalStr) {
if (mVersion == null) {
int versionIdx = vcalStr.indexOf("\nVERSION:");
mVersion = VERSION_VCALENDAR10;
if (versionIdx != -1){
String versionStr = vcalStr.substring(
versionIdx, vcalStr.indexOf("\n", versionIdx + 1));
if (versionStr.indexOf("2.0") > 0)
mVersion = VERSION_VCALENDAR20;
}
}
if (mVersion.equals(VERSION_VCALENDAR10))
mParser = new VCalParser_V10();
if (mVersion.equals(VERSION_VCALENDAR20))
mParser = new VCalParser_V20();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,186 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.syncml.pim.vcalendar;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashSet;
import android.syncml.pim.VBuilder;
public class VCalParser_V20 extends VCalParser_V10 {
private static final String V10LINEBREAKER = "\r\n";
private static final HashSet<String> acceptableComponents = new HashSet<String>(
Arrays.asList("VEVENT", "VTODO", "VALARM", "VTIMEZONE"));
private static final HashSet<String> acceptableV20Props = new HashSet<String>(
Arrays.asList("DESCRIPTION", "DTEND", "DTSTART", "DUE",
"COMPLETED", "RRULE", "STATUS", "SUMMARY", "LOCATION"));
private boolean hasTZ = false; // MUST only have one TZ property
private String[] lines;
private int index;
@Override
public boolean parse(InputStream is, String encoding, VBuilder builder)
throws IOException {
// get useful info for android calendar, and alter to vcal 1.0
byte[] bytes = new byte[is.available()];
is.read(bytes);
String scStr = new String(bytes);
StringBuilder v10str = new StringBuilder("");
lines = splitProperty(scStr);
index = 0;
if ("BEGIN:VCALENDAR".equals(lines[index]))
v10str.append("BEGIN:VCALENDAR" + V10LINEBREAKER);
else
return false;
index++;
if (false == parseV20Calbody(lines, v10str)
|| index > lines.length - 1)
return false;
if (lines.length - 1 == index && "END:VCALENDAR".equals(lines[index]))
v10str.append("END:VCALENDAR" + V10LINEBREAKER);
else
return false;
return super.parse(
// use vCal 1.0 parser
new ByteArrayInputStream(v10str.toString().getBytes()),
encoding, builder);
}
/**
* Parse and pick acceptable iCalendar body and translate it to
* calendarV1.0 format.
* @param lines iCalendar components/properties line list.
* @param buffer calendarV10 format string buffer
* @return true for success, or false
*/
private boolean parseV20Calbody(String[] lines, StringBuilder buffer) {
try {
while (!"VERSION:2.0".equals(lines[index]))
index++;
buffer.append("VERSION:1.0" + V10LINEBREAKER);
index++;
for (; index < lines.length - 1; index++) {
String[] keyAndValue = lines[index].split(":", 2);
String key = keyAndValue[0];
String value = keyAndValue[1];
if ("BEGIN".equals(key.trim())) {
if (!key.equals(key.trim()))
return false; // MUST be "BEGIN:componentname"
index++;
if (false == parseV20Component(value, buffer))
return false;
}
}
} catch (ArrayIndexOutOfBoundsException e) {
return false;
}
return true;
}
/**
* Parse and pick acceptable calendar V2.0's component and translate it to
* V1.0 format.
* @param compName component name
* @param buffer calendarV10 format string buffer
* @return true for success, or false
* @throws ArrayIndexOutOfBoundsException
*/
private boolean parseV20Component(String compName, StringBuilder buffer)
throws ArrayIndexOutOfBoundsException {
String endTag = "END:" + compName;
String[] propAndValue;
String propName, value;
if (acceptableComponents.contains(compName)) {
if ("VEVENT".equals(compName) || "VTODO".equals(compName)) {
buffer.append("BEGIN:" + compName + V10LINEBREAKER);
while (!endTag.equals(lines[index])) {
propAndValue = lines[index].split(":", 2);
propName = propAndValue[0].split(";", 2)[0];
value = propAndValue[1];
if ("".equals(lines[index]))
buffer.append(V10LINEBREAKER);
else if (acceptableV20Props.contains(propName)) {
buffer.append(propName + ":" + value + V10LINEBREAKER);
} else if ("BEGIN".equals(propName.trim())) {
// MUST be BEGIN:VALARM
if (propName.equals(propName.trim())
&& "VALARM".equals(value)) {
buffer.append("AALARM:default" + V10LINEBREAKER);
while (!"END:VALARM".equals(lines[index]))
index++;
} else
return false;
}
index++;
} // end while
buffer.append(endTag + V10LINEBREAKER);
} else if ("VALARM".equals(compName)) { // VALARM component MUST
// only appear within either VEVENT or VTODO
return false;
} else if ("VTIMEZONE".equals(compName)) {
do {
if (false == hasTZ) {// MUST only have 1 time TZ property
propAndValue = lines[index].split(":", 2);
propName = propAndValue[0].split(";", 2)[0];
if ("TZOFFSETFROM".equals(propName)) {
value = propAndValue[1];
buffer.append("TZ" + ":" + value + V10LINEBREAKER);
hasTZ = true;
}
}
index++;
} while (!endTag.equals(lines[index]));
} else
return false;
} else {
while (!endTag.equals(lines[index]))
index++;
}
return true;
}
/** split ever property line to String[], not split folding line. */
private String[] splitProperty(String scStr) {
/*
* Property splitted by \n, and unfold folding lines by removing
* CRLF+LWSP-char
*/
scStr = scStr.replaceAll("\r\n", "\n").replaceAll("\n ", "")
.replaceAll("\n\t", "");
String[] strs = scStr.split("\n");
return strs;
}
}

View File

@@ -1,6 +0,0 @@
<HTML>
<BODY>
Support classes for SyncML.
{@hide}
</BODY>
</HTML>

View File

@@ -49,8 +49,11 @@ import java.util.Map.Entry;
* This class standy by the person-contact in
* Android system, we must use this class instance as parameter to transmit to
* VCardComposer so that create vCard string.
*
* @deprecated Please use the new code in android.pim.vcard
*/
// TODO: rename the class name, next step
@Deprecated
public class ContactStruct {
private static final String LOG_TAG = "ContactStruct";

View File

@@ -29,7 +29,10 @@ import android.syncml.pim.vcard.ContactStruct.PhoneData;
/**
* Compose VCard string
*
* @depricated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardComposer {
final public static int VERSION_VCARD21_INT = 1;

View File

@@ -47,7 +47,10 @@ import java.util.List;
* If we store all VNode entries in memory like VDataBuilder.java,
* OutOfMemoryError may be thrown. Thus, this class push each VCard entry into
* ContentResolver immediately.
*
* @depricated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardDataBuilder implements VBuilder {
static private String LOG_TAG = "VCardDataBuilder";

View File

@@ -20,6 +20,10 @@ import java.util.List;
import android.syncml.pim.VBuilder;
/**
* @depricated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardEntryCounter implements VBuilder {
private int mCount;

View File

@@ -16,6 +16,10 @@
package android.syncml.pim.vcard;
/**
* @depricated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardException extends java.lang.Exception{
// constructors

View File

@@ -18,7 +18,10 @@ package android.syncml.pim.vcard;
/**
* VCardException thrown when VCard is nested without VCardParser's being notified.
*
* @depricated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardNestedException extends VCardException {
public VCardNestedException() {}
public VCardNestedException(String message) {

View File

@@ -23,6 +23,10 @@ import android.util.Log;
import java.io.ByteArrayInputStream;
import java.io.IOException;
/**
* @deprecated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardParser {
// TODO: fix this.

View File

@@ -31,7 +31,10 @@ import java.util.HashSet;
/**
* This class is used to parse vcard. Please refer to vCard Specification 2.1.
*
* @deprecated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardParser_V21 {
private static final String LOG_TAG = "VCardParser_V21";

View File

@@ -25,7 +25,10 @@ import java.util.HashSet;
/**
* This class is used to parse vcard3.0. <br>
* Please refer to vCard Specification 3.0 (http://tools.ietf.org/html/rfc2426)
*
* @deprecated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardParser_V30 extends VCardParser_V21 {
private static final String LOG_TAG = "VCardParser_V30";

View File

@@ -26,8 +26,10 @@ import java.util.Set;
/**
* Class which tries to detects the source of the vCard from its properties.
* Currently this implementation is very premature.
* @hide
*
* @deprecated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardSourceDetector implements VBuilder {
// Should only be used in package.
static final int TYPE_UNKNOWN = 0;

View File

@@ -17,8 +17,11 @@
package android.syncml.pim.vcard;
/**
* VCardException used only when the version of the vCard is different.
* VCardException used only when the version of the vCard is different.
*
* @deprecated Please use the code in android.pim.vcard
*/
@Deprecated
public class VCardVersionException extends VCardException {
public VCardVersionException() {
}