KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > test > SIFFileSystemSyncSource


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 package sync4j.syncclient.test;
19
20 import java.io.*;
21 import java.security.Principal JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Date JavaDoc;
24 import java.util.Vector JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.Properties JavaDoc;
27
28 import sync4j.syncclient.common.logging.Logger;
29 import sync4j.syncclient.common.SourceUtils;
30 import sync4j.syncclient.test.FileSystemSyncSource;
31 import sync4j.syncclient.spds.engine.*;
32 import sync4j.syncclient.spds.SyncException;
33
34 import sync4j.framework.tools.Base64;
35
36 import sync4j.foundation.pdi.contact.*;
37 import sync4j.foundation.pdi.event.*;
38 import sync4j.foundation.pdi.converter.*;
39 import sync4j.foundation.pdi.parser.*;
40
41 /**
42  * This class implements a <i>SyncSource</i> that extends a FileSystemSyncSource
43  * and it's able to receive and send items in the following formats:
44  * <ul>
45  * <li>SIF-C
46  * <li>SIF-E
47  * <li>text
48  * <li>vCard
49  * <li>iCalendar
50  * </ul>
51  *
52  * The clientContentType and the serverContentType specify the format of
53  * which the client and the server send the items and would receive the returned.
54  *
55  * @author Luigia Fassina @ Funambol
56  *
57  * @version $Id: SIFFileSystemSyncSource.java,v 1.7 2005/06/13 17:30:37 nichele Exp $
58  *
59  */

60 public class SIFFileSystemSyncSource extends FileSystemSyncSource
61 implements SyncSource {
62
63     // --------------------------------------------------------------- Constants
64
private static final String JavaDoc DATABASE_HEADER
65     = "SIFFileSystemSyncSource file database";
66
67     //
68
// Types of client and server content
69
//
70
private static final String JavaDoc CONTENT_TYPE_VCARD = "vCard" ;
71     private static final String JavaDoc CONTENT_TYPE_ICAL = "iCalendar";
72     private static final String JavaDoc CONTENT_TYPE_TEXT = "text" ;
73     private static final String JavaDoc CONTENT_TYPE_SIFC = "SIF-C" ;
74     private static final String JavaDoc CONTENT_TYPE_SIFE = "SIF-E" ;
75
76     //
77
// Types of content item
78
//
79
private static final int TYPE_VCARD = 0;
80     private static final int TYPE_ICAL = 1;
81     private static final int TYPE_TEXT = 2;
82     private static final int TYPE_SIFC = 3;
83     private static final int TYPE_SIFE = 4;
84
85     // -------------------------------------------------------------- Properties
86
/**
87      * The drive where to read the sourceDirectory
88      */

89     private String JavaDoc sourceDrive;
90     public void setSourceDrive(String JavaDoc sourceDrive) {
91         this.sourceDrive = sourceDrive;
92         if (getSourceDirectory() != null) {
93             super.setSourceDirectory(sourceDrive + getSourceDirectory());
94         }
95     }
96     public String JavaDoc getSourceDrive() {
97         return this.sourceDrive;
98     }
99
100     public void setSourceDirectory(String JavaDoc sourceDirectory) {
101         if (sourceDrive != null) {
102             sourceDirectory = sourceDrive + sourceDirectory;
103         }
104         super.setSourceDirectory(sourceDirectory);
105     }
106
107
108     /**
109      * The charset to use in object conversion
110      */

111     private String JavaDoc charset = "PLAIN";
112     public void setCharset(String JavaDoc charset) {
113         this.charset = charset;
114     }
115     public String JavaDoc getCharset() {
116         return this.charset;
117     }
118
119
120     /**
121      * The items type to read/save from/on the sourceDirectory
122      */

123     private String JavaDoc clientContentType;
124     public String JavaDoc getClientContentType() {
125         return this.clientContentType;
126     }
127     public void setClientContentType(String JavaDoc clientContentType) {
128         this.clientContentType = clientContentType;
129         setClientItemType();
130     }
131
132     /**
133      * Sets an int that define the type of the client content
134      */

135     private int CLIENT_TYPE = TYPE_TEXT;
136     private void setClientItemType() {
137         if (this.clientContentType.equals(CONTENT_TYPE_VCARD)) {
138             CLIENT_TYPE = TYPE_VCARD;
139         } else if (this.clientContentType.equals(CONTENT_TYPE_ICAL)) {
140             CLIENT_TYPE = TYPE_ICAL;
141         } else if (this.clientContentType.equals(CONTENT_TYPE_TEXT)) {
142             CLIENT_TYPE = TYPE_TEXT;
143         } else if (this.clientContentType.equals(CONTENT_TYPE_SIFC)) {
144             CLIENT_TYPE = TYPE_SIFC;
145         } else if (this.clientContentType.equals(CONTENT_TYPE_SIFE)) {
146             CLIENT_TYPE = TYPE_SIFE;
147         }
148     }
149
150     /**
151      * The type to use on received items and to use to send items to the server
152      */

153     private String JavaDoc serverContentType;
154     public String JavaDoc getServerContentType() {
155         return this.serverContentType;
156     }
157     public void setServerContentType(String JavaDoc serverContentType) {
158         this.serverContentType = serverContentType;
159         setServerItemType();
160     }
161
162     /**
163      * Sets an int that define the type of the server content
164      */

165     private int SERVER_TYPE = TYPE_TEXT;
166     private void setServerItemType() {
167         if (this.serverContentType.equals(CONTENT_TYPE_VCARD)) {
168             SERVER_TYPE = TYPE_VCARD;
169         } else if (this.serverContentType.equals(CONTENT_TYPE_ICAL)) {
170             SERVER_TYPE = TYPE_ICAL;
171         } else if (this.serverContentType.equals(CONTENT_TYPE_TEXT)) {
172             SERVER_TYPE = TYPE_TEXT;
173         } else if (this.serverContentType.equals(CONTENT_TYPE_SIFC)) {
174             SERVER_TYPE = TYPE_SIFC;
175         } else if (this.serverContentType.equals(CONTENT_TYPE_SIFE)) {
176             SERVER_TYPE = TYPE_SIFE;
177         }
178     }
179
180     // ------------------------------------------------------------ Constructors
181
/** Creates a new instance of AbstractSyncSource */
182     public SIFFileSystemSyncSource() {
183     }
184
185     // ---------------------------------------------------------- Public methods
186
public SyncItem setSyncItem(Principal JavaDoc principal, SyncItem syncItem)
187     throws SyncException {
188         try {
189             String JavaDoc fileName = syncItem.getKey().getKeyAsString();
190             byte[] fileContent =
191                 (byte[])syncItem.getPropertyValue(SyncItem.PROPERTY_BINARY_CONTENT);
192
193             if (fileContent == null) {
194                 fileContent = new byte[0];
195             }
196
197             if (isEncode()) {
198                 fileContent = Base64.decode(fileContent);
199             }
200
201             //
202
// Verify client item type
203
//
204
switch (CLIENT_TYPE) {
205                 // To VCard
206
case TYPE_VCARD:
207                     //
208
// Verify server item type
209
//
210
switch (SERVER_TYPE) {
211                         // From SIF-C
212
case TYPE_SIFC:
213                             fileContent = handleSIFCAsVCard(fileContent, fileName, syncItem);
214                             break;
215                         // From VCard or Text
216
case TYPE_VCARD:
217                         case TYPE_TEXT:
218                             //
219
// No convertion is required
220
//
221
break;
222                         default:
223                             String JavaDoc msg = "Content types not compatible: "
224                                        + " Client content type = "
225                                        + clientContentType
226                                        + " Server content type = "
227                                        + serverContentType
228                                        ;
229                             throw new SyncException(msg);
230                     }
231                     break;
232                 // To ICalendar
233
case TYPE_ICAL:
234                     //
235
// Verify server item type
236
//
237
switch (SERVER_TYPE) {
238                         // From SIF-E
239
case TYPE_SIFE:
240                             fileContent = handleSIFEAsICal(fileContent, fileName, syncItem);
241                             break;
242                         // From ICalendar or Text
243
case TYPE_ICAL:
244                         case TYPE_TEXT:
245                             //
246
// No convertion is required
247
//
248
break;
249                         default:
250                             String JavaDoc msg = "Content types not compatible: "
251                                        + " Client content type = "
252                                        + clientContentType
253                                        + " Server content type = "
254                                        + serverContentType
255                                        ;
256                             throw new SyncException(msg);
257                     }
258                     break;
259                 // To Text
260
case TYPE_TEXT:
261                     //
262
// Is not need to check the server item type because no
263
// conversion is required
264
//
265
break;
266                 // To SIF-C
267
case TYPE_SIFC:
268                     //
269
// Verify server item type
270
//
271
switch (SERVER_TYPE) {
272                         // From VCard
273
case TYPE_VCARD:
274                             fileContent = handleVCardAsSIFC(fileContent, fileName, syncItem);
275                             fileContent = handleSIFContent(fileContent, fileName, syncItem);
276                             break;
277                         // From SIF-C
278
case TYPE_SIFC:
279                             fileContent = handleSIFContent(fileContent, fileName, syncItem);
280                             break;
281                         // From Text
282
case TYPE_TEXT:
283                             //
284
// No conversion is required
285
//
286
break;
287                         default:
288                             String JavaDoc msg = "Content types not compatible: "
289                                        + " Client content type = "
290                                        + clientContentType
291                                        + " Server content type = "
292                                        + serverContentType
293                                        ;
294                             throw new SyncException(msg);
295                     }
296                     break;
297                 // To SIF-E
298
case TYPE_SIFE:
299                     //
300
// Verify server item type
301
//
302
switch (SERVER_TYPE) {
303                         // From ICal
304
case TYPE_ICAL:
305                             fileContent = handleICalAsSIFE(fileContent, fileName, syncItem);
306                             fileContent = handleSIFContent(fileContent, fileName, syncItem);
307                             break;
308                         // From SIF-E
309
case TYPE_SIFE:
310                             fileContent = handleSIFContent(fileContent, fileName, syncItem);
311                             break;
312                         // From Text
313
case TYPE_TEXT:
314                             //
315
// No conversion is required
316
//
317
break;
318                         default:
319                             String JavaDoc msg = "Content types not compatible: "
320                                        + " Client content type = "
321                                        + clientContentType
322                                        + " Server content type = "
323                                        + serverContentType
324                                        ;
325                             throw new SyncException(msg);
326                     }
327                     break;
328             }
329
330             FileOutputStream fos = new FileOutputStream(
331                 new File(getSourceDirectory(), fileName)
332             );
333             fos.write(fileContent);
334             fos.close();
335
336             setState(principal, fileName, SyncItemState.SYNCHRONIZED);
337
338             SyncItem newSyncItem =
339                 new SyncItemImpl(this, fileName, SyncItemState.NEW);
340
341             newSyncItem.setProperties(syncItem.getProperties());
342
343             return newSyncItem;
344         } catch (Exception JavaDoc e) {
345             throw new SyncException( "Error setting the item "
346                                    + syncItem.getKey().getKeyAsString()
347                                    , e
348                                    );
349         }
350     }
351
352     // ------------------------------------------------------------ Private data
353
/**
354      * Convert item from SIF-C format into VCard format
355      *
356      * @param fileContent a byte[] with the content of item
357      * @param fileName the name of file that content the item
358      * @param syncItem the SyncItem object
359      *
360      * @return byte[] the file content converted into VCard format
361      *
362      * @throws SyncException
363      */

364     private byte[] handleSIFCAsVCard(byte[] fileContent, String JavaDoc fileName, SyncItem syncItem)
365     throws SyncException {
366
367         try {
368
369             //
370
// Converting the xmlStream into a Contact object
371
//
372
ByteArrayInputStream xmlStream = new ByteArrayInputStream(fileContent);
373             XMLContactParser parser = new XMLContactParser(xmlStream);
374             Contact contact = (Contact)parser.parse();
375             //
376
// Converting the Contact object into a vcard string
377
//
378
Converter converter = new Converter((String JavaDoc)null, charset);
379             String JavaDoc vcard = converter.contactToVcard(contact);
380
381             return vcard.getBytes();
382
383         } catch (Exception JavaDoc e) {
384             String JavaDoc msg = "Error converting item "
385                        + syncItem.getKey().getKeyAsString()
386                        + " from SIF-C to VCard format"
387                        ;
388             throw new SyncException(msg, e);
389         }
390
391     }
392
393     /**
394      * Convert item from SIF-E format into ICal format
395      *
396      * @param fileContent a byte[] with the content of item
397      * @param fileName the name of file that content the item
398      * @param syncItem the SyncItem object
399      *
400      * @return byte[] the file content converted into ICal format
401      * @throws SyncException
402      */

403     private byte[] handleSIFEAsICal(byte[] fileContent, String JavaDoc fileName, SyncItem syncItem)
404     throws SyncException {
405
406         try {
407
408             //
409
// Converting the xmlStream into a Calendar object
410
//
411
ByteArrayInputStream xmlStream = new ByteArrayInputStream(fileContent);
412             XMLEventParser parser = new XMLEventParser(xmlStream);
413             Calendar calendar = (Calendar)parser.parse();
414             //
415
// Converting the Calendar object into a ical string
416
//
417
Converter converter = new Converter((String JavaDoc)null, charset);
418             String JavaDoc ical = converter.calendarToIcalendar(calendar);
419
420             return ical.getBytes();
421
422         } catch (Exception JavaDoc e) {
423             String JavaDoc msg = "Error converting item "
424                        + syncItem.getKey().getKeyAsString()
425                        + " from SIF-E to ICal format"
426                        ;
427             throw new SyncException(msg, e);
428         }
429
430     }
431
432     /**
433      * Convert item from VCard format into SIF-C format
434      *
435      * @param fileContent a byte[] with the content of item
436      * @param fileName the name of file that content the item
437      * @param syncItem the SyncItem object
438      *
439      * @return byte[] the file content converted into SIF-C format
440      *
441      * @throws SyncException
442      */

443     private byte[] handleVCardAsSIFC(byte[] fileContent, String JavaDoc fileName, SyncItem syncItem)
444     throws SyncException {
445
446         try {
447
448             //
449
// Handle the long line
450
//
451
String JavaDoc fc = SourceUtils.handleLineDelimiting(new String JavaDoc(fileContent));
452
453             ByteArrayInputStream buffer = new ByteArrayInputStream(fc.getBytes());
454             //
455
//Converting the vCard item into a Contact object
456
//
457
VcardParser parser = new VcardParser(buffer);
458             Contact contact = (Contact)parser.vCard();
459
460             //
461
//Converting the Contact object into an XML file
462
//
463
Converter converter = new Converter((String JavaDoc)null, charset);
464             String JavaDoc xmlStream = converter.contactToXML(contact);
465
466             return xmlStream.getBytes();
467
468         } catch(TokenMgrError e) {
469             throw new SyncException("Lexical error to parse item " +
470                                     syncItem.getKey().getKeyAsString(), e);
471         } catch (ParseException e) {
472             throw new SyncException("Error parsing the item " +
473                                     syncItem.getKey().getKeyAsString()
474                                     + " from vCard to SIF-C", e);
475         } catch (Exception JavaDoc e) {
476             throw new SyncException( "Error to handle convert from vCard to SIF-C"
477                                    + " of the item "
478                                    + syncItem.getKey().getKeyAsString(), e);
479         }
480     }
481
482     /**
483      * Convert item from SIF-E format into ICalendar format
484      *
485      * @param fileContent a byte[] with the content of item
486      * @param fileName the name of file that content the item
487      * @param syncItem the SyncItem object
488      *
489      * @return byte[] the file content converted into SIF-E format
490      *
491      * @throws SyncException
492      */

493     private byte[] handleICalAsSIFE(byte[] fileContent, String JavaDoc fileName, SyncItem syncItem)
494     throws SyncException {
495
496         try {
497
498             //
499
// Handle the long line
500
//
501
String JavaDoc fc = SourceUtils.handleLineDelimiting(new String JavaDoc(fileContent));
502
503             ByteArrayInputStream buffer = new ByteArrayInputStream(fc.getBytes());
504             //
505
//Converting the iCal item into a Calendar object
506
//
507
ICalendarParser parser = new ICalendarParser(buffer);
508             Calendar calendar = (Calendar)parser.iCalendar();
509
510             //
511
//Converting the Calendar object into an XML file
512
//
513
Converter converter = new Converter((String JavaDoc)null, charset);
514             String JavaDoc xmlStream = converter.calendarToXML(calendar);
515
516             return xmlStream.getBytes();
517
518         } catch(TokenMgrError e) {
519             throw new SyncException("Lexical error to parse item " +
520                                     syncItem.getKey().getKeyAsString(), e);
521         } catch (ParseException e) {
522             throw new SyncException("Error parsing the item " +
523                                     syncItem.getKey().getKeyAsString()
524                                     + " from iCal to SIF-E", e);
525         } catch (Exception JavaDoc e) {
526             throw new SyncException( "Error to handle convert from iCal to SIF-E"
527                                    + " of the item "
528                                    + syncItem.getKey().getKeyAsString(), e);
529         }
530     }
531
532     /**
533      * Il client content type is SIF-C or SIF-E and server are the same
534      * content type, than check if the file exist
535      *
536      * @param fileContent a byte[] with the content of item
537      * @param fileName the name of file that content the item
538      * @param syncItem the SyncItem object
539      *
540      * @return byte[] the file content merged
541      *
542      * @throws SyncException
543      */

544     private byte[] handleSIFContent(byte[] fileContent, String JavaDoc fileName, SyncItem syncItem)
545     throws SyncException {
546
547         try {
548
549             HashMap JavaDoc hashMap = null;
550             HashMap JavaDoc hashMapFromFile = null;
551             String JavaDoc xmlStream = new String JavaDoc(fileContent);
552
553             File f = new File(getSourceDirectory(), fileName);
554             if (f.exists()) {
555                 hashMapFromFile = SourceUtils.xmlToHashMap(readFileString(f));
556                 hashMap = SourceUtils.xmlToHashMap(xmlStream);
557                 hashMapFromFile.putAll(hashMap);
558                 fileContent = SourceUtils.hashMapToXml(hashMapFromFile).getBytes();
559             }
560             else {
561                 fileContent = xmlStream.getBytes();
562             }
563
564             return fileContent;
565
566         } catch (IOException e) {
567             throw new SyncException("Error setting the item " +
568                                     syncItem.getKey().getKeyAsString(), e);
569         } catch (ParseException e) {
570             throw new SyncException("Error parsing the item " +
571                                     syncItem.getKey().getKeyAsString(), e);
572         } catch (Exception JavaDoc e) {
573             throw new SyncException("Error setting the hashmap in item " +
574                                     syncItem.getKey().getKeyAsString(), e);
575         }
576     }
577
578     /**
579      * Reads a file into a String given its filename
580      *
581      * @param file the filename (as java.io.File)
582      *
583      * @return the content of the file as a string
584      *
585      * @throws java.io.IOException;
586      */

587     private String JavaDoc readFileString(File file) throws IOException {
588         FileInputStream fis = null;
589
590         byte[] buf = new byte[(int)file.length()];
591         try {
592             fis = new FileInputStream(file);
593             fis.read(buf);
594             fis.close();
595         } finally {
596             if (fis != null) {
597                 fis.close();
598             }
599         }
600         return new String JavaDoc(buf);
601     }
602
603     /**
604      * Filters the SyncItems in the synchronization database (after a refresh)
605      * based on the given principal, last sync timestamp and state (see
606      * SyncItemState). If state is equals to UNKNOWN all items are returned.<br>
607      * Note that the current implementation ignores the principal: data do not
608      * depend on users.
609      *
610      * @param principal principal. null means any
611      * @param since last sync timestamp. null neans since ever
612      * @param state the state to use as filter
613      *
614      * @return an array of SyncItem objects whose state is equal to the given
615      * state.
616      */

617     protected SyncItem[] filterSyncItems(Principal JavaDoc principal, Date JavaDoc since, char state)
618     throws SyncException {
619         Properties JavaDoc syncDatabase = updateSyncDatabase(principal);
620
621         Vector JavaDoc syncItems = new Vector JavaDoc();
622
623         long fileTimestamp,
624              sinceTimestamp = (since == null) ? -1 : since.getTime();
625
626         SyncItem syncItem = null;
627         String JavaDoc fileName = null;
628         String JavaDoc stateString = null;
629         char fileState ;
630         byte[] fileContent = new byte[0];
631
632         for (Enumeration JavaDoc en = syncDatabase.keys(); en.hasMoreElements(); ) {
633             fileName = (String JavaDoc)en.nextElement();
634             stateString = (String JavaDoc)syncDatabase.get(fileName);
635             fileState = stateFromStateString(stateString);
636             if ((state == SyncItemState.UNKNOWN) || (fileState == state)) {
637                 fileTimestamp = lastModifiedFromStateString(stateString);
638                 if (fileTimestamp > sinceTimestamp ) {
639                     syncItem = new SyncItemImpl(this, fileName, fileState);
640                     fileContent = readFileContent(fileName);
641
642                     if (fileContent.length != 0) {
643                         //
644
// Check the content type of client items and the
645
// content type required from server item: if different
646
// than change the item format in the server item format
647
//
648
try {
649                             fileContent = handleItemContentType(fileContent, fileName, syncItem);
650                         } catch(Exception JavaDoc e) {
651                             e.printStackTrace();
652                             if(Logger.isLoggable(Logger.INFO)) {
653                                 Logger.info("Error handle item content type " + e);
654                             }
655                             throw new SyncException("Error handle item content type ", e);
656                         }
657                     }
658
659                     if (isEncode()){
660                         syncItem.setProperty(
661                             new SyncItemProperty(
662                                 SyncItem.PROPERTY_BINARY_CONTENT,
663                                 Base64.encode(fileContent)
664                             )
665                         );
666                     } else {
667                         syncItem.setProperty(
668                             new SyncItemProperty(
669                                 SyncItem.PROPERTY_BINARY_CONTENT,
670                                 fileContent
671                             )
672                         );
673                     }
674                     syncItems.addElement(syncItem);
675                 }
676             }
677         } // next en
678

679         SyncItem[] ret = new SyncItem[syncItems.size()];
680         for (int i=0; i<ret.length; ++i) {
681             ret[i] = (SyncItem)syncItems.elementAt(i);
682         }
683
684         return ret;
685     }
686
687     /**
688      * Check the content type of client items and the content type required
689      * from server: if different than change the item format into server item
690      * format
691      *
692      * @param fileContent a byte[] with the content of item
693      * @param fileName the name of file that content the item
694      * @param syncItem the SyncItem object
695      *
696      * @return byte[] the file content
697      *
698      * @throws SyncException
699      */

700     private byte[] handleItemContentType(byte[] fileContent,
701                                          String JavaDoc fileName ,
702                                          SyncItem syncItem )
703     throws SyncException {
704
705         //
706
// Verify server item type
707
//
708
switch (SERVER_TYPE) {
709             // To VCard
710
case TYPE_VCARD:
711                 //
712
// Verify client item type
713
//
714
switch (CLIENT_TYPE) {
715                     // From SIF-C
716
case TYPE_SIFC:
717                         fileContent = handleSIFCAsVCard(fileContent, fileName, syncItem);
718                         break;
719                     // From VCard or Text
720
case TYPE_VCARD:
721                     case TYPE_TEXT:
722                         //
723
// No convertion is required
724
//
725
break;
726                     default:
727                         String JavaDoc msg = "Content types not compatible: "
728                                    + " Client content type = "
729                                    + clientContentType
730                                    + " Server content type = "
731                                    + serverContentType
732                                    ;
733                         throw new SyncException(msg);
734                 }
735                 break;
736             // To ICalendar
737
case TYPE_ICAL:
738                 //
739
// Verify client item type
740
//
741
switch (CLIENT_TYPE) {
742                     // From SIF-E
743
case TYPE_SIFE:
744                         fileContent = handleSIFEAsICal(fileContent, fileName, syncItem);
745                         break;
746                     // From ICalendar or Text
747
case TYPE_ICAL:
748                     case TYPE_TEXT:
749                         //
750
// No convertion is required
751
//
752
break;
753                     default:
754                         String JavaDoc msg = "Content types not compatible: "
755                                    + " Client content type = "
756                                    + clientContentType
757                                    + " Server content type = "
758                                    + serverContentType
759                                    ;
760                         throw new SyncException(msg);
761                 }
762                 break;
763             // To Text
764
case TYPE_TEXT:
765                 //
766
// Is not need to check the client item type because no
767
// conversion is required
768
//
769
break;
770             // To SIF-C
771
case TYPE_SIFC:
772                 //
773
// Verify client item type
774
//
775
switch (CLIENT_TYPE) {
776                     // From VCard
777
case TYPE_VCARD:
778                         fileContent = handleVCardAsSIFC(fileContent, fileName, syncItem);
779                         break;
780                     // From SIF-C
781
case TYPE_SIFC:
782                         fileContent = handleSIFContent(fileContent, fileName, syncItem);
783                         break;
784                     // From Text
785
case TYPE_TEXT:
786                         //
787
// No conversion is required
788
//
789
break;
790                     default:
791                         String JavaDoc msg = "Content types not compatible: "
792                                    + " Client content type = "
793                                    + clientContentType
794                                    + " Server content type = "
795                                    + serverContentType
796                                    ;
797                         throw new SyncException(msg);
798                 }
799                 break;
800             // To SIF-E
801
case TYPE_SIFE:
802                 //
803
// Verify client item type
804
//
805
switch (CLIENT_TYPE) {
806                     // From ICal
807
case TYPE_ICAL:
808                         fileContent = handleICalAsSIFE(fileContent, fileName, syncItem);
809                         break;
810                     // From SIF-E
811
case TYPE_SIFE:
812                         fileContent = handleSIFContent(fileContent, fileName, syncItem);
813                         break;
814                     // From Text
815
case TYPE_TEXT:
816                         //
817
// No conversion is required
818
//
819
break;
820                     default:
821                         String JavaDoc msg = "Content types not compatible: "
822                                    + " Client content type = "
823                                    + clientContentType
824                                    + " Server content type = "
825                                    + serverContentType
826                                    ;
827                         throw new SyncException(msg);
828                 }
829                 break;
830         } //end switch server type
831
return fileContent;
832     }
833 }
834
Popular Tags