Author: tharinduj
Date: 2007-09-08 20:10:17 +0200 (Sat, 08 Sep 2007)
New Revision: 4849

Modified:
   
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnection.java
   
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnectionManager.java
   
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/CacheUtils.java
   
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/XWikiConstants.java
Log:
Moved cache management code into CacheUtils.java

Modified: 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnection.java
===================================================================
--- 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnection.java
      2007-09-08 07:11:51 UTC (rev 4848)
+++ 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnection.java
      2007-09-08 18:10:17 UTC (rev 4849)
@@ -312,17 +312,9 @@
     public String getUserName()
     {
         return userName;
-    }    
+    }        
     
     /**
-     * Sets the local cache directory of this connection.
-     */
-    protected void setCacheDirectory(IPath localCacheDir)
-    {
-       this.localCacheDir = localCacheDir;
-    }
-    
-    /**
      * [EMAIL PROTECTED]
      * 
      * @see 
org.xwiki.plugins.eclipse.model.IXWikiConnection#getCacheDirectory()
@@ -330,6 +322,14 @@
     public IPath getCacheDirectory() {
                return localCacheDir;
        }
+    
+    /**
+     * Sets the local cache directory of this connection.
+     */
+    public void setCacheDirectory(IPath localCacheDir)
+    {
+        this.localCacheDir = localCacheDir;
+    }
 
        /**
      * [EMAIL PROTECTED]

Modified: 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnectionManager.java
===================================================================
--- 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnectionManager.java
       2007-09-08 07:11:51 UTC (rev 4848)
+++ 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnectionManager.java
       2007-09-08 18:10:17 UTC (rev 4849)
@@ -21,26 +21,17 @@
 
 package org.xwiki.plugins.eclipse.model.impl;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
 import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 
 import org.codehaus.swizzle.confluence.Confluence;
 import org.codehaus.swizzle.confluence.IdentityObjectConvertor;
 import org.codehaus.swizzle.confluence.SwizzleConfluenceException;
 import org.codehaus.swizzle.confluence.SwizzleXWiki;
-import org.eclipse.core.runtime.IPath;
 import org.xwiki.plugins.eclipse.model.IXWikiConnection;
 import org.xwiki.plugins.eclipse.model.IXWikiConnectionManager;
 import org.xwiki.plugins.eclipse.util.CacheUtils;
-import org.xwiki.plugins.eclipse.util.XWikiConstants;
 
 /**
  * Default implementation of [EMAIL PROTECTED] IXWikiConnectionManager}.
@@ -103,33 +94,7 @@
         conection.setUserName(userName);
         conection.setRpcProxy(rpc);
         connections.add(conection);
-        // Get cache locations
-        IPath masterCacheDir = CacheUtils.getCacheDirectory();
-        Date timeStamp = new Date();
-        IPath connectionCacheDir =
-            
masterCacheDir.addTrailingSeparator().append(String.valueOf(timeStamp.getTime()));
-        IPath connectionCacheFile =
-            
masterCacheDir.addTrailingSeparator().append(String.valueOf(timeStamp.getTime()))
-                .addFileExtension("cache");        
-        // Prepare the data to be cached
-        Map<String, String> cacheData = new HashMap<String, String>();
-        cacheData.put(XWikiConstants.CONNECTION_USERNAME, userName);
-        cacheData.put(XWikiConstants.CONNECTION_PASSWORD, password);
-        cacheData.put(XWikiConstants.CONNECTION_URL, serverUrl);
-        cacheData.put(XWikiConstants.CONNECTION_PROXY, proxy);
-        // Write to the cache
-        try {
-            ObjectOutputStream oos =
-                new ObjectOutputStream(new 
FileOutputStream(connectionCacheFile.toFile()));
-            oos.writeObject(cacheData);
-            oos.close();
-        } catch (IOException e) {
-            // TODO What should happen here ?            
-        }
-        // Create and set the cache directory for this connection
-        connectionCacheDir.toFile().mkdir();
-        conection.setCacheDirectory(connectionCacheDir);
-        // Done updating cache.
+        CacheUtils.saveConnection(conection);
         return conection;
     }
 

Modified: 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/CacheUtils.java
===================================================================
--- 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/CacheUtils.java
 2007-09-08 07:11:51 UTC (rev 4848)
+++ 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/CacheUtils.java
 2007-09-08 18:10:17 UTC (rev 4849)
@@ -21,8 +21,16 @@
 
 package org.xwiki.plugins.eclipse.util;
 
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.eclipse.core.runtime.IPath;
 import org.xwiki.plugins.eclipse.Activator;
+import org.xwiki.plugins.eclipse.model.impl.XWikiConnection;
 
 /**
  * All utility functions related to local cache management should go here.
@@ -36,4 +44,36 @@
                // Return the plugin state location for now.
                return Activator.getDefault().getStateLocation();
        }
+    
+    /**
+     * Saves the given xwiki connection into local cache.
+     * @param connection Connection to be cached.
+     */
+    public static void saveConnection(XWikiConnection connection) {
+        // Get cache locations
+        IPath masterCacheDir = CacheUtils.getCacheDirectory();
+        Date timeStamp = new Date();
+        IPath connectionCacheDir =
+            
masterCacheDir.addTrailingSeparator().append(String.valueOf(timeStamp.getTime()));
+        IPath connectionCacheFile =
+            
masterCacheDir.addTrailingSeparator().append(String.valueOf(timeStamp.getTime()))
+                .addFileExtension("cache");        
+        // Prepare the data to be cached
+        Map<String, String> cacheData = new HashMap<String, String>();
+        cacheData.put(XWikiConstants.CONNECTION_USERNAME, 
connection.getUserName());        
+        cacheData.put(XWikiConstants.CONNECTION_URL, 
connection.getServerUrl());
+        // Write to the cache
+        try {
+            ObjectOutputStream oos =
+                new ObjectOutputStream(new 
FileOutputStream(connectionCacheFile.toFile()));
+            oos.writeObject(cacheData);
+            oos.close();
+        } catch (IOException e) {
+            // TODO What should happen here ?            
+        }
+        // Create and set the cache directory for this connection
+        connectionCacheDir.toFile().mkdir();
+        connection.setCacheDirectory(connectionCacheDir);
+        // Done updating cache.
+    }
 }

Modified: 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/XWikiConstants.java
===================================================================
--- 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/XWikiConstants.java
     2007-09-08 07:11:51 UTC (rev 4848)
+++ 
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/XWikiConstants.java
     2007-09-08 18:10:17 UTC (rev 4849)
@@ -52,13 +52,8 @@
     public static String TOGGLE_BUTTON_ICON = "icons/view-fullscreen.png";
 
     /* Cache Constants */
-    public static String CONNECTION_USERNAME = "USERNAME";
+    public static String CONNECTION_USERNAME = "USERNAME";    
     
-    public static String CONNECTION_PASSWORD = "PASSWORD";
-    
-    public static String CONNECTION_URL = "URL";
-    
-    public static String CONNECTION_PROXY = "PROXY";
-    
-    public static String CONNECTION_CACHE_DIR = "CACHE";
+    public static String CONNECTION_URL = "URL";    
+      
 }

_______________________________________________
notifications mailing list
notifications@xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to