Author: snjeza
Date: 2012-04-25 06:59:18 -0400 (Wed, 25 Apr 2012)
New Revision: 40480
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshBlogsJob.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshNewsJob.java
Log:
JBIDE-11192 - Offline Support
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java 2012-04-25
10:59:03 UTC (rev 40479)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java 2012-04-25
10:59:18 UTC (rev 40480)
@@ -63,6 +63,8 @@
}
public abstract File getCacheFile();
+
+ public abstract File getValidCacheFile();
protected void getEntries(File file) throws IOException,
IllegalArgumentException, FeedException {
@@ -185,36 +187,14 @@
cacheFile.getName(), urlString, destination, monitor);
URL url = getURL();
if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
+ return getValidEntries(monitor);
}
if (status.isOK() && url != null) {
- cacheModified = ECFExamplesTransport.getInstance()
- .getLastModified(url);
- InputStream in = null;
- OutputStream out = null;
- try {
- in = new FileInputStream(tempFile);
- out = new FileOutputStream(cacheFile);
- ProjectExamplesActivator.copy(in, out);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (Exception e) {
- // ignore
- }
- }
- if (out != null) {
- try {
- out.close();
- } catch (Exception e) {
- // ignore
- }
- }
- }
+ cacheModified = ECFExamplesTransport.getInstance().getLastModified(url);
+ ProjectExamplesActivator.copyFile(tempFile, cacheFile);
tempFile.delete();
if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
+ return getValidEntries(monitor);
}
cacheFile.setLastModified(cacheModified);
getEntries(cacheFile);
@@ -222,13 +202,47 @@
setException(status.getException());
}
} catch (Exception e) {
+ return getValidEntries(monitor);
+ }
+ }
+ if (monitor.isCanceled()) {
+ return getValidEntries(monitor);
+ }
+ if (getEntries().size() > 0) {
+ try {
+ File validCacheFile = getValidCacheFile();
+ if (!validCacheFile.isFile() || cacheFile.lastModified() !=
validCacheFile.lastModified()) {
+ ProjectExamplesActivator.copyFile(cacheFile, getValidCacheFile());
+ validCacheFile.setLastModified(cacheFile.lastModified());
+ }
+ } catch (Exception e) {
exception = e;
+ return getValidEntries(monitor);
+ }
+ } else {
+ return getValidEntries(monitor);
+ }
+ return Status.OK_STATUS;
+ }
+
+ protected IStatus getValidEntries(IProgressMonitor monitor) {
+ File file = getValidCacheFile();
+ if (file.isFile()) {
+ try {
+ getEntries(file);
+ } catch (Exception e) {
+ exception = e;
return Status.CANCEL_STATUS;
}
}
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
return Status.OK_STATUS;
}
+
+
private long getUrlModified() {
URL url = getURL();
if (exception != null) {
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshBlogsJob.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshBlogsJob.java 2012-04-25
10:59:03 UTC (rev 40479)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshBlogsJob.java 2012-04-25
10:59:18 UTC (rev 40480)
@@ -24,6 +24,7 @@
public class RefreshBlogsJob extends AbstractRefreshJob {
private static final String CACHE_FILE = "blogs.xml";
+ private static final String VALID_CACHE_FILE = "valid_blogs.xml";
public static RefreshBlogsJob INSTANCE = new RefreshBlogsJob();
private RefreshBlogsJob() {
@@ -32,8 +33,17 @@
@Override
public File getCacheFile() {
+ return getFile(CACHE_FILE);
+ }
+
+ protected File getFile(String name) {
IPath location = JBossCentralActivator.getDefault().getStateLocation();
- File file = new File(location.toFile(), CACHE_FILE);
+ File file = new File(location.toFile(), name);
return file;
}
+
+ @Override
+ public File getValidCacheFile() {
+ return getFile(VALID_CACHE_FILE);
+ }
}
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshNewsJob.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshNewsJob.java 2012-04-25
10:59:03 UTC (rev 40479)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshNewsJob.java 2012-04-25
10:59:18 UTC (rev 40480)
@@ -24,6 +24,8 @@
public class RefreshNewsJob extends AbstractRefreshJob {
private static final String CACHE_FILE = "news.xml";
+ private static final String VALID_CACHE_FILE = "valid_news.xml";
+
public static RefreshNewsJob INSTANCE = new RefreshNewsJob();
@@ -33,8 +35,17 @@
@Override
public File getCacheFile() {
+ return getFile(CACHE_FILE);
+ }
+
+ protected File getFile(String name) {
IPath location = JBossCentralActivator.getDefault().getStateLocation();
- File file = new File(location.toFile(), CACHE_FILE);
+ File file = new File(location.toFile(), name);
return file;
}
+
+ @Override
+ public File getValidCacheFile() {
+ return getFile(VALID_CACHE_FILE);
+ }
}
Show replies by date