Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2011-12-05 11:34:12 -0500
committerSteffen Pingel2011-12-05 11:34:12 -0500
commit37fc151f7c3bcd975ea83fdc7d02a41a77e7f538 (patch)
tree76d541fa2009856d01e6e398b132caabf3ecb3f7 /org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal
parente16cd7c253208a4324c43854bfb743e693beb1e7 (diff)
downloadorg.eclipse.mylyn.tasks-37fc151f7c3bcd975ea83fdc7d02a41a77e7f538.tar.gz
org.eclipse.mylyn.tasks-37fc151f7c3bcd975ea83fdc7d02a41a77e7f538.tar.xz
org.eclipse.mylyn.tasks-37fc151f7c3bcd975ea83fdc7d02a41a77e7f538.zip
NEW - bug 361048: [api] move service message implementation to
notifications component https://bugs.eclipse.org/bugs/show_bug.cgi?id=361048 Change-Id: I4f88348bfc60a084a01378931fd8210817fa8d79
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/Environment.java172
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedEntry.java107
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedReader.java65
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/IServiceMessageListener.java21
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessage.java122
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageEvent.java52
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageManager.java266
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageXmlHandler.java89
8 files changed, 0 insertions, 894 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/Environment.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/Environment.java
deleted file mode 100644
index cceae9426..000000000
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/Environment.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Tasktop Technologies and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.internal.tasks.core.notifications;
-
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.mylyn.commons.core.CoreUtil;
-import org.eclipse.osgi.service.resolver.VersionRange;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.Version;
-
-/**
- * @author Steffen Pingel
- */
-public class Environment {
-
- private final Dictionary<Object, Object> environment;
-
- public Environment() {
- environment = new Hashtable<Object, Object>(System.getProperties());
- }
-
- public Version getFrameworkVersion() {
- Bundle bundle = Platform.getBundle("org.eclipse.mylyn"); //$NON-NLS-1$
- if (bundle != null) {
- return CoreUtil.getVersion(bundle);
- } else {
- return Version.emptyVersion;
- }
- }
-
- public Version getPlatformVersion() {
- Bundle bundle = Platform.getBundle("org.eclipse.platform"); //$NON-NLS-1$
- if (bundle == null) {
- bundle = Platform.getBundle(Platform.PI_RUNTIME);
- }
- if (bundle != null) {
- String versionString = (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
- try {
- return new Version(versionString);
- } catch (IllegalArgumentException e) {
- // should never happen
- }
- }
- return Version.emptyVersion;
- }
-
- public Version getRuntimeVersion() {
- Version result = parseRuntimeVersion(System.getProperty("java.runtime.version")); //$NON-NLS-1$
- if (result == Version.emptyVersion) {
- result = parseRuntimeVersion(System.getProperty("java.version")); //$NON-NLS-1$
- }
- return result;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public boolean matches(FeedEntry entry, IProgressMonitor monitor) {
- if (!matchesVersion(entry.getFilter("frameworkVersion"), getFrameworkVersion())) { //$NON-NLS-1$
- return false;
- }
- if (!matchesVersion(entry.getFilter("platformVersion"), getPlatformVersion())) { //$NON-NLS-1$
- return false;
- }
- if (!matchesVersion(entry.getFilter("runtimeVersion"), getRuntimeVersion())) { //$NON-NLS-1$
- return false;
- }
- List<String> filterExpressions = entry.getFilters("filter"); //$NON-NLS-1$
- for (String filterExpression : filterExpressions) {
- try {
- Filter filter = FrameworkUtil.createFilter(filterExpression);
- if (!filter.match((Dictionary) environment)) {
- return false;
- }
- } catch (InvalidSyntaxException e) {
- // ignore that filter
- }
- }
- List<String> requiredFeatures = entry.getFilters("requires"); //$NON-NLS-1$
- for (String requiredFeature : requiredFeatures) {
- if (!getInstalledFeatures(monitor).contains(parseFeature(requiredFeature))) {
- return false;
- }
- }
- List<String> conflictedFeatures = entry.getFilters("conflicts"); //$NON-NLS-1$
- for (String conflictedFeature : conflictedFeatures) {
- if (getInstalledFeatures(monitor).contains(parseFeature(conflictedFeature))) {
- return false;
- }
- }
- return true;
- }
-
- private int findLastNumberIndex(String versionString, int secondSeparator) {
- int lastDigit = secondSeparator;
- for (int i = secondSeparator + 1; i < versionString.length(); i++) {
- if (Character.isDigit(versionString.charAt(i))) {
- lastDigit++;
- } else {
- break;
- }
- }
- if (lastDigit == secondSeparator) {
- return secondSeparator - 1;
- }
- return lastDigit;
- }
-
- public Set<String> getInstalledFeatures(IProgressMonitor monitor) {
- return Collections.emptySet();
- }
-
- private boolean matchesVersion(String expectedVersionRangeExpression, Version actualVersion) {
- if (expectedVersionRangeExpression != null) {
- try {
- VersionRange versionRange = new VersionRange(expectedVersionRangeExpression);
- if (!versionRange.isIncluded(actualVersion)) {
- return false;
- }
- } catch (IllegalArgumentException e) {
- // ignore
- }
- }
- return true;
- }
-
- private String parseFeature(String requiredFeature) {
- int i = requiredFeature.indexOf(";"); //$NON-NLS-1$
- if (i != -1) {
- return requiredFeature.substring(0, i);
- }
- return requiredFeature;
- }
-
- private Version parseRuntimeVersion(String versionString) {
- if (versionString != null) {
- int firstSeparator = versionString.indexOf('.');
- if (firstSeparator != -1) {
- try {
- int secondSeparator = versionString.indexOf('.', firstSeparator + 1);
- if (secondSeparator != -1) {
- return new Version(versionString.substring(0,
- findLastNumberIndex(versionString, secondSeparator) + 1));
- }
- return new Version(versionString.substring(0,
- findLastNumberIndex(versionString, firstSeparator) + 1));
- } catch (IllegalArgumentException e) {
- // ignore
- }
- }
- }
- return Version.emptyVersion;
- }
-
-}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedEntry.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedEntry.java
deleted file mode 100644
index 4098c4c88..000000000
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedEntry.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Tasktop Technologies and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.internal.tasks.core.notifications;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-
-import com.sun.syndication.feed.module.DCModule;
-import com.sun.syndication.feed.module.DCSubject;
-import com.sun.syndication.feed.synd.SyndEntry;
-
-/**
- * @author Steffen Pingel
- */
-public class FeedEntry extends ServiceMessage {
-
- private final SyndEntry source;
-
- public FeedEntry(SyndEntry source) {
- this.source = source;
- setId(source.getUri());
- setTitle(source.getTitle());
- if (source.getDescription() != null) {
- setDescription(source.getDescription().getValue());
- }
- setUrl(source.getLink());
- setImage("dialog_messasge_info_image"); //$NON-NLS-1$
- }
-
- public FeedEntry() {
- this.source = null;
- }
-
- public SyndEntry getSource() {
- return source;
- }
-
- public List<String> getFilters(String key) {
- Assert.isNotNull(key);
- List<String> result = new ArrayList<String>();
- DCModule module = (DCModule) source.getModule(DCModule.URI);
- if (module != null && module.getSubjects() != null) {
- for (Iterator<?> it = module.getSubjects().iterator(); it.hasNext();) {
- DCSubject category = (DCSubject) it.next();
- String value = parseFilter(key, category.getValue());
- if (value != null) {
- result.add(value);
- }
- }
- }
-// for (Iterator<?> it = source.getCategories().iterator(); it.hasNext();) {
-// SyndCategory category = (SyndCategory) it.next();
-// String value = parseFilter(key, category.getName());
-// if (value != null) {
-// result.add(value);
-// }
-// }
- return result;
- }
-
- public String getFilter(String key) {
- Assert.isNotNull(key);
- DCModule module = (DCModule) source.getModule(DCModule.URI);
- if (module != null && module.getSubjects() != null) {
- for (Iterator<?> it = module.getSubjects().iterator(); it.hasNext();) {
- DCSubject category = (DCSubject) it.next();
- String value = parseFilter(key, category.getValue());
- if (value != null) {
- return value;
- }
- }
- }
-// for (Iterator<?> it = source.getCategories().iterator(); it.hasNext();) {
-// SyndCategory category = (SyndCategory) it.next();
-// String value = parseCategory(key, category.getName());
-// if (value != null) {
-// return value;
-// }
-// }
- return null;
- }
-
- private String parseFilter(String key, String category) {
- if (category != null) {
- int i = category.indexOf("="); //$NON-NLS-1$
- if (i != -1) {
- if (category.substring(0, i).trim().equals(key)) {
- return category.substring(i + 1).trim();
- }
- }
- }
- return null;
- }
-
-}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedReader.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedReader.java
deleted file mode 100644
index bba4dfc1e..000000000
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/FeedReader.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Tasktop Technologies and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.internal.tasks.core.notifications;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
-
-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 Steffen Pingel
- */
-public class FeedReader {
-
- private final Environment environment;
-
- private final List<FeedEntry> entries;
-
- public FeedReader(Environment environment) {
- this.environment = environment;
- this.entries = new ArrayList<FeedEntry>();
- }
-
- public IStatus parse(InputStream in, IProgressMonitor monitor) {
- SyndFeedInput input = new SyndFeedInput();
- try {
- SyndFeed feed = input.build(new XmlReader(in));
- for (Iterator<?> it = feed.getEntries().iterator(); it.hasNext();) {
- SyndEntry syndEntry = (SyndEntry) it.next();
- FeedEntry entry = new FeedEntry(syndEntry);
- if (environment.matches(entry, monitor)) {
- entries.add(entry);
- }
- }
- return Status.OK_STATUS;
- } catch (Exception e) {
- return new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, IStatus.ERROR,
- "Failed to parse RSS feed", e); //$NON-NLS-1$
- }
- }
-
- public List<FeedEntry> getEntries() {
- return entries;
- }
-
-}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/IServiceMessageListener.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/IServiceMessageListener.java
deleted file mode 100644
index eca6e93c3..000000000
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/IServiceMessageListener.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Tasktop Technologies and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.internal.tasks.core.notifications;
-
-/**
- * @author Robert Elves
- */
-public interface IServiceMessageListener {
-
- public void handleEvent(ServiceMessageEvent event);
-
-}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessage.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessage.java
deleted file mode 100644
index 144e82d7a..000000000
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessage.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Tasktop Technologies and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.internal.tasks.core.notifications;
-
-/**
- * @author Robert Elves
- */
-public class ServiceMessage implements Comparable<ServiceMessage> {
-
- public enum Element {
- ID, TITLE, DESCRIPTION, URL, IMAGE
- };
-
- private String id;
-
- private String title;
-
- private String description;
-
- private String url;
-
- private String image;
-
- private String eTag;
-
- private String lastModified;
-
- public String getId() {
- return id;
- }
-
- public String getTitle() {
- return title;
- }
-
- public String getDescription() {
- return description;
- }
-
- public String getUrl() {
- return url;
- }
-
- public String getImage() {
- return image;
- }
-
- public void setETag(String eTag) {
- this.eTag = eTag;
- }
-
- public void setLastModified(String lastModified) {
- this.lastModified = lastModified;
- }
-
- public String getETag() {
- return eTag;
- }
-
- public String getLastModified() {
- return lastModified;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public void setImage(String image) {
- this.image = image;
- }
-
- public boolean isValid() {
- return id != null && title != null && description != null && image != null;
- }
-
- public int compareTo(ServiceMessage o) {
- return -getId().compareTo(o.getId());
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("ServiceMessage [id="); //$NON-NLS-1$
- builder.append(id);
- builder.append(", title="); //$NON-NLS-1$
- builder.append(title);
- builder.append(", description="); //$NON-NLS-1$
- builder.append(description);
- builder.append(", url="); //$NON-NLS-1$
- builder.append(url);
- builder.append(", image="); //$NON-NLS-1$
- builder.append(image);
- builder.append(", eTag="); //$NON-NLS-1$
- builder.append(eTag);
- builder.append(", lastModified="); //$NON-NLS-1$
- builder.append(lastModified);
- builder.append("]"); //$NON-NLS-1$
- return builder.toString();
- }
-
-}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageEvent.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageEvent.java
deleted file mode 100644
index 8483cd5c7..000000000
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageEvent.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Tasktop Technologies and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.internal.tasks.core.notifications;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.EventObject;
-import java.util.List;
-
-/**
- * @author Steffen Pingel
- */
-public class ServiceMessageEvent extends EventObject {
-
- public enum EVENT_KIND {
- MESSAGE_UPDATE, STOP
- };
-
- private static final long serialVersionUID = 1L;
-
- private final List<ServiceMessage> messages;
-
- private final EVENT_KIND eventKind;
-
- public ServiceMessageEvent(ServiceMessageManager manager, EVENT_KIND kind) {
- this(manager, kind, new ArrayList<ServiceMessage>());
- }
-
- public ServiceMessageEvent(ServiceMessageManager manager, EVENT_KIND eventKind, List<ServiceMessage> messages) {
- super(manager);
- this.eventKind = eventKind;
- this.messages = Collections.unmodifiableList(new ArrayList<ServiceMessage>(messages));
- }
-
- public List<ServiceMessage> getMessages() {
- return messages;
- }
-
- public EVENT_KIND getEventKind() {
- return eventKind;
- }
-
-}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageManager.java
deleted file mode 100644
index 8c19a2ef5..000000000
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageManager.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2010 Tasktop Technologies.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Tasktop EULA
- * which accompanies this distribution, and is available at
- * http://tasktop.com/legal
- *******************************************************************************/
-
-package org.eclipse.mylyn.internal.tasks.core.notifications;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.mylyn.commons.core.StatusHandler;
-import org.eclipse.mylyn.commons.net.WebLocation;
-import org.eclipse.mylyn.commons.net.WebUtil;
-import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
-
-/**
- * @author Robert Elves
- * @author Steffen Pingel
- */
-public class ServiceMessageManager {
-
- protected static final long START_DELAY = 30 * 1000;
-
- protected static final long RECHECK_DELAY = 14 * 24 * 60 * 60 * 1000;
-
- private String serviceMessageUrl;
-
- private volatile List<? extends ServiceMessage> messages = Collections.emptyList();
-
- private Job messageCheckJob;
-
- private final List<IServiceMessageListener> listeners = new CopyOnWriteArrayList<IServiceMessageListener>();
-
- private String lastModified;
-
- private String eTag;
-
- private boolean statusLogged;
-
- private final long checktime;
-
- private final Environment environment;
-
- public ServiceMessageManager(String serviceMessageUrl, String lastModified, String eTag, long checktime,
- Environment environment) {
- this.serviceMessageUrl = serviceMessageUrl;
- this.lastModified = lastModified;
- this.checktime = checktime;
- this.eTag = eTag;
- this.environment = environment;
- }
-
- public ServiceMessageManager(String serviceMessageUrl, String lastModified, String eTag, long checktime) {
- this(serviceMessageUrl, lastModified, eTag, checktime, new Environment());
- }
-
- public void start() {
- if (messageCheckJob == null) {
- messageCheckJob = new Job("Checking for new service message") { //$NON-NLS-1$
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- updateServiceMessage(monitor);
- return Status.OK_STATUS;
- } catch (Throwable t) {
- // fail silently
- return Status.CANCEL_STATUS;
- }
- }
-
- };
- messageCheckJob.setSystem(true);
- messageCheckJob.setPriority(Job.DECORATE);
- messageCheckJob.addJobChangeListener(new JobChangeAdapter() {
- @Override
- public void done(IJobChangeEvent event) {
- if (messageCheckJob != null) {
- messageCheckJob.schedule(RECHECK_DELAY);
- }
- }
- });
- }
- if (checktime == 0) {
- messageCheckJob.schedule(START_DELAY);
- } else {
- long nextCheckTime = checktime + RECHECK_DELAY;
- long now = System.currentTimeMillis();
- if (nextCheckTime < now) {
- messageCheckJob.schedule(START_DELAY);
- } else if (nextCheckTime > now) {
- if (nextCheckTime - now < START_DELAY) {
- messageCheckJob.schedule(START_DELAY);
- } else {
- messageCheckJob.schedule(nextCheckTime - now);
- }
- }
- }
- }
-
- public void stop() {
- if (messageCheckJob != null) {
- messageCheckJob.cancel();
- messageCheckJob = null;
- }
-
- final ServiceMessageEvent event = new ServiceMessageEvent(this, ServiceMessageEvent.EVENT_KIND.STOP);
-
- for (final IServiceMessageListener listener : listeners) {
- SafeRunner.run(new ISafeRunnable() {
- public void run() throws Exception {
- listener.handleEvent(event);
- }
-
- public void handleException(Throwable e) {
- StatusHandler.log(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN, "Listener failed: " //$NON-NLS-1$
- + listener.getClass(), e));
- }
- });
- }
- }
-
- public void setServiceMessageUrl(String url) {
- this.serviceMessageUrl = url;
- }
-
- public void addServiceMessageListener(IServiceMessageListener listener) {
- listeners.add(listener);
- }
-
- public void removeServiceMessageListener(IServiceMessageListener listener) {
- listeners.remove(listener);
- }
-
- private void notifyListeners(List<? extends ServiceMessage> messages) {
- this.messages = messages;
- for (final ServiceMessage message : messages) {
- message.setETag(eTag);
- message.setLastModified(lastModified);
- }
-
- ArrayList<ServiceMessage> sortedMessages = new ArrayList<ServiceMessage>(messages);
- Collections.sort(messages);
- final ServiceMessageEvent event = new ServiceMessageEvent(this, ServiceMessageEvent.EVENT_KIND.MESSAGE_UPDATE,
- sortedMessages);
- for (final IServiceMessageListener listener : listeners) {
- SafeRunner.run(new ISafeRunnable() {
- public void run() throws Exception {
- listener.handleEvent(event);
- }
-
- public void handleException(Throwable e) {
- StatusHandler.log(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN, "Listener failed: " //$NON-NLS-1$
- + listener.getClass(), e));
- }
- });
- }
- }
-
- public List<ServiceMessage> getServiceMessages() {
- return new ArrayList<ServiceMessage>(this.messages);
- }
-
- /**
- * Public for testing
- */
- public int updateServiceMessage(IProgressMonitor monitor) {
- int status = -1;
- List<? extends ServiceMessage> messages = null;
- try {
- HttpClient httpClient = new HttpClient(WebUtil.getConnectionManager());
- WebUtil.configureHttpClient(httpClient, null);
-
- WebLocation location = new WebLocation(serviceMessageUrl);
- HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(httpClient, location,
- new SubProgressMonitor(monitor, 1));
-
- GetMethod method = new GetMethod(serviceMessageUrl);
- method.setRequestHeader("If-Modified-Since", lastModified); //$NON-NLS-1$
- method.setRequestHeader("If-None-Match", eTag); //$NON-NLS-1$
-
- try {
- status = WebUtil.execute(httpClient, hostConfiguration, method, monitor);
- if (status == HttpStatus.SC_OK && !monitor.isCanceled()) {
- Header lastModifiedHeader = method.getResponseHeader("Last-Modified"); //$NON-NLS-1$
- if (lastModifiedHeader != null) {
- lastModified = lastModifiedHeader.getValue();
- }
- Header eTagHeader = method.getResponseHeader("ETag"); //$NON-NLS-1$
- if (eTagHeader != null) {
- eTag = eTagHeader.getValue();
- }
-
- InputStream in = WebUtil.getResponseBodyAsStream(method, monitor);
- try {
- messages = readMessages(in, monitor);
- } finally {
- in.close();
- }
- } else if (status == HttpStatus.SC_NOT_FOUND) {
- // no messages
- } else if (status == HttpStatus.SC_NOT_MODIFIED) {
- // no new messages
- } else {
- logStatus(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN,
- "Http error retrieving service message: " + HttpStatus.getStatusText(status))); //$NON-NLS-1$
- }
- } finally {
- WebUtil.releaseConnection(method, monitor);
- }
- } catch (Exception e) {
- logStatus(new Status(IStatus.WARNING, ITasksCoreConstants.ID_PLUGIN,
- "Http error retrieving service message.", e)); //$NON-NLS-1$
- }
-
- if (messages != null && messages.size() > 0) {
- notifyListeners(messages);
- }
- return status;
- }
-
- private void logStatus(IStatus status) {
- if (!statusLogged) {
- statusLogged = true;
- //StatusHandler.log(status);
- }
- }
-
-// private List<ServiceMessage> readMessages(InputStream in) throws ParserConfigurationException, SAXException,
-// IOException {
-// SAXParserFactory factory = SAXParserFactory.newInstance();
-// factory.setValidating(false);
-// SAXParser parser = factory.newSAXParser();
-//
-// ServiceMessageXmlHandler handler = new ServiceMessageXmlHandler();
-// parser.parse(in, handler);
-// return handler.getMessages();
-// }
-
- private List<? extends ServiceMessage> readMessages(InputStream in, IProgressMonitor monitor) throws IOException {
- FeedReader reader = new FeedReader(environment);
- reader.parse(in, monitor);
- return reader.getEntries();
- }
-
-}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageXmlHandler.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageXmlHandler.java
deleted file mode 100644
index 27b5fa6fe..000000000
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/notifications/ServiceMessageXmlHandler.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Tasktop Technologies and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.internal.tasks.core.notifications;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * @author Robert Elves
- * @author Steffen Pingel
- */
-public class ServiceMessageXmlHandler extends DefaultHandler {
-
- private static final String TAG_MESSAGE = "ServiceMessage"; //$NON-NLS-1$
-
- private StringBuilder characters;
-
- private final List<ServiceMessage> messages = new ArrayList<ServiceMessage>();
-
- private ServiceMessage message;
-
- @Override
- public void characters(char[] ch, int start, int length) throws SAXException {
- characters.append(ch, start, length);
- }
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if (TAG_MESSAGE.equals(qName.trim())) {
- message = new ServiceMessage();
- }
- characters = new StringBuilder();
- }
-
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException {
- if (message == null) {
- return;
- }
- if (TAG_MESSAGE.equals(qName.trim())) {
- if (message.isValid()) {
- messages.add(message);
- }
- } else {
- String parsedText = characters.toString();
- ServiceMessage.Element element;
- try {
- element = ServiceMessage.Element.valueOf(qName.trim().toUpperCase());
- switch (element) {
- case ID:
- message.setId(parsedText);
- break;
- case DESCRIPTION:
- message.setDescription(parsedText);
- break;
- case TITLE:
- message.setTitle(parsedText);
- break;
- case URL:
- message.setUrl(parsedText);
- break;
- case IMAGE:
- message.setImage(parsedText);
- break;
- }
- } catch (IllegalArgumentException e) {
- // ignore unrecognized elements
- }
- }
- }
-
- public List<ServiceMessage> getMessages() {
- return new ArrayList<ServiceMessage>(messages);
- }
-
-}

Back to the top