001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * UpgradeSearch.java
028: *
029: * Created on 22 maggio 2005, 2.00
030: *
031: */
032:
033: package it.businesslogic.ireport.plugin.checkupdate;
034:
035: import it.businesslogic.ireport.gui.MainFrame;
036: import it.businesslogic.ireport.util.I18n;
037: import java.net.Proxy;
038: import java.net.URLConnection;
039:
040: /**
041: *
042: * @author Administrator
043: */
044: public class UpgradeSearch implements Runnable {
045:
046: private CheckUpdateDialog win = null;
047:
048: public void run() {
049: try {
050: //Thread.currentThread().setContextClassLoader(it.businesslogic.ireport.gui.MainFrame.getMainInstance().getReportClassLoader() );
051:
052: java.util.Properties props = it.businesslogic.ireport.gui.MainFrame
053: .getMainInstance().getProperties();
054:
055: if (props.getProperty("update.useProxy", "false").equals(
056: "true")) {
057: System.getProperties().put("proxySet", "true");
058:
059: String urlProxy = props.getProperty("update.proxyUrl",
060: "");
061: String port = "8080";
062: String server = urlProxy;
063: if (urlProxy.indexOf(":") > 0) {
064: port = urlProxy
065: .substring(urlProxy.indexOf(":") + 1);
066: server = urlProxy.substring(0, urlProxy
067: .indexOf(":"));
068: }
069:
070: System.getProperties().put("proxyHost", server);
071: System.getProperties().put("proxyPort", port);
072:
073: MainFrame.getMainInstance().logOnConsole(
074: "Using proxy: " + urlProxy);
075:
076: }
077:
078: java.net.URL url = new java.net.URL(
079: "http://ireport.sf.net/lastversion.php");
080:
081: byte[] webBuffer = new byte[100];
082: URLConnection uConn = url.openConnection();
083:
084: if (props.getProperty("update.useProxy", "false").equals(
085: "true")
086: && props.getProperty("update.useAuth", "false")
087: .equals("true")) {
088: String password = props.getProperty("update.username",
089: "")
090: + ":"
091: + props.getProperty("update.password", "");
092:
093: org.w3c.tools.codec.Base64Encoder b = new org.w3c.tools.codec.Base64Encoder(
094: password);
095: String encodedPassword = b.processString();
096: uConn.setRequestProperty("Proxy-Authorization",
097: encodedPassword);
098: }
099:
100: //uConn.setReadTimeout(1000);
101: java.io.InputStream is = uConn.getInputStream();
102: int readed = is.read(webBuffer);
103: String version = new String(webBuffer, 0, readed);
104: if (version.toLowerCase().startsWith("ireport")) {
105: if (version
106: .compareTo(it.businesslogic.ireport.gui.MainFrame.constTitle) > 0) {
107:
108: final String fversion = version;
109: javax.swing.SwingUtilities
110: .invokeLater(new Runnable() {
111: public void run() {
112: javax.swing.JOptionPane
113: .showMessageDialog(
114: it.businesslogic.ireport.gui.MainFrame
115: .getMainInstance(),
116: I18n
117: .getFormattedString(
118: "messages.upgradeSearch.newVersion",
119: "{0} is available on http://ireport.sf.net!",
120: new Object[] { fversion }));
121: }
122: });
123: }
124: }
125: } catch (Throwable ex) {
126: ex.printStackTrace();
127: }
128:
129: if (win != null)
130: win.setVisible(false);
131: }
132:
133: public CheckUpdateDialog getWin() {
134: return win;
135: }
136:
137: public void setWin(CheckUpdateDialog win) {
138: this.win = win;
139: }
140: }
|