Author: snjeza
Date: 2011-11-22 18:13:50 -0500 (Tue, 22 Nov 2011)
New Revision: 36545
Added:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java
Modified:
trunk/central/plugins/org.jboss.tools.central/plugin.xml
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossBlogsHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.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-9850 feeds should be cached so it doesnt show blank when opening up the second time
Modified: trunk/central/plugins/org.jboss.tools.central/plugin.xml
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/plugin.xml 2011-11-22 23:13:41 UTC (rev
36544)
+++ trunk/central/plugins/org.jboss.tools.central/plugin.xml 2011-11-22 23:13:50 UTC (rev
36545)
@@ -132,6 +132,14 @@
name="WTP Runtime Preferences"
id="org.jboss.tools.wtp.runtime.preferences">
</command>
+ <command
+ name="Warning"
+ id="org.jboss.tools.central.newsWarning">
+ </command>
+ <command
+ name="Warning"
+ id="org.jboss.tools.central.blogsWarning">
+ </command>
</extension>
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossBlogsHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossBlogsHandler.java 2011-11-22
23:13:41 UTC (rev 36544)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossBlogsHandler.java 2011-11-22
23:13:50 UTC (rev 36545)
@@ -14,6 +14,8 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.jboss.tools.central.jobs.RefreshBlogsJob;
@@ -27,7 +29,39 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (RefreshBlogsJob.INSTANCE.getState() == Job.NONE) {
- RefreshBlogsJob.INSTANCE.schedule();
+ final RefreshBlogsJob job = RefreshBlogsJob.INSTANCE;
+ job.setForcedDownload(true);
+ job.setException(null);
+ job.setNeedsRefresh(true);
+ job.addJobChangeListener(new IJobChangeListener() {
+
+ @Override
+ public void sleeping(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void scheduled(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void running(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ job.setForcedDownload(false);
+ job.removeJobChangeListener(this);
+ }
+
+ @Override
+ public void awake(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void aboutToRun(IJobChangeEvent event) {
+ }
+ });
+ job.schedule();
}
return null;
}
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java 2011-11-22
23:13:41 UTC (rev 36544)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java 2011-11-22
23:13:50 UTC (rev 36545)
@@ -14,6 +14,8 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.jboss.tools.central.jobs.RefreshNewsJob;
@@ -27,7 +29,39 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (RefreshNewsJob.INSTANCE.getState() == Job.NONE) {
- RefreshNewsJob.INSTANCE.schedule();
+ final RefreshNewsJob job = RefreshNewsJob.INSTANCE;
+ job.setForcedDownload(true);
+ job.setNeedsRefresh(true);
+ job.setException(null);
+ job.addJobChangeListener(new IJobChangeListener() {
+
+ @Override
+ public void sleeping(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void scheduled(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void running(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ job.setForcedDownload(false);
+ job.removeJobChangeListener(this);
+ }
+
+ @Override
+ public void awake(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void aboutToRun(IJobChangeEvent event) {
+ }
+ });
+ job.schedule();
}
return null;
}
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2011-11-22
23:13:41 UTC (rev 36544)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2011-11-22
23:13:50 UTC (rev 36545)
@@ -34,6 +34,8 @@
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridDataFactory;
@@ -65,9 +67,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbenchWindow;
@@ -97,6 +96,7 @@
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.dialogs.ProjectExamplesDialog;
+import org.jboss.tools.central.jobs.AbstractRefreshJob;
import org.jboss.tools.central.jobs.RefreshBlogsJob;
import org.jboss.tools.central.jobs.RefreshNewsJob;
import org.jboss.tools.central.jobs.RefreshTutorialsJob;
@@ -115,6 +115,9 @@
*/
public class GettingStartedPage extends AbstractJBossCentralPage {
+ private static final String NEWS_WARNING_ID =
"org.jboss.tools.central.newsWarning";
+ private static final String BLOGS_WARNING_ID =
"org.jboss.tools.central.blogsWarning";
+
private static final String CLASS_ATTRIBUTE = "class";
public static final String ID = ID_PREFIX + "GettingStartedPage";
@@ -156,6 +159,10 @@
private Composite settingsComposite;
private Point oldSize;
private Font categoryFont;
+ private Action newsWarning;
+ private ToolBarManager newsToolBarManager;
+ private ToolBarManager blogsToolBarManager;
+ private Action blogsWarning;
public GettingStartedPage(FormEditor editor) {
super(editor, ID, "Getting Started");
@@ -250,10 +257,16 @@
});
showLoading(blogsPageBook, blogsLoadingComposite, blogsScrollComposite);
blogsPageBook.pack(true);
- RefreshBlogsJob refreshBlogsJob = RefreshBlogsJob.INSTANCE;
+ RefreshBlogsJob job = RefreshBlogsJob.INSTANCE;
+ job.setException(null);
+ if (job.getEntries().size() > 0) {
+ job.setNeedsRefresh(true);
+ refreshBlogs();
+ job.setNeedsRefresh(false);
+ }
refreshBlogsJobChangeListener = new RefreshBlogsJobChangeListener();
- refreshBlogsJob.addJobChangeListener(refreshBlogsJobChangeListener);
- refreshBlogsJob.schedule();
+ job.addJobChangeListener(refreshBlogsJobChangeListener);
+ job.schedule();
}
private void createNewsSection(FormToolkit toolkit, Composite parent) {
@@ -297,10 +310,16 @@
});
showLoading(newsPageBook, newsLoadingComposite, newsScrollComposite);
newsPageBook.pack(true);
- RefreshNewsJob refreshNewsJob = RefreshNewsJob.INSTANCE;
+ AbstractRefreshJob job = RefreshNewsJob.INSTANCE;
+ job.setException(null);
+ if (job.getEntries().size() > 0) {
+ job.setNeedsRefresh(true);
+ refreshNews();
+ job.setNeedsRefresh(false);
+ }
refreshNewsJobChangeListener = new RefreshNewsJobChangeListener();
- refreshNewsJob.addJobChangeListener(refreshNewsJobChangeListener);
- refreshNewsJob.schedule();
+ job.addJobChangeListener(refreshNewsJobChangeListener);
+ job.schedule();
}
@@ -349,16 +368,27 @@
headerComposite.setLayout(rowLayout);
headerComposite.setBackground(null);
- ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
- toolBarManager.createControl(headerComposite);
+
+ blogsToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
+ blogsToolBarManager.createControl(headerComposite);
+ blogsWarning = new Action("Warning",
JBossCentralActivator.getImageDescriptor("/icons/nwarning.gif")) {
+
+ };
+ blogsWarning.setId(BLOGS_WARNING_ID);
+ blogsWarning.setActionDefinitionId(BLOGS_WARNING_ID);
+ //blogsWarning.setEnabled(false);
+ blogsToolBarManager.add(blogsWarning);
+
+ setItemVisible(blogsToolBarManager, BLOGS_WARNING_ID, false);
+
CommandContributionItem item = JBossCentralActivator.createContributionItem(getSite(),
"org.jboss.tools.central.openJBossBlogs");
- toolBarManager.add(item);
+ blogsToolBarManager.add(item);
item = JBossCentralActivator.createContributionItem(getSite(),
"org.jboss.tools.central.refreshJBossBlogs");
- toolBarManager.add(item);
+ blogsToolBarManager.add(item);
- toolBarManager.update(true);
+ blogsToolBarManager.update(true);
section.setTextClient(headerComposite);
}
@@ -371,23 +401,42 @@
headerComposite.setLayout(rowLayout);
headerComposite.setBackground(null);
- ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
- toolBarManager.createControl(headerComposite);
+ newsToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
+ newsToolBarManager.createControl(headerComposite);
+ newsWarning = new Action("Warning",
JBossCentralActivator.getImageDescriptor("/icons/nwarning.gif")) {
+
+ };
+ newsWarning.setId(NEWS_WARNING_ID);
+ newsWarning.setActionDefinitionId(NEWS_WARNING_ID);
+ //newsWarning.setEnabled(false);
+ newsToolBarManager.add(newsWarning);
+
+ setItemVisible(newsToolBarManager, NEWS_WARNING_ID, false);
+
CommandContributionItem item = JBossCentralActivator.createContributionItem(getSite(),
"org.jboss.tools.central.openJBossNews");
- toolBarManager.add(item);
+ newsToolBarManager.add(item);
item = JBossCentralActivator.createContributionItem(getSite(),
"org.jboss.tools.central.openJBossToolsTwitter");
- toolBarManager.add(item);
+ newsToolBarManager.add(item);
item = JBossCentralActivator.createContributionItem(getSite(),
"org.jboss.tools.central.refreshJBossNews");
- toolBarManager.add(item);
+ newsToolBarManager.add(item);
- toolBarManager.update(true);
+ newsToolBarManager.update(true);
section.setTextClient(headerComposite);
}
+ protected void setItemVisible(ToolBarManager toolBarManager, String id, boolean value)
{
+ IContributionItem[] items = toolBarManager.getItems();
+ for (IContributionItem item:items) {
+ if (id.equals(item.getId())) {
+ item.setVisible(value);
+ }
+ }
+ }
+
private void createTutorialsSection(FormToolkit toolkit, Composite parent) {
tutorialsSection = createSection(toolkit, parent, "Project Examples",
ExpandableComposite.TITLE_BAR|ExpandableComposite.TWISTIE|ExpandableComposite.EXPANDED);
@@ -773,7 +822,7 @@
});
}
- private void showException(PageBook pageBook, FormText exceptionText, Exception e) {
+ private void showException(PageBook pageBook, FormText exceptionText, Throwable e) {
JBossCentralActivator.log(e);
String message = StringEscapeUtils.escapeXml(e.getMessage());
String text = JBossCentralActivator.FORM_START_TAG +
@@ -790,33 +839,41 @@
RefreshBlogsJob job = RefreshBlogsJob.INSTANCE;
if (job.getState() == Job.NONE) {
if (job.getException() != null) {
- showException(blogsPageBook, blogsExceptionText,
- job.getException());
- return;
+ if (job.getEntries().size() <= 0) {
+ showException(blogsPageBook, blogsExceptionText,
+ job.getException());
+ return;
+ }
}
List<FeedsEntry> entries = job.getEntries();
if (entries == null || entries.size() == 0) {
showNote(blogsPageBook, blogsNoteText, blogsScrollComposite);
return;
}
- showEntries(entries, blogsComposite, blogsPageBook, blogsScrollComposite);
+ if (job.needsRefresh()) {
+ showEntries(entries, blogsComposite, blogsPageBook, blogsScrollComposite);
+ }
}
}
public void refreshNews() {
- RefreshNewsJob job = RefreshNewsJob.INSTANCE;
+ AbstractRefreshJob job = RefreshNewsJob.INSTANCE;
if (job.getState() == Job.NONE) {
if (job.getException() != null) {
- showException(newsPageBook, newsExceptionText,
+ if (job.getEntries().size() <= 0) {
+ showException(newsPageBook, newsExceptionText,
job.getException());
- return;
+ return;
+ }
}
List<FeedsEntry> entries = job.getEntries();
- if (entries == null || entries.size() == 0) {
+ if (entries.size() == 0) {
showNote(newsPageBook, newsNoteText, newsScrollComposite);
return;
}
- showEntries(entries, newsComposite, newsPageBook, newsScrollComposite);
+ if (job.needsRefresh()) {
+ showEntries(entries, newsComposite, newsPageBook, newsScrollComposite);
+ }
}
}
@@ -1053,6 +1110,9 @@
}
protected void resize(boolean force) {
+ if (blogsSection == null) {
+ return;
+ }
Point size;
//if (Platform.OS_MACOSX.equals(Platform.getOS())) {
size = form.getSize();
@@ -1161,6 +1221,15 @@
public void run() {
setBusyIndicator(blogsLoadingComposite, false);
refreshBlogs();
+ setItemVisible(blogsToolBarManager, BLOGS_WARNING_ID, false);
+ RefreshBlogsJob job = RefreshBlogsJob.INSTANCE;
+ if (job.getEntries().size() > 0 && job.getException() != null) {
+ String tooltip = job.getException().getClass().getName() + ": " +
job.getException().getLocalizedMessage();
+ blogsWarning.setToolTipText(tooltip);
+ setItemVisible(blogsToolBarManager, BLOGS_WARNING_ID, true);
+ }
+ blogsToolBarManager.update(true);
+ blogsSection.layout(true, true);
}
});
@@ -1173,8 +1242,9 @@
@Override
public void scheduled(IJobChangeEvent event) {
- RefreshBlogsJob.INSTANCE.setException(null);
- showLoading(blogsPageBook, blogsLoadingComposite, blogsScrollComposite);
+ if (RefreshBlogsJob.INSTANCE.getEntries().size() <= 0) {
+ showLoading(blogsPageBook, blogsLoadingComposite, blogsScrollComposite);
+ }
}
@Override
@@ -1247,6 +1317,15 @@
public void run() {
setBusyIndicator(newsLoadingComposite, false);
refreshNews();
+ setItemVisible(newsToolBarManager, NEWS_WARNING_ID, false);
+ RefreshNewsJob job = RefreshNewsJob.INSTANCE;
+ if (job.getEntries().size() > 0 && job.getException() != null) {
+ String tooltip = job.getException().getClass().getName() + ": " +
job.getException().getLocalizedMessage();
+ newsWarning.setToolTipText(tooltip);
+ setItemVisible(newsToolBarManager, NEWS_WARNING_ID, true);
+ }
+ newsToolBarManager.update(true);
+ newsSection.layout(true, true);
}
});
@@ -1259,8 +1338,9 @@
@Override
public void scheduled(IJobChangeEvent event) {
- RefreshNewsJob.INSTANCE.setException(null);
- showLoading(newsPageBook, newsLoadingComposite, newsScrollComposite);
+ if (RefreshNewsJob.INSTANCE.getEntries().size() <= 0) {
+ showLoading(newsPageBook, newsLoadingComposite, newsScrollComposite);
+ }
}
@Override
Added:
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
(rev 0)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java 2011-11-22
23:13:50 UTC (rev 36545)
@@ -0,0 +1,275 @@
+package org.jboss.tools.central.jobs;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.jboss.tools.central.JBossCentralActivator;
+import org.jboss.tools.central.model.FeedsEntry;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.filetransfer.ECFExamplesTransport;
+
+import com.sun.syndication.feed.synd.SyndContent;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.io.FeedException;
+import com.sun.syndication.io.SyndFeedInput;
+import com.sun.syndication.io.XmlReader;
+
+public abstract class AbstractRefreshJob extends Job {
+
+ protected List<FeedsEntry> entries = new ArrayList<FeedsEntry>();
+ protected Throwable exception;
+ protected long cacheModified;
+ private String urlString;
+ private File cacheFile;
+ private boolean forcedDownload = false;
+ private boolean needsRefresh = true;
+
+ public AbstractRefreshJob(String name, String urlString) {
+ super(name);
+ this.urlString = urlString;
+ setPriority(LONG);
+ cacheFile = getCacheFile();
+ if (cacheFile.exists()) {
+ cacheModified = cacheFile.lastModified();
+ try {
+ getEntries(cacheFile);
+ } catch (FileNotFoundException e) {
+ JBossCentralActivator.log(e);
+ } catch (IllegalArgumentException e) {
+ JBossCentralActivator.log(e);
+ } catch (FeedException e) {
+ JBossCentralActivator.log(e);
+ } catch (IOException e) {
+ JBossCentralActivator.log(e);
+ }
+ }
+ }
+
+ public abstract File getCacheFile();
+
+ protected void getEntries(File file) throws IOException,
+ IllegalArgumentException, FeedException {
+ entries.clear();
+ needsRefresh = true;
+ InputStream in = new FileInputStream(file);
+ SyndFeedInput input = new SyndFeedInput();
+ SyndFeed syndFeed = input.build(new XmlReader(in));
+ List<SyndEntry> feeds = syndFeed.getEntries();
+ if (feeds == null || feeds.size() == 0) {
+ return;
+ }
+ int i = 0;
+
+ for (SyndEntry feed : feeds) {
+ FeedsEntry entry = adaptEntry(feed);
+ if (entry == null) {
+ continue;
+ }
+ if (i++ > JBossCentralActivator.MAX_FEEDS) {
+ break;
+ }
+ entries.add(entry);
+ }
+ }
+
+ private FeedsEntry adaptEntry(SyndEntry entry) {
+ if (entry == null) {
+ return null;
+ }
+ String title = null;
+ if (entry.getTitle() != null) {
+ title = entry.getTitle();
+ } else {
+ SyndContent titleEx = entry.getTitleEx();
+ if (titleEx != null && !titleEx.getValue().isEmpty()) {
+ title = titleEx.getValue();
+ }
+ }
+ if (title == null) {
+ return null;
+ }
+ title = StringEscapeUtils.escapeHtml(title);
+ String link;
+ if (entry.getLink() != null) {
+ link = entry.getLink();
+ } else {
+ link = entry.getUri();
+ }
+ String description = null;
+ if (entry.getDescription() != null) {
+ SyndContent desc = entry.getDescription();
+ if (desc != null && !desc.getValue().isEmpty()) {
+ description = desc.getValue();
+ }
+ }
+ if (description == null) {
+ List<SyndContent> contents = entry.getContents();
+ if (contents != null && contents.size() > 0) {
+ SyndContent desc = contents.get(0);
+ if (desc != null && !desc.getValue().isEmpty()) {
+ description = desc.getValue();
+ }
+ }
+ }
+
+ Date date;
+ if (entry.getUpdatedDate() != null) {
+ date = entry.getUpdatedDate();
+ } else {
+ date = entry.getPublishedDate();
+ }
+ String author = entry.getAuthor();
+ if (author != null) {
+ author = StringEscapeUtils.escapeHtml(author);
+ }
+
+ // description = " " + description;
+ return new FeedsEntry(title, link, description, entry.getAuthor(), date);
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ public void setException(Throwable exception) {
+ this.exception = exception;
+ }
+
+ public List<FeedsEntry> getEntries() {
+ return entries;
+ }
+
+ public String getUrlString() {
+ return urlString;
+ }
+
+ @Override
+ public IStatus run(IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ exception = null;
+ long urlModified = -1;
+ if (!forcedDownload) {
+ urlModified = getUrlModified();
+ if (exception != null) {
+ return Status.CANCEL_STATUS;
+ }
+ }
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ if (forcedDownload || urlModified != cacheModified) {
+ try {
+ File tempFile = File.createTempFile("news", ".xml");
+ tempFile.deleteOnExit();
+ OutputStream destination = new FileOutputStream(tempFile);
+ IStatus status = ECFExamplesTransport.getInstance().download(
+ cacheFile.getName(), urlString, destination, monitor);
+ URL url = getURL();
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ 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
+ }
+ }
+ }
+ tempFile.delete();
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ cacheFile.setLastModified(cacheModified);
+ getEntries(cacheFile);
+ } else {
+ setException(status.getException());
+ }
+ } catch (Exception e) {
+ exception = e;
+ return Status.CANCEL_STATUS;
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ private long getUrlModified() {
+ URL url = getURL();
+ if (exception != null) {
+ return -1;
+ }
+ long urlModified;
+ try {
+ urlModified = ECFExamplesTransport.getInstance().getLastModified(
+ url);
+ } catch (CoreException e) {
+ exception = e;
+ urlModified = -1;
+ }
+ return urlModified;
+ }
+
+ private URL getURL() {
+ URL url;
+ try {
+ url = new URL(urlString);
+ return url;
+ } catch (MalformedURLException e) {
+ exception = e;
+ return null;
+ }
+ }
+
+ public boolean isForcedDownload() {
+ return forcedDownload;
+ }
+
+ public void setForcedDownload(boolean forced) {
+ this.forcedDownload = forced;
+ }
+
+ public boolean needsRefresh() {
+ return needsRefresh;
+ }
+
+ public void setNeedsRefresh(boolean needRefresh) {
+ this.needsRefresh = needRefresh;
+ }
+
+}
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 2011-11-22
23:13:41 UTC (rev 36544)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshBlogsJob.java 2011-11-22
23:13:50 UTC (rev 36545)
@@ -10,150 +10,29 @@
************************************************************************************/
package org.jboss.tools.central.jobs;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.io.File;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.IPath;
import org.jboss.tools.central.JBossCentralActivator;
-import org.jboss.tools.central.model.FeedsEntry;
-import com.sun.syndication.feed.synd.SyndContent;
-import com.sun.syndication.feed.synd.SyndEntry;
-import com.sun.syndication.feed.synd.SyndFeed;
-import com.sun.syndication.io.SyndFeedInput;
-import com.sun.syndication.io.XmlReader;
-
/**
*
* @author snjeza
*
*/
-public class RefreshBlogsJob extends Job {
+public class RefreshBlogsJob extends AbstractRefreshJob {
- private List<FeedsEntry> entries = new ArrayList<FeedsEntry>();
- private Exception exception;
- public static RefreshBlogsJob INSTANCE = new
RefreshBlogsJob(JBossCentralActivator.BLOGS_URL);
+ private static final String CACHE_FILE = "blogs.xml";
+ public static RefreshBlogsJob INSTANCE = new RefreshBlogsJob();
- private String blogsurl;
-
- private RefreshBlogsJob(String blogsurl) {
- super("Refreshing JBoss Blogs...");
- setPriority(LONG);
- this.blogsurl=blogsurl;
+ private RefreshBlogsJob() {
+ super("Refreshing JBoss Blogs...", JBossCentralActivator.BLOGS_URL);
}
@Override
- public IStatus run(IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- entries.clear();
- SyndFeedInput input = new SyndFeedInput();
- URL url;
- try {
- url = new URL(blogsurl);
- } catch (MalformedURLException e) {
- exception = e;
- return Status.CANCEL_STATUS;
- }
- try {
- SyndFeed syndFeed = input.build(new XmlReader(url));
- List<SyndEntry> feeds = syndFeed.getEntries();
- if (feeds == null || feeds.size() == 0) {
- return Status.OK_STATUS;
- }
- int i = 0;
-
- for (SyndEntry feed:feeds) {
- FeedsEntry entry = adaptEntry(feed);
- if (entry == null) {
- continue;
- }
- if (i++ > JBossCentralActivator.MAX_FEEDS) {
- break;
- }
- entries.add(entry);
- }
- } catch (Exception e) {
- exception = e;
- return Status.CANCEL_STATUS;
- }
- return Status.OK_STATUS;
+ public File getCacheFile() {
+ IPath location = JBossCentralActivator.getDefault().getStateLocation();
+ File file = new File(location.toFile(), CACHE_FILE);
+ return file;
}
-
-
- private FeedsEntry adaptEntry(SyndEntry entry) {
- if (entry == null) {
- return null;
- }
- String title = null;
- if (entry.getTitle() != null) {
- title = entry.getTitle();
- } else {
- SyndContent titleEx = entry.getTitleEx();
- if (titleEx != null && !titleEx.getValue().isEmpty()) {
- title = titleEx.getValue();
- }
- }
- if (title == null) {
- return null;
- }
- title = StringEscapeUtils.escapeHtml(title);
- String link;
- if (entry.getLink() != null) {
- link = entry.getLink();
- } else {
- link = entry.getUri();
- }
- String description = null;
- if (entry.getDescription() != null) {
- SyndContent desc = entry.getDescription();
- if (desc != null && !desc.getValue().isEmpty()) {
- description = desc.getValue();
- }
- }
- if (description == null) {
- List<SyndContent> contents = entry.getContents();
- if (contents != null && contents.size() > 0) {
- SyndContent desc = contents.get(0);
- if (desc != null && !desc.getValue().isEmpty()) {
- description = desc.getValue();
- }
- }
- }
-
-
- Date date;
- if (entry.getUpdatedDate() != null) {
- date = entry.getUpdatedDate();
- } else {
- date = entry.getPublishedDate();
- }
- String author = entry.getAuthor();
- if (author != null) {
- author = StringEscapeUtils.escapeHtml(author);
- }
-
- //description = " " + description;
- return new FeedsEntry(title, link, description, entry.getAuthor(), date);
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
-
- public List<FeedsEntry> getEntries() {
- return entries;
- }
}
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 2011-11-22
23:13:41 UTC (rev 36544)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshNewsJob.java 2011-11-22
23:13:50 UTC (rev 36545)
@@ -10,150 +10,30 @@
************************************************************************************/
package org.jboss.tools.central.jobs;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.io.File;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.IPath;
import org.jboss.tools.central.JBossCentralActivator;
-import org.jboss.tools.central.model.FeedsEntry;
-import com.sun.syndication.feed.synd.SyndContent;
-import com.sun.syndication.feed.synd.SyndEntry;
-import com.sun.syndication.feed.synd.SyndFeed;
-import com.sun.syndication.io.SyndFeedInput;
-import com.sun.syndication.io.XmlReader;
-
/**
*
* @author snjeza
*
*/
-public class RefreshNewsJob extends Job {
+public class RefreshNewsJob extends AbstractRefreshJob {
- private List<FeedsEntry> entries = new ArrayList<FeedsEntry>();
- private Exception exception;
- public static RefreshNewsJob INSTANCE = new
RefreshNewsJob(JBossCentralActivator.NEWS_URL);
+ private static final String CACHE_FILE = "news.xml";
+ public static RefreshNewsJob INSTANCE = new RefreshNewsJob();
+
- private String newsurl;
-
- private RefreshNewsJob(String newsurl) {
- super("Refreshing JBoss Blogs...");
- setPriority(LONG);
- this.newsurl=newsurl;
+ private RefreshNewsJob() {
+ super("Refreshing JBoss News...", JBossCentralActivator.NEWS_URL);
}
@Override
- public IStatus run(IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- entries.clear();
- SyndFeedInput input = new SyndFeedInput();
- URL url;
- try {
- url = new URL(newsurl);
- } catch (MalformedURLException e) {
- exception = e;
- return Status.CANCEL_STATUS;
- }
- try {
- SyndFeed syndFeed = input.build(new XmlReader(url));
- List<SyndEntry> feeds = syndFeed.getEntries();
- if (feeds == null || feeds.size() == 0) {
- return Status.OK_STATUS;
- }
- int i = 0;
-
- for (SyndEntry feed:feeds) {
- FeedsEntry entry = adaptEntry(feed);
- if (entry == null) {
- continue;
- }
- if (i++ > JBossCentralActivator.MAX_FEEDS) {
- break;
- }
- entries.add(entry);
- }
- } catch (Exception e) {
- exception = e;
- return Status.CANCEL_STATUS;
- }
- return Status.OK_STATUS;
+ public File getCacheFile() {
+ IPath location = JBossCentralActivator.getDefault().getStateLocation();
+ File file = new File(location.toFile(), CACHE_FILE);
+ return file;
}
-
-
- private FeedsEntry adaptEntry(SyndEntry entry) {
- if (entry == null) {
- return null;
- }
- String title = null;
- if (entry.getTitle() != null) {
- title = entry.getTitle();
- } else {
- SyndContent titleEx = entry.getTitleEx();
- if (titleEx != null && !titleEx.getValue().isEmpty()) {
- title = titleEx.getValue();
- }
- }
- if (title == null) {
- return null;
- }
- title = StringEscapeUtils.escapeHtml(title);
- String link;
- if (entry.getLink() != null) {
- link = entry.getLink();
- } else {
- link = entry.getUri();
- }
- String description = null;
- if (entry.getDescription() != null) {
- SyndContent desc = entry.getDescription();
- if (desc != null && !desc.getValue().isEmpty()) {
- description = desc.getValue();
- }
- }
- if (description == null) {
- List<SyndContent> contents = entry.getContents();
- if (contents != null && contents.size() > 0) {
- SyndContent desc = contents.get(0);
- if (desc != null && !desc.getValue().isEmpty()) {
- description = desc.getValue();
- }
- }
- }
-
-
- Date date;
- if (entry.getUpdatedDate() != null) {
- date = entry.getUpdatedDate();
- } else {
- date = entry.getPublishedDate();
- }
- String author = entry.getAuthor();
- if (author != null) {
- author = StringEscapeUtils.escapeHtml(author);
- }
-
- //description = " " + description;
- return new FeedsEntry(title, link, description, entry.getAuthor(), date);
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
-
- public List<FeedsEntry> getEntries() {
- return entries;
- }
}