2 * OutboundFunambolContactObject.java
4 * Created on Oct 28, 2007, 1:48:43 PM
6 * GroupDAV connector for Funambol v6.5
7 * Copyright (C) 2007 Mathew McBride
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 package net
.bionicmessage
.funambol
.groupdav
.contacts
;
24 //import com.funambol.common.pim.common.Converter;
25 import net
.bionicmessage
.funambol
.framework
.OutboundObject
;
27 //import com.funambol.foundation.pdi.contact.*;
28 //import com.funambol.foundation.pdi.converter.*;
29 //import com.funambol.foundation.pdi.parser.*;
30 import com
.funambol
.common
.pim
.contact
.Contact
;
31 import com
.funambol
.common
.pim
.converter
.*;
32 import com
.funambol
.common
.pim
.sif
.SIFCParser
;
33 import java
.io
.StringReader
;
34 import com
.funambol
.common
.pim
.vcard
.*;
35 import com
.funambol
.framework
.engine
.SyncItem
;
36 import com
.funambol
.framework
.engine
.SyncItemImpl
;
37 import com
.funambol
.framework
.engine
.source
.SyncSource
;
38 import java
.io
.ByteArrayInputStream
;
39 import net
.bionicmessage
.funambol
.framework
.ObjectTransformationException
;
45 public class OutboundFunambolContactObject
implements OutboundObject
{
47 public static final String TYPE_SIFC
= "text/x-s4j-sifc";
48 public static final String TYPE_VCARD
= "text/x-vcard";
49 private Contact conObject
;
51 public OutboundFunambolContactObject() {
54 public void setContactObject(Contact obj
) {
58 public Object
getPDIDataObject() {
62 public Class
getPDIDataClass() {
63 return com
.funambol
.common
.pim
.contact
.Contact
.class;
66 public String
getStringRepresentation(String type
) throws ObjectTransformationException
{
68 //StringReader sr = new StringReader(type);
69 BaseConverter conv
= null;
70 if (type
.equals(TYPE_SIFC
)) {
71 conv
= new ContactToSIFC(null, "UTF-8");
72 } else if (type
.endsWith(TYPE_VCARD
)) {
73 conv
= new ContactToVcard(null, "UTF-8");
75 return conv
.convert(conObject
);
76 } catch (Exception e
) {
77 throw new ObjectTransformationException("Error transforming contact to" + type
, e
);
81 public void parseIntoObjectFromString(String str
, String type
) throws ObjectTransformationException
{
83 ByteArrayInputStream bis
= new ByteArrayInputStream(str
.getBytes("UTF-8"));
84 if (type
.equals(TYPE_SIFC
)) {
85 SIFCParser scp
= new SIFCParser(bis
);
86 conObject
= scp
.parse();
87 } else if (type
.equals(TYPE_VCARD
)) {
88 VcardParser vcp
= new VcardParser(bis
);
89 conObject
= vcp
.vCard();
91 } catch (Exception e
) {
92 throw new ObjectTransformationException("Error parsing from type: "+ type
, e
);
96 public String
getDefaultStringOutputType() {
100 public SyncItem
generateSyncItem(SyncSource origSource
) throws Exception
{
101 String content
= null;
102 String type
= origSource
.getInfo().getPreferredType().getType();
104 content
= getStringRepresentation(getDefaultStringOutputType());
106 content
= getStringRepresentation(type
);
108 String uid
= conObject
.getUid();
109 SyncItemImpl si
= new SyncItemImpl(origSource
, uid
);
110 byte[] con
= content
.getBytes("UTF-8");