KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > server > engine > ContactSyncItem


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.server.engine;
20
21 import sync4j.framework.engine.*;
22
23 import sync4j.server.pdi.*;
24
25 /**
26  * This class implements a <i>SyncItem</i> that represents a vCard 2.1/3.0
27  * contact object. Each vCard proporty is represented by a proper <i>SyncProperty</i>.
28  *
29  * @author Stefano Fornari @ Funambol
30  */

31 public class ContactSyncItem extends SyncItemImpl implements SyncItem {
32     // --------------------------------------------------------------- Constants
33

34     public final static String JavaDoc PROPERTY_VCARD_CONTENT = "VCARD_CONTENT";
35     
36     // ------------------------------------------------------------ Private data
37

38     // ------------------------------------------------------------ Constructors
39

40     /**
41      * Constructs a <i>ContactSyncItem</i> from another <i>SyncItem</i>. The
42      * binary content is translated into a String object, which is parsed
43      * occordingly to vCard v 2.1/3.0 specifications (RFCs 2425-26).
44      *
45      * @param fromSyncItem the <i>SyncItem</i> to convert
46      *
47      * @throws PDIException in case of errors in parsing the content
48      *
49      */

50     public ContactSyncItem(SyncItem fromSyncItem)
51     throws PDIException {
52         byte[] content = (byte[])fromSyncItem.getPropertyValue(PROPERTY_BINARY_CONTENT);
53         
54         if (content == null) {
55             throw new PDIException("No " + PROPERTY_BINARY_CONTENT + " property found!");
56         }
57         
58         Contact vCard = new Contact(new String JavaDoc(content));
59         
60         //
61
// Copy fromSyncItem's data
62
//
63
setSyncSource(fromSyncItem.getSyncSource());
64         setState(fromSyncItem.getState());
65         setProperties(fromSyncItem.getProperties());
66         
67         //
68
// Store the vCard and the vCard fields as properties
69
//
70
setPropertiesFromVCard(vCard);
71     }
72         
73     // --------------------------------------------------------- Private methods
74

75     /**
76      * The given vCard object is used to create the following SyncItem's
77      * properties:
78      * <table>
79      * <tr><td><i>property</i></td><td><i>mandatory</i></td><td><i>description</i></td><tr>
80      * <tr>
81      * <td> VCARD_CONTENT </td>
82      * <td> Y </td>
83      * <td> The vCard object itself </td>
84      * </tr>
85      * <tr>
86      * <td> FN </td>
87      * <td> Y </td>
88      * <td> vCard's FN </td>
89      * </tr>
90      * <tr>
91      * <td> N </td>
92      * <td> Y </td>
93      * <td> vCard's N </td>
94      * </tr>
95      * <tr>
96      * <td> NICKNAME </td>
97      * <td> N </td>
98      * <td> vCard's NICKNAME </td>
99      * </tr>
100      * <tr>
101      * <td> PHOTO </td>
102      * <td> N </td>
103      * <td> vCard's PHOTO </td>
104      * </tr>
105      * <tr>
106      * <td> BDAY </td>
107      * <td> N </td>
108      * <td> vCard's BDAY </td>
109      * </tr>
110      * <tr>
111      * <td> ADR </td>
112      * <td> N </td>
113      * <td> vCard's ADR </td>
114      * </tr>
115      * <tr>
116      * <td> LABEL </td>
117      * <td> N </td>
118      * <td> vCard's LABEL </td>
119      * </tr>
120      * <tr>
121      * <td> TEL </td>
122      * <td> N </td>
123      * <td> vCard's TEL </td>
124      * </tr>
125      * <tr>
126      * <td> EMAIL </td>
127      * <td> N </td>
128      * <td> vCard's EMAIL </td>
129      * </tr>
130      * <tr>
131      * <td> MAILER </td>
132      * <td> N </td>
133      * <td> vCard's MAILER </td>
134      * </tr>
135      * <tr>
136      * <td> TZ </td>
137      * <td> N </td>
138      * <td> vCard's TZ </td>
139      * </tr>
140      * <tr>
141      * <td> GEO </td>
142      * <td> N </td>
143      * <td> vCard's GEO </td>
144      * </tr>
145      * <tr>
146      * <td> TITLE </td>
147      * <td> N </td>
148      * <td> vCard's TITLE </td>
149      * </tr>
150      * <tr>
151      * <td> ROLE </td>
152      * <td> N </td>
153      * <td> vCard's ROLE </td>
154      * </tr>
155      * <tr>
156      * <td> LOGO </td>
157      * <td> N </td>
158      * <td> vCard's LOGO </td>
159      * </tr>
160      * <tr>
161      * <td> AGENT </td>
162      * <td> N </td>
163      * <td> vCard's AGENT </td>
164      * </tr>
165      * <tr>
166      * <td> ORG </td>
167      * <td> N </td>
168      * <td> vCard's ORG </td>
169      * </tr>
170      * <tr>
171      * <td> VATEGORIES </td>
172      * <td> N </td>
173      * <td> vCard's CATEGORIES </td>
174      * </tr>
175      * <tr>
176      * <td> NOTE </td>
177      * <td> N </td>
178      * <td> vCard's NOTE </td>
179      * </tr>
180      * <tr>
181      * <td> PRODID </td>
182      * <td> N </td>
183      * <td> vCard's PRODID </td>
184      * </tr>
185      * <tr>
186      * <td> REV </td>
187      * <td> N </td>
188      * <td> vCard's REV </td>
189      * </tr>
190      * <tr>
191      * <td> SORT-STRING </td>
192      * <td> N </td>
193      * <td> vCard's SORT-STRING </td>
194      * </tr>
195      * <tr>
196      * <td> SOUND </td>
197      * <td> N </td>
198      * <td> vCard's SOUND </td>
199      * </tr>
200      * <tr>
201      * <td> UID </td>
202      * <td> N </td>
203      * <td> vCard's UID </td>
204      * </tr>
205      * <tr>
206      * <td> URL </td>
207      * <td> N </td>
208      * <td> vCard's URL </td>
209      * </tr>
210      * <tr>
211      * <td> VERSION </td>
212      * <td> N </td>
213      * <td> vCard's VERSION </td>
214      * </tr>
215      * <tr>
216      * <td> CLASS </td>
217      * <td> N </td>
218      * <td> vCard's CLASS </td>
219      * </tr>
220      * <tr>
221      * <td> KEY </td>
222      * <td> N </td>
223      * <td> vCard's KEY </td>
224      * </tr>
225      * </table>
226      *
227      * @param vCard the vCard object
228      */

229     private void setPropertiesFromVCard(Contact vCard) {
230     }
231 }
Popular Tags