KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > LatestVersionPlugin


1 /*
2  * LatestVersionPlugin.java - Latest Version Check Plugin
3  * Copyright (C) 1999, 2003 Slava Pestov
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */

19
20 import javax.swing.JOptionPane JavaDoc;
21 import java.io.*;
22 import java.net.URL JavaDoc;
23 import org.gjt.sp.jedit.*;
24
25 public class LatestVersionPlugin extends EditPlugin
26 {
27     public static void doVersionCheck(View view)
28     {
29         view.showWaitCursor();
30
31         try
32         {
33             URL JavaDoc url = new URL JavaDoc(jEdit.getProperty(
34                 "version-check.url"));
35             InputStream in = url.openStream();
36             BufferedReader bin = new BufferedReader(
37                 new InputStreamReader(in));
38
39             String JavaDoc line;
40             String JavaDoc develBuild = null;
41             String JavaDoc stableBuild = null;
42             while((line = bin.readLine()) != null)
43             {
44                 if(line.startsWith(".build"))
45                     develBuild = line.substring(6).trim();
46                 else if(line.startsWith(".stablebuild"))
47                     stableBuild = line.substring(12).trim();
48             }
49
50             bin.close();
51
52             if(develBuild != null && stableBuild != null)
53             {
54                 doVersionCheck(view,stableBuild,develBuild);
55             }
56         }
57         catch(IOException e)
58         {
59             String JavaDoc[] args = { jEdit.getProperty("version-check.url"),
60                 e.toString() };
61             GUIUtilities.error(view,"read-error",args);
62         }
63
64         view.hideWaitCursor();
65     }
66
67     public static void doVersionCheck(View view, String JavaDoc stableBuild,
68         String JavaDoc develBuild)
69     {
70         String JavaDoc myBuild = jEdit.getBuild();
71         String JavaDoc pre = myBuild.substring(6,7);
72         String JavaDoc variant;
73         String JavaDoc build;
74
75         if(pre.equals("99"))
76         {
77             variant = "stable";
78             build = stableBuild;
79         }
80         else
81         {
82             variant = "devel";
83             build = develBuild;
84         }
85
86         // special case: no current development version
87
if(develBuild.compareTo(stableBuild) < 0)
88             variant += "-nodevel";
89
90         int retVal = GUIUtilities.confirm(view,"version-check." + variant,
91             new String JavaDoc[] { MiscUtilities.buildToVersion(myBuild),
92                 MiscUtilities.buildToVersion(stableBuild),
93                 MiscUtilities.buildToVersion(develBuild) },
94                 JOptionPane.YES_NO_OPTION,
95                 JOptionPane.QUESTION_MESSAGE);
96         if(retVal == JOptionPane.YES_OPTION)
97             jEdit.openFile(view,jEdit.getProperty("version-check.url"));
98     }
99 }
100
Popular Tags