/*
 * UbdateSearch.java
 *
 * Created on 22 maggio 2005, 2.00
 */

package it.businesslogic.ireport.plugin.checkupdate;

import java.net.URLConnection;

/**
 *
 * @author  Administrator
 */
public class UpgradeSearch implements Runnable {
    
    private CheckUpdateDialog win = null;
    public void run() {
        try {
            Thread.currentThread().setContextClassLoader(it.businesslogic.ireport.gui.MainFrame.getMainInstance().getReportClassLoader() );
                        
            java.net.URL url = new java.net.URL("http://ireport.sf.net/lastversion.php");
            byte[] webBuffer = new byte[100];
            URLConnection uConn = url.openConnection();
            //uConn.setReadTimeout(1000);
            java.io.InputStream is = uConn.getInputStream();
            int readed = is.read(webBuffer);
            String version = new String(webBuffer,0,readed);
            if (version.toLowerCase().startsWith("ireport")) {
                if (version.compareTo(it.businesslogic.ireport.gui.MainFrame.constTitle) > 0) {
                    javax.swing.JOptionPane.showMessageDialog(it.businesslogic.ireport.gui.MainFrame.getMainInstance(),version +" is available on http://ireport.sf.net!");
                }
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
        
        if (win != null)   win.setVisible(false);
    }

    public CheckUpdateDialog getWin() {
        return win;
    }

    public void setWin(CheckUpdateDialog win) {
        this.win = win;
    }
}

