Store and propagate the latest edition, too.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Jan 2011 06:30:36 +0000 (07:30 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Jan 2011 06:30:36 +0000 (07:30 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/CoreListener.java
src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java
src/main/java/net/pterodactylus/sone/core/UpdateChecker.java
src/main/java/net/pterodactylus/sone/core/UpdateListener.java
src/main/java/net/pterodactylus/sone/core/UpdateListenerManager.java
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index 364b9f1..99a119b 100644 (file)
@@ -1771,8 +1771,8 @@ public class Core implements IdentityListener, UpdateListener {
         * {@inheritDoc}
         */
        @Override
-       public void updateFound(Version version, long releaseTime) {
-               coreListenerManager.fireUpdateFound(version, releaseTime);
+       public void updateFound(Version version, long releaseTime, long latestEdition) {
+               coreListenerManager.fireUpdateFound(version, releaseTime, latestEdition);
        }
 
 }
index 5fbb333..fb83c9f 100644 (file)
@@ -135,7 +135,9 @@ public interface CoreListener extends EventListener {
         *            The version that was found
         * @param releaseTime
         *            The release time of the new version
+        * @param latestEdition
+        *            The latest edition of the Sone homepage
         */
-       public void updateFound(Version version, long releaseTime);
+       public void updateFound(Version version, long releaseTime, long latestEdition);
 
 }
index 4fc9532..6dbdc58 100644 (file)
@@ -201,15 +201,17 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        /**
         * Notifies all listeners that a new version was found.
         *
-        * @see CoreListener#updateFound(Version, long)
+        * @see CoreListener#updateFound(Version, long, long)
         * @param version
         *            The new version
         * @param releaseTime
         *            The release time of the new version
+        * @param latestEdition
+        *            The latest edition of the Sone homepage
         */
-       void fireUpdateFound(Version version, long releaseTime) {
+       void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
                for (CoreListener coreListener : getListeners()) {
-                       coreListener.updateFound(version, releaseTime);
+                       coreListener.updateFound(version, releaseTime, latestEdition);
                }
        }
 
index 51e8df4..e07e160 100644 (file)
@@ -60,6 +60,9 @@ public class UpdateChecker {
        /** The current URI of the homepage. */
        private FreenetURI currentUri;
 
+       /** The latest known edition. */
+       private long latestEdition;
+
        /** The current latest known version. */
        private Version currentLatestVersion = SonePlugin.VERSION;
 
@@ -135,6 +138,15 @@ public class UpdateChecker {
                return latestVersionDate;
        }
 
+       /**
+        * Returns the latest known edition of the Sone homepage.
+        *
+        * @return The latest edition of the Sone homepage
+        */
+       public long getLatestEdition() {
+               return latestEdition;
+       }
+
        //
        // ACTIONS
        //
@@ -163,7 +175,8 @@ public class UpdateChecker {
                                        }
                                        Bucket resultBucket = uriResult.getRight().asBucket();
                                        try {
-                                               parseProperties(resultBucket.getInputStream());
+                                               parseProperties(resultBucket.getInputStream(), edition);
+                                               latestEdition = edition;
                                        } catch (IOException ioe1) {
                                                logger.log(Level.WARNING, "Could not parse sone.properties of " + uri, ioe1);
                                        } finally {
@@ -189,14 +202,16 @@ public class UpdateChecker {
         * Parses the properties of the latest version and fires events, if
         * necessary.
         *
-        * @see UpdateListener#updateFound(Version, long)
-        * @see UpdateListenerManager#fireUpdateFound(Version, long)
+        * @see UpdateListener#updateFound(Version, long, long)
+        * @see UpdateListenerManager#fireUpdateFound(Version, long, long)
         * @param propertiesInputStream
         *            The input stream to parse
+        * @param edition
+        *            The latest edition of the Sone homepage
         * @throws IOException
         *             if an I/O error occured
         */
-       private void parseProperties(InputStream propertiesInputStream) throws IOException {
+       private void parseProperties(InputStream propertiesInputStream, long edition) throws IOException {
                Properties properties = new Properties();
                InputStreamReader inputStreamReader = null;
                try {
@@ -226,7 +241,7 @@ public class UpdateChecker {
                        currentLatestVersion = version;
                        latestVersionDate = releaseTime;
                        logger.log(Level.INFO, "Found new version: %s (%tc)", new Object[] { version, new Date(releaseTime) });
-                       updateListenerManager.fireUpdateFound(version, releaseTime);
+                       updateListenerManager.fireUpdateFound(version, releaseTime, edition);
                }
        }
 
index 1469afa..18f4b88 100644 (file)
@@ -36,7 +36,9 @@ public interface UpdateListener extends EventListener {
         *            The version that was found
         * @param releaseTime
         *            The release time of the version
+        * @param latestEdition
+        *            The latest edition of the Sone homepage
         */
-       public void updateFound(Version version, long releaseTime);
+       public void updateFound(Version version, long releaseTime, long latestEdition);
 
 }
index 3f3b21f..cddf8db 100644 (file)
@@ -45,10 +45,12 @@ public class UpdateListenerManager extends AbstractListenerManager<Void, UpdateL
         *            The new version
         * @param releaseTime
         *            The release time of the new version
+        * @param latestEdition
+        *            The latest edition of the Sone homepage
         */
-       void fireUpdateFound(Version version, long releaseTime) {
+       void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
                for (UpdateListener updateListener : getListeners()) {
-                       updateListener.updateFound(version, releaseTime);
+                       updateListener.updateFound(version, releaseTime, latestEdition);
                }
        }
 
index fa43945..a7df9c2 100644 (file)
@@ -193,6 +193,7 @@ public class SoneTemplatePage extends TemplatePage {
                templateContext.set("request", request);
                templateContext.set("currentVersion", SonePlugin.VERSION);
                templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion());
+               templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition());
                templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
                templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
        }
index 0df6d79..67a3952 100644 (file)
@@ -765,7 +765,7 @@ public class WebInterface implements CoreListener {
         * {@inheritDoc}
         */
        @Override
-       public void updateFound(Version version, long releaseTime) {
+       public void updateFound(Version version, long releaseTime, long latestEdition) {
                newVersionNotification.getTemplateContext().set("version", version);
                newVersionNotification.getTemplateContext().set("releaseTime", releaseTime);
                notificationManager.addNotification(newVersionNotification);