Author: asiri
Date: 2007-09-09 21:06:12 +0200 (Sun, 09 Sep 2007)
New Revision: 4855
Added:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/ICacheable.java
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiConnection.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiPage.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiSpace.java
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/model/impl/XWikiPage.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiSpace.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/wrappers/XWikiPageWrapper.java
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/CacheUtils.java
Log:
Completed local cache management (update / delete) routines. When the user
navigates through the document hierarchy, each document retrieved from the
server is added to the local cache. Also, when the user deletes documents cache
is updated accordingly.
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiConnection.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiConnection.java
2007-09-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiConnection.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -26,12 +26,13 @@
import org.codehaus.swizzle.confluence.Confluence;
import org.codehaus.swizzle.confluence.SwizzleConfluenceException;
import org.eclipse.core.runtime.IPath;
+import org.xwiki.plugins.eclipse.util.ICacheable;
/**
* A connection (session...) to a XWiki server. Each connection is uniquely
identified by a
* loginToken.
*/
-public interface IXWikiConnection
+public interface IXWikiConnection extends ICacheable
{
/**
* Initializes this connection by retrieving all spaces.
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiPage.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiPage.java
2007-09-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiPage.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -24,11 +24,13 @@
import java.util.Date;
import org.codehaus.swizzle.confluence.SwizzleConfluenceException;
+import org.eclipse.core.runtime.IPath;
+import org.xwiki.plugins.eclipse.util.ICacheable;
/**
* Represents an XWiki document.
*/
-public interface IXWikiPage
+public interface IXWikiPage extends ICacheable
{
/**
* Initializes this page if it has not been initialized. This method
simply retrieves all the
@@ -133,6 +135,11 @@
public String getContentStatus();
/**
+ * @return The cache path for this page.
+ */
+ public IPath getCachePath();
+
+ /**
* @return Whether this page is current and not deleted.
*/
public boolean isCurrent();
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiSpace.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiSpace.java
2007-09-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/IXWikiSpace.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -25,11 +25,12 @@
import org.codehaus.swizzle.confluence.SwizzleConfluenceException;
import org.eclipse.core.runtime.IPath;
+import org.xwiki.plugins.eclipse.util.ICacheable;
/**
* Represents an XWiki Space.
*/
-public interface IXWikiSpace
+public interface IXWikiSpace extends ICacheable
{
/**
* Initializes this space if it has not been initialized. This method
simply retrieves all the
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-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnection.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -24,7 +24,6 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -47,7 +46,7 @@
/**
* Default implementation of [EMAIL PROTECTED] IXWikiConnection}
*/
-public class XWikiConnection implements IXWikiConnection, TreeAdapter,
Serializable
+public class XWikiConnection implements IXWikiConnection, TreeAdapter
{
/**
* An XML-RPC proxy
@@ -224,14 +223,14 @@
for (int i = 0; i < spaceSummaries.size(); i++) {
SpaceSummary summary = (SpaceSummary) spaceSummaries.get(i);
XWikiSpace xwikiSpace = new XWikiSpace(this, summary);
- // Initialize and update cache.
xwikiSpace.setCachePath(getCachePath().addTrailingSeparator().append(
xwikiSpace.getKey()));
- CacheUtils.saveSpace(xwikiSpace);
+ CacheUtils.updateCache(xwikiSpace);
xwikiSpace.getCachePath().toFile().mkdir();
addSpace(xwikiSpace);
}
setSpacesReady(true);
+ CacheUtils.updateCache(this);
}
}
@@ -254,12 +253,12 @@
summary.setName(result.getName());
summary.setType(result.getType());
summary.setUrl(result.getUrl());
-
- IXWikiSpace wikiSpace = new XWikiSpace(this, summary, result);
-
- // We need this space to be displayed.
- wikiSpace.setMasked(false);
- // Finally, add the space to local model.
+ XWikiSpace wikiSpace = new XWikiSpace(this, summary, result);
+ wikiSpace.setMasked(false);
+ wikiSpace.setCachePath(getCachePath().addTrailingSeparator().append(
+ wikiSpace.getKey()));
+ CacheUtils.updateCache(wikiSpace);
+ wikiSpace.getCachePath().toFile().mkdir();
addSpace(wikiSpace);
}
@@ -360,7 +359,9 @@
public void removeSpace(String key) throws SwizzleConfluenceException
{
rpc.removeSpace(key);
+ IXWikiSpace space = spacesByKey.get(key);
spacesByKey.remove(key);
+ CacheUtils.clearCache(space);
}
/**
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-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiConnectionManager.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -90,18 +90,15 @@
// Assume older version of xwiki and turn-off conversion on client.
rpc.setConvertor(new IdentityObjectConvertor());
}
- // Continue as usual.
XWikiConnection conection = new XWikiConnection();
conection.setServerUrl(serverUrl);
conection.setUserName(userName);
conection.setRpcProxy(rpc);
- // Initialize and update cache.
- Date timeStamp = new Date();
IPath masterCacheDir = CacheUtils.getMasterCacheDirectory();
IPath cachePath =
-
masterCacheDir.addTrailingSeparator().append(String.valueOf(timeStamp.getTime()));
+ masterCacheDir.addTrailingSeparator().append(String.valueOf(new
Date().getTime()));
conection.setCachePath(cachePath);
- CacheUtils.saveConnection(conection);
+ CacheUtils.updateCache(conection);
conection.getCachePath().toFile().mkdir();
connections.add(conection);
return conection;
@@ -125,6 +122,7 @@
public void removeConnection(IXWikiConnection connection)
{
connections.remove(connection);
+ CacheUtils.clearCache(connection);
}
}
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiPage.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiPage.java
2007-09-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiPage.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -22,7 +22,10 @@
package org.xwiki.plugins.eclipse.model.impl;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.util.Date;
import org.codehaus.swizzle.confluence.Confluence;
@@ -41,6 +44,7 @@
import org.xwiki.plugins.eclipse.model.IXWikiSpace;
import org.xwiki.plugins.eclipse.model.adapters.TreeAdapter;
import org.xwiki.plugins.eclipse.model.wrappers.XWikiPageWrapper;
+import org.xwiki.plugins.eclipse.util.CacheUtils;
import org.xwiki.plugins.eclipse.util.GuiUtils;
import org.xwiki.plugins.eclipse.util.XWikiConstants;
@@ -53,19 +57,17 @@
/**
* Parent XWikiSpace.
*/
- private IXWikiSpace parent;
+ private transient IXWikiSpace parent;
/**
* Summary of this page.
*/
- private PageSummary summary;
+ private transient PageSummary summary;
- // TODO Again, like for spaces, why keep a summary when it's all included
in the page ?
-
/**
* Data (opposite of summary ?) of this page.
*/
- private Page page;
+ private transient Page page;
/**
* Whether data has been retrieved or not.
@@ -73,6 +75,11 @@
private boolean dataReady = false;
/**
+ * Cache path for this page.
+ */
+ private transient IPath cachePath;
+
+ /**
* Creates a new intance of an XWikiPage. Clients should use [EMAIL
PROTECTED] IXWikiSpace#getPages()} and
* similar methods to retrieve / create pages.
*
@@ -330,8 +337,9 @@
if (!isDataReady()) {
Confluence rpc = getParentSpace().getConnection().getRpcProxy();
String pageId = getId();
- this.page = rpc.getPage(pageId);
+ this.page = rpc.getPage(pageId);
setDataReady(true);
+ CacheUtils.updateCache(this);
}
}
@@ -474,6 +482,24 @@
{
return (Integer) this.page.getVersion();
}
+
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @see org.xwiki.plugins.eclipse.model.IXWikiPage#getCachePath()
+ */
+ public IPath getCachePath()
+ {
+ return this.cachePath;
+ }
+
+ /**
+ * Sets the cache path for this page.
+ * @param cachePath Cache path.
+ */
+ protected void setCachePath(IPath cachePath) {
+ this.cachePath = cachePath;
+ }
/**
* [EMAIL PROTECTED]
@@ -522,7 +548,7 @@
*/
public void setContent(String newContent)
{
- this.page.setContent(newContent);
+ this.page.setContent(newContent);
}
/**
@@ -557,7 +583,26 @@
Confluence rpc = getParentSpace().getConnection().getRpcProxy();
this.page = rpc.storePage(page);
setDataReady(true);
+ CacheUtils.updateCache(this);
return this;
}
+ /**
+ * Custom serializer method.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException
+ {
+ out.writeObject(summary.toMap());
+ out.writeObject(page.toMap());
+ out.defaultWriteObject();
+ }
+
+ /**
+ * Custom deserializer method.
+ */
+ private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException
+ {
+ // We'll worry about this later.
+ }
+
}
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiSpace.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiSpace.java
2007-09-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/impl/XWikiSpace.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -24,7 +24,6 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -49,7 +48,7 @@
/**
* Default implementation of [EMAIL PROTECTED] IXWikiSpace}.
*/
-public class XWikiSpace implements IXWikiSpace, TreeAdapter, Serializable
+public class XWikiSpace implements IXWikiSpace, TreeAdapter
{
/**
@@ -143,8 +142,7 @@
*/
protected void addPage(IXWikiPage page)
{
- pagesByID.put(page.getId(), page);
- // pagesByTitle.put(page.getTitle(), page);
+ pagesByID.put(page.getId(), page);
}
/**
@@ -268,9 +266,9 @@
if (!isDataReady()) {
Confluence rpc = getConnection().getRpcProxy();
String spaceKey = getKey();
- this.space = rpc.getSpace(spaceKey);
- CacheUtils.saveSpace(this);
+ this.space = rpc.getSpace(spaceKey);
setDataReady(true);
+ CacheUtils.updateCache(this);
}
if (!isPagesReady()) {
Confluence rpc = getConnection().getRpcProxy();
@@ -278,10 +276,14 @@
List<Object> pages = rpc.getPages(spaceKey);
for (int i = 0; i < pages.size(); i++) {
PageSummary pageSummary = (PageSummary) pages.get(i);
- IXWikiPage xwikiPage = new XWikiPage(this, pageSummary);
+ XWikiPage xwikiPage = new XWikiPage(this, pageSummary);
+
xwikiPage.setCachePath(getCachePath().addTrailingSeparator().append(
+ xwikiPage.getId()));
+ CacheUtils.updateCache(xwikiPage);
addPage(xwikiPage);
}
setPagesReady(true);
+ CacheUtils.updateCache(this);
}
}
@@ -297,8 +299,11 @@
page.setTitle(title);
page.setContent(content);
Page result = getConnection().getRpcProxy().storePage(page);
- IXWikiPage wikiPage = new XWikiPage(this, result);
- addPage(wikiPage);
+ XWikiPage xwikiPage = new XWikiPage(this, result);
+ xwikiPage.setCachePath(getCachePath().addTrailingSeparator().append(
+ xwikiPage.getId()));
+ CacheUtils.updateCache(xwikiPage);
+ addPage(xwikiPage);
}
/**
@@ -488,6 +493,7 @@
getConnection().getRpcProxy().removePage(pageId);
IXWikiPage pageToRemove = getPageByID(pageId);
pagesByID.remove(pageToRemove.getId());
+ CacheUtils.clearCache(pageToRemove);
} catch (SwizzleConfluenceException e) {
throw e;
}
Modified:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/wrappers/XWikiPageWrapper.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/wrappers/XWikiPageWrapper.java
2007-09-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/model/wrappers/XWikiPageWrapper.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -25,6 +25,7 @@
import java.util.Date;
import org.codehaus.swizzle.confluence.SwizzleConfluenceException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.xwiki.plugins.eclipse.model.IXWikiPage;
import org.xwiki.plugins.eclipse.model.IXWikiSpace;
@@ -244,6 +245,16 @@
return 0;
}
}
+
+ /**
+ * [EMAIL PROTECTED]
+ *
+ * @see org.xwiki.plugins.eclipse.model.IXWikiPage#getCachePath()
+ */
+ public IPath getCachePath()
+ {
+ return page.getCachePath();
+ }
/**
* [EMAIL PROTECTED]
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-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/CacheUtils.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -21,14 +21,13 @@
package org.xwiki.plugins.eclipse.util;
+import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import org.eclipse.core.runtime.IPath;
import org.xwiki.plugins.eclipse.Activator;
-import org.xwiki.plugins.eclipse.model.impl.XWikiConnection;
-import org.xwiki.plugins.eclipse.model.impl.XWikiSpace;
/**
* All utility functions related to local cache management should go here.
@@ -46,38 +45,56 @@
}
/**
- * Saves the given xwiki connection into local cache.
+ * Caches the given object into local repository.
*
- * @param connection Connection to be cached.
+ * @param cacheable Object to be cached.
*/
- public static void saveConnection(XWikiConnection connection)
+ public static void updateCache(ICacheable cacheable)
{
try {
ObjectOutputStream oos =
- new ObjectOutputStream(new
FileOutputStream(connection.getCachePath()
+ new ObjectOutputStream(new
FileOutputStream(cacheable.getCachePath()
.addFileExtension("cache").toFile()));
- oos.writeObject(connection);
+ oos.writeObject(cacheable);
oos.close();
} catch (IOException e) {
+ e.printStackTrace();
// TODO What should happen here ?
}
}
/**
- * Saves the given xwiki space into local cache.
+ * Removes all cached objects relevant to this Cacheable.
*
- * @param space Space to be cached.
+ * @param cacheable Cacheable to be wiped.
*/
- public static void saveSpace(XWikiSpace space)
+ public static void clearCache(ICacheable cacheable)
{
- try {
- ObjectOutputStream oos =
- new ObjectOutputStream(new
FileOutputStream(space.getCachePath()
- .addFileExtension("cache").toFile()));
- oos.writeObject(space);
- oos.close();
- } catch (IOException e) {
- // TODO What should happen here ?
+ File cacheFile =
cacheable.getCachePath().addFileExtension("cache").toFile();
+ File dataCacheDirectory = cacheable.getCachePath().toFile();
+ if (cacheFile.exists()) {
+ cacheFile.delete();
}
+ if (dataCacheDirectory.exists() && dataCacheDirectory.isDirectory()) {
+ removeDirectory(dataCacheDirectory);
+ }
}
+
+ /**
+ * Utility method for removing a non-empty directory.
+ * @param dir Directory to be removed
+ * @return Success or otherwise
+ */
+ private static boolean removeDirectory(File dir) {
+ if (dir.isDirectory()) {
+ String[] children = dir.list();
+ for (int i=0; i<children.length; i++) {
+ boolean success = removeDirectory(new File(dir, children[i]));
+ if (!success) {
+ return false;
+ }
+ }
+ }
+ return dir.delete();
+ }
}
Added:
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/ICacheable.java
===================================================================
---
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/ICacheable.java
2007-09-09 14:29:14 UTC (rev 4854)
+++
xwiki-extensions/xwiki-eclipse/trunk/plugins/org.xwiki.eclipse/src/main/java/org/xwiki/plugins/eclipse/util/ICacheable.java
2007-09-09 19:06:12 UTC (rev 4855)
@@ -0,0 +1,10 @@
+package org.xwiki.plugins.eclipse.util;
+
+import java.io.Serializable;
+
+import org.eclipse.core.runtime.IPath;
+
+public interface ICacheable extends Serializable
+{
+ public IPath getCachePath();
+}
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications