diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/VersionInformation.java b/libreplan-business/src/main/java/org/libreplan/business/common/VersionInformation.java
index 113768faf..6daecdd1c 100644
--- a/libreplan-business/src/main/java/org/libreplan/business/common/VersionInformation.java
+++ b/libreplan-business/src/main/java/org/libreplan/business/common/VersionInformation.java
@@ -19,18 +19,66 @@
package org.libreplan.business.common;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* It contains the current version of project and implements of singleton
- * pattern.
+ * pattern.
+ * It also has a cached value with information about last project version
+ * published. It checks the last version against a URL.
+ *
* @author Susana Montes Pedreira
*/
public class VersionInformation {
+ private static final Log LOG = LogFactory.getLog(VersionInformation.class);
+
+ /**
+ * URL with a text file only with last number version of LibrePlan
+ */
+ private static final String LIBREPLAN_VERSION_URL = "http://libreplan.org/VERSION";
+
+ /**
+ * Delay to wait till we check the URL again
+ */
+ private static final long DELAY_TO_CHECK_URL = 24 * 60 * 60 * 1000; // 1 day
+
private static final VersionInformation singleton = new VersionInformation();
private String projectVersion;
+ private boolean newVersionCached = false;
+
+ private Date lastVersionCachedDate = new Date();
+
private VersionInformation() {
+ loadNewVersionFromURL();
+ }
+
+ private void loadNewVersionFromURL() {
+ lastVersionCachedDate = new Date();
+ try {
+ URL url = new URL(LIBREPLAN_VERSION_URL);
+ String lastVersion = (new BufferedReader(new InputStreamReader(
+ url.openStream()))).readLine();
+ if (projectVersion != null && lastVersion != null) {
+ newVersionCached = !projectVersion.equals(lastVersion);
+ }
+ } catch (MalformedURLException e) {
+ LOG.warn("Problems reading LibrePlan version from "
+ + LIBREPLAN_VERSION_URL, e);
+ } catch (IOException e) {
+ LOG.warn("Problems reading LibrePlan version from "
+ + LIBREPLAN_VERSION_URL, e);
+ }
}
public static VersionInformation getInstance() {
@@ -52,4 +100,27 @@ public class VersionInformation {
projectVersion = argVersion;
}
-}
\ No newline at end of file
+ /**
+ * Returns true if a new version of the project is published.
+ */
+ public static boolean isNewVersionAvailable() {
+ return singleton.checkIsNewVersionAvailable();
+ }
+
+ /**
+ * If there is a new version already detected, it doesn't check it again.
+ * Otherwise, during one day it returns the cached value. And it checks it
+ * again after that time.
+ */
+ private boolean checkIsNewVersionAvailable() {
+ if (!newVersionCached) {
+ long oneDayLater = lastVersionCachedDate.getTime()
+ + DELAY_TO_CHECK_URL;
+ if (oneDayLater < new Date().getTime()) {
+ loadNewVersionFromURL();
+ }
+ }
+ return newVersionCached;
+ }
+
+}
diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateController.java
index 66cb1c88e..01a72b305 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateController.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/TemplateController.java
@@ -28,6 +28,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.libreplan.business.common.VersionInformation;
import org.libreplan.business.scenarios.IScenarioManager;
import org.libreplan.business.scenarios.entities.Scenario;
import org.libreplan.web.common.ITemplateModel.IOnFinished;
@@ -182,4 +183,8 @@ public class TemplateController extends GenericForwardComposer {
return templateModel.isUserAdmin();
}
+ public boolean isNewVersionAvailable() {
+ return VersionInformation.isNewVersionAvailable();
+ }
+
}
diff --git a/libreplan-webapp/src/main/webapp/common/layout/template.zul b/libreplan-webapp/src/main/webapp/common/layout/template.zul
index 5025e945d..9331af4cb 100644
--- a/libreplan-webapp/src/main/webapp/common/layout/template.zul
+++ b/libreplan-webapp/src/main/webapp/common/layout/template.zul
@@ -156,6 +156,15 @@ signature="java.lang.Boolean isDefaultPasswordsControl()"?>
+