xlawrence    2004/11/30 18:08:01 CET

  Modified files:
    src/java/org/jahia/suite/calendar/syncClients SyncClient.java 
  Log:
  The SyncClient can now initialize a synchronization and create the necessary 
data files for the sync engine
  
  Revision  Changes    Path
  1.5       +68 -5     
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/SyncClient.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/SyncClient.java.diff?r1=1.4&r2=1.5&f=h
  
  
  
  Index: SyncClient.java
  ===================================================================
  RCS file: 
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/SyncClient.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SyncClient.java   29 Nov 2004 16:49:04 -0000      1.4
  +++ SyncClient.java   30 Nov 2004 17:08:01 -0000      1.5
  @@ -44,12 +44,16 @@
   import sync4j.syncclient.spds.SyncManager;
   import sync4j.syncclient.spds.SyncException;
   
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.FileNotFoundException;
   
   import org.apache.log4j.Logger;
   
   import net.fortuna.ical4j.data.ParserException;
  +import net.fortuna.ical4j.model.ValidationException;
   
   /**
    *
  @@ -57,6 +61,8 @@
    */
   public class SyncClient {
       
  +    public static final String DB_DIRECTORY = "./db/";
  +    
       private SyncClientFrame syncClientGUI;
       private CalendarFileManager calManager;
       
  @@ -76,16 +82,73 @@
           log.error(e);
           e.printStackTrace();
       }
  -    
  +       
  +    /**
  +     *
  +     */
  +    protected void generateSyncItemFile(File file, String content) 
  +    throws IOException, FileNotFoundException {
  +        // new file for a new item
  +        if (!file.exists()) {
  +            file.createNewFile();
  +            
  +            // existing file for existing item
  +        } else {
  +            FileInputStream fin = new FileInputStream(file);
  +            byte[] buf = new byte[(int)file.length()];
  +            fin.read(buf);
  +            fin.close();
  +            String currentContent = new String(buf);
  +            
  +            // If the content has not changed between 2 syncs...
  +            if (currentContent.equals(content)) {
  +                // ... do nothing
  +                log.debug("Content has not changed for: "+file.getName());
  +                return;
  +            } else {
  +                file.delete();
  +                file.createNewFile();
  +            }
  +        }
  +        
  +        FileOutputStream fout = new FileOutputStream(file);
  +        fout.write(content.getBytes());
  +        fout.flush();
  +        fout.close();       
  +    }
  +        
       /**
        *
        */
  -    public void sync(String fileName) throws FileNotFoundException, 
IOException,
  -    SyncException, DMException, ParserException {  
  -        calManager.getCalendarItems(fileName);
  -        syncClientGUI.log("File successfully parsed");
  +    public void sync(String fileName, String calendar) throws 
  +    FileNotFoundException, IOException, SyncException, DMException, 
  +    ParserException, ValidationException {
  +        String[] items = calManager.getCalendarItems(fileName);
  +        syncClientGUI.log("File is valid. Preparing Sync data...");
  +        
  +        File dir = new File(DB_DIRECTORY + calendar);
  +        dir.mkdir();
  +        for (int i=0; i<items.length; i++) {
  +            File f = new File(DB_DIRECTORY + calendar +"/"+ i);
  +            generateSyncItemFile(f, items[i]);
  +        }
  +        syncClientGUI.log("Sync data ready. Synchonizing...");
           
           Properties props = System.getProperties();
  +        
  +        // The initial URL for the SyncML request
  +        props.put("syncml-url", "");
  +        
  +        // The target URI of the server being contacted
  +        props.put("target-local-uri", "");
  +        
  +        // Username and password for authentication to the sync server
  +        props.put("username", "");
  +        props.put("password", "");
  +        
  +        // The identification tag of this SyncML agent
  +        props.put("device-id", "");
  +        
           props.put(SimpleDeviceManager.PROP_DM_DIR_BASE, "conf");
           System.setProperties(props);
           
  

Reply via email to