|
/******************************************************************************
Copyright (C) 2006 MakeLogic
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Date : 14th December 2005
Authors : MakeLogic
Design : Ujjwal
Developer : Dharma
********************************************************************************/
package com.makeLogic;
import java.awt.*;
import java.lang.reflect.Method;
import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.html.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import com.makeLogic.utils.Trace;
public class CheckForNewUpdates implements Runnable
{
Component parentComponent;
final public static String MODULE_NAME = "MakeLogicTail_2.1.0";
public static String uid;
String updateLink = "http://www.makelogic.com";
String updateURL = "http://makelogictail.sourceforge.net/cgi-bin/MakeLogicTail.cgi";
String os_name = "";
String os_version = "";
String java_version = "";
String jvm_version = "";
String jrt_version = "";
String jvm_vendor = "";
String jrt_name = "";
Hashtable paramsHashtable;
public CheckForNewUpdates(Component parent)
{
Trace.enter("CheckForNewUpdates.CheckForNewUpdates");
parentComponent = parent;
//..Read the uid from the properties file
int maxValue = getMaxValue(Tail.tailMDI.keySetValues);
for(int i = 1 ; i < maxValue+1; i++)
{
try
{
String tempString = Tail.tailMDI.keySetValues.getProperty(""+i);
//..Verify if uid present or not
if(tempString.startsWith("uid"))
{
tempString = tempString.substring(tempString.indexOf("=")+1);
uid = tempString;
break;
}
}
catch(Exception exp)
{
//..Exception thrown when the property value does not exists
//..Do Nothing
Trace.exception(exp);
}
}
if(uid==null)
{
uid="0";
}
Thread thread = new Thread(this);
thread.start();
Trace.exit("CheckForNewUpdates.CheckForNewUpdates");
}
//..Call System.getProperty with exception handling
public static String getProperty(String name)
{
String value = "";
try
{
value = System.getProperty(name);
//..Debug
//..System.out.println("..ML.. :: "+name+"="+value);
if(value == null)
{
value = "NOT_FOUND";
}
return value;
}
catch(Exception ex)
{
//..Debug
//..System.out.println("..ML.. 1."+ex.getMessage());
//..ex.printStackTrace();
value = ex.getMessage();
Trace.exception(ex);
return value;
}
}
public void run()
{
Trace.enter("CheckForNewUpdates.run");
try
{
os_name = getProperty("os.name");
os_version = getProperty("os.version");
java_version = getProperty("java.version");
jvm_version = getProperty("java.vm.version");
jrt_version = getProperty("java.runtime.version");
jvm_vendor = getProperty("java.vm.vendor");
jrt_name = getProperty("java.runtime.name");
//..Encode the ULR parameters
String urlParameters = "";
//..UID
urlParameters += URLEncoder.encode("UID", "UTF-8") + "=" + URLEncoder.encode(uid, "UTF-8");
//..Module Name
urlParameters += "&" + URLEncoder.encode("ModuleName", "UTF-8") + "=" + URLEncoder.encode(CheckForNewUpdates.MODULE_NAME, "UTF-8");
//..ut -> Usage Time
urlParameters += "&" + URLEncoder.encode("ut", "UTF-8") + "=" + URLEncoder.encode(TailMDI.ut+"", "UTF-8");
//..os_name
urlParameters += "&" + URLEncoder.encode("os_name", "UTF-8") + "=" + URLEncoder.encode(os_name, "UTF-8");
//..os_version
urlParameters += "&" + URLEncoder.encode("os_version", "UTF-8") + "=" + URLEncoder.encode(os_version, "UTF-8");
//..java_version
urlParameters += "&" + URLEncoder.encode("java_version", "UTF-8") + "=" + URLEncoder.encode(java_version, "UTF-8");
//..jvm_version
urlParameters += "&" + URLEncoder.encode("jvm_version", "UTF-8") + "=" + URLEncoder.encode(jvm_version, "UTF-8");
//..jrt_version
urlParameters += "&" + URLEncoder.encode("jrt_version", "UTF-8") + "=" + URLEncoder.encode(jrt_version, "UTF-8");
//..jvm_vendor
urlParameters += "&" + URLEncoder.encode("jvm_vedor", "UTF-8") + "=" + URLEncoder.encode(jvm_vendor, "UTF-8");
//..jrt_name
urlParameters += "&" + URLEncoder.encode("jrt_name", "UTF-8") + "=" + URLEncoder.encode(jrt_name, "UTF-8");
//String urlString = "http://makelogictail.sourceforge.net/cgi-bin/MakeLogicTail.cgi?UID="+uid+"&ModuleName="+CheckForNewUpdates.MODULE_NAME;
//..String urlString = "http://makelogictail.sourceforge.net/cgi-bin/MakeLogicTail.cgi?UID="+uid+"&ModuleName="+CheckForNewUpdates.MODULE_NAME+"&ut="+TailMDI.ut;
//..Build the complete URL with parameters
String urlString = updateURL+"?"+urlParameters;
//..Debug
//..System.out.println("..ML.. URL STRING : "+urlString);
URL url = new URL(urlString);
InputStream is = null;
//..Connection failed
try{
//Trace.message("Checking for updates");
is = (InputStream)url.getContent();
}
catch(Exception ex)
{
//Trace.message("Checking for updates failed ....\n Check your internet settings");
//..No Trace.exception line here
Trace.exit("CheckForNewUpdates.run");
return;
}
BufferedReader reader = new BufferedReader( new InputStreamReader(is));
String tempString = "";
String fullString = "";
while((tempString = reader.readLine())!=null)
{
fullString += tempString;
}
reader.close();
StringTokenizer st = new StringTokenizer(fullString,";");
String pair = "";
String name = "";
String value = "";
paramsHashtable = new Hashtable();
while(st.hasMoreTokens())
{
pair = st.nextToken();
if(pair.equalsIgnoreCase("ok"))
{
//..set ut to 0
TailMDI.ut = 0;
break;
}
name = pair.substring(0,pair.indexOf("="));
value = pair.substring(pair.indexOf("=")+1);
paramsHashtable.put(name,value);
}
//..Show message if new version is available
if(paramsHashtable.containsKey("msg"))
{
JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new HTMLEditorKit());
String html = " <body bgcolor=\"#CBD9FA\" leftmargin=\"15\" > "+
"<p align=\"center\"><font face=\"Verdana\" size=\"3\" >"+paramsHashtable.get("msg")+"</font></p>"+
"<p align=\"center\"><font face=\"Verdana\" size=\"3\" ><a href=\""+ paramsHashtable.get("link") +"\">"+ paramsHashtable.get("link") +"</a></font></p>"+
"<p align=\"center\"> </p>"+
"</body>";
editorPane.setText(html);
editorPane.setEditable(false);
editorPane.addHyperlinkListener(new HyperActive());
JOptionPane.showMessageDialog(parentComponent, editorPane, "MakeLogic Tail", JOptionPane.INFORMATION_MESSAGE);
}
//..New UID
if(paramsHashtable.containsKey("newuid"))
{
//..Write the new uid into properties file
//..Find the uid from the properties
//..Find it in the properties and update to new value
int maxValue = getMaxValue(Tail.tailMDI.keySetValues);
int i = 1;
for(i = 1 ; i < maxValue+1; i++)
{
try
{
tempString = Tail.tailMDI.keySetValues.getProperty(""+i);
//..Verify if uid present or not
if(tempString.startsWith("uid"))
{
Tail.tailMDI.keySetValues.setProperty(""+i,"uid="+paramsHashtable.get("newuid").toString());
break;
}
}
catch(Exception exp)
{
//..Exception thrown when the property value does not exists
//..Do Nothing
Trace.exception(exp);
}
}
//..If not found add a new entry
if(i >= maxValue + 1)
{
Tail.tailMDI.keySetValues.setProperty(""+(maxValue+1),"uid="+paramsHashtable.get("newuid").toString());
}
//..Store the Properties into a file.
try
{
Tail.tailMDI.keySetValues.store(new FileOutputStream(TailMDI.KEYSET_FILE),null);
}
catch(Exception ex)
{
Trace.exception(ex);
}
}
}
catch(Exception excp)
{
//..Debug
//..System.out.println("..ML.. 2." +excp.toString() );
//..excp.printStackTrace();
Trace.exception(excp);
}
Trace.exit("CheckForNewUpdates.run");
}
//..Gets the maximum value in the properties
public int getMaxValue(Properties keySetValues)
{
Trace.enter("CheckForNewUpdates.getMaxValue");
int maxValue = 0;
int verifyUpto = keySetValues.size()+1;
for(int i = 1 ; i < verifyUpto; i++)
{
try
{
String tempString = keySetValues.getProperty(""+i);
if(tempString == null)
{
verifyUpto++;
continue;
}
//..Set the maxValue
if(i > maxValue)
{
maxValue = i;
}
}
catch(Exception exp)
{
//..Exception thrown when the property value does not exists
verifyUpto++;
Trace.exception(exp);
}
}
Trace.exit("CheckForNewUpdates.getMaxValue");
return maxValue;
}
public static void main(String[] args)
{
Trace.enter("CheckForNewUpdates.main");
CheckForNewUpdates c = new CheckForNewUpdates(null);
Trace.exit("CheckForNewUpdates.main");
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Founder of MakeLogic - A Mobile Solutions and XML Web Services Company. B-Tech engineer from India's reputed IITs.
Designed and Authored products like MicroGraphs, MakeLogic VersionManager and MakeLogic Device Broker. Pls see http://www.makelogic.com
MakeLogic is a strategic business partner of Microsoft, Sun, IBM, HP and Citrix.
Contact : madanuuk@makelogic.com OR +91 - 40 - 55322433