Exemplo n.º 1
0
  private void checkUpdate()
      throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
    String url;
    try {
      url = Registry.getProperty("updater.url");
    } catch (Exception e) {
      throw new IOException(e.getMessage()); // i hate leaking "exception"
    }
    HttpClient client = new HttpClient();

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("version", Build.getVersion());
    params.put("release", "" + Build.getRelease());
    if (PreferencesManager.getVersionIndependentPreferences()
        .getBoolean("updater.include.usageData", true)) {
      params.put("uuid", Application.getUUID());
      params.put("platform.arch", Platform.getArch());
      params.put("platform.os", Platform.getOS().getCanonicalName());
      params.put("platform.os.version", Platform.getOS().getVersion());
      params.put("locale.country", LanguageBundle.getCurrentLocale().getCountry());
      params.put("locale.language", LanguageBundle.getCurrentLocale().getLanguage());
    }

    List<NameValuePair> nvp = new ArrayList<NameValuePair>();
    for (String key : params.keySet()) nvp.add(new NameValuePair(key, "" + params.get(key)));

    GetMethod request = new GetMethod(url);
    request.setQueryString(nvp.toArray(new NameValuePair[nvp.size()]));
    LogFactory.getLog(getClass()).info(String.format("Checking for updates: %s", request.getURI()));
    client.executeMethod(request);
    String response = request.getResponseBodyAsString();
    Document doc = DomUtil.parseXMLString(response);
    availableRelease = XPathHelper.xpathAsDouble(doc, "/korsakow/release");
    availableVersion = XPathHelper.xpathAsString(doc, "/korsakow/version");
    message = XPathHelper.xpathAsString(doc, "/korsakow/message");
  }
Exemplo n.º 2
0
 @Override
 public void run() {
   try {
     checkUpdate();
   } catch (IOException e) {
     // we don't notify on IO errors because a common case is when you're using the software
     // without a connection or the site is
     // down or something, don't bug the user about it.
     // other errors like in the format of the XML are exception circumstance.
     Logger.getLogger(Updater.class).error(e);
   } catch (Exception e) {
     UIUtil.runUITaskNow(new ErrorAction(LanguageBundle.getString("updater.error.title"), e));
   }
   if (availableRelease > Build.getRelease()) {
     UIUtil.runUITaskNow(
         new AlertAction(
             LanguageBundle.getString("updater.newversion.title"),
             LanguageBundle.getString("updater.newversion.message", availableVersion, message)));
   }
 }