Exemplo n.º 1
0
  public boolean restartApplicationWithScript() {
    String command = null;
    try {
      if (Spark.isWindows()) {
        String sparkExe =
            getCommandPath() + File.separator + Default.getString(Default.SHORT_NAME) + ".exe";
        if (!new File(sparkExe).exists()) {
          Log.warning("Client EXE file does not exist");
          return false;
        }
        String starterExe = getCommandPath() + File.separator + "starter.exe";
        if (!new File(starterExe).exists()) {
          Log.warning("Starter EXE file does not exist");
          return false;
        }
        command = starterExe + " \"" + sparkExe + "\"";
      } else if (Spark.isLinux()) {
        command = getCommandPath() + File.separator + Default.getString(Default.SHORT_NAME);
        if (!new File(command).exists()) {
          Log.warning("Client startup script does not exist");
          return false;
        }
      } else if (Spark.isMac()) {
        command = "open -a " + Default.getString(Default.SHORT_NAME);
      }

      Runtime.getRuntime().exec(command);
      System.exit(0);
      return true;
    } catch (IOException e) {
      Log.error("Error trying to restart application with script", e);
      return false;
    }
  }
Exemplo n.º 2
0
  /**
   * Checks for the latest update on the server.
   *
   * @param forced true if you want to bypass the normal checking security.
   */
  private void checkForUpdates(final boolean forced) {
    final CheckUpdates updater = new CheckUpdates();
    try {
      final SwingWorker updateThread =
          new SwingWorker() {
            public Object construct() {
              try {
                Thread.sleep(50);
              } catch (InterruptedException e) {
                Log.error(e);
              }
              return "ok";
            }

            public void finished() {
              try {
                updater.checkForUpdate(forced);
              } catch (Exception e) {
                Log.error("There was an error while checking for a new update.", e);
              }
            }
          };

      updateThread.start();

    } catch (Exception e) {
      Log.warning("Error updating.", e);
    }
  }
Exemplo n.º 3
0
  public void removePrivacyList(String listName) {
    try {
      privacyManager.deletePrivacyList(listName);

      _privacyLists.remove(getPrivacyList(listName));
    } catch (XMPPException e) {
      Log.warning("Could not remove PrivacyList " + listName);
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  private static String useGoogleTranslator(String text, TranslationType type) {

    String response = "";
    String urlString =
        "http://translate.google.com/translate_t?text=" + text + "&langpair=" + type.getID();
    // disable scripting to avoid requiring js.jar
    HttpUnitOptions.setScriptingEnabled(false);

    // create the conversation object which will maintain state for us
    WebConversation wc = new WebConversation();

    // Obtain the google translation page
    WebRequest webRequest = new GetMethodWebRequest(urlString);
    // required to prevent a 403 forbidden error from google
    webRequest.setHeaderField("User-agent", "Mozilla/4.0");

    try {
      WebResponse webResponse = wc.getResponse(webRequest);
      // NodeList list = webResponse.getDOM().getDocumentElement().getElementsByTagName("div");
      try {
        NodeList list2 =
            XPathAPI.selectNodeList(webResponse.getDOM(), "//span[@id='result_box']/span/text()");

        for (int i = 0; i < list2.getLength(); ++i) {
          response = response + list2.item(i).getNodeValue() + " ";
        }

      } catch (TransformerException e) {
        Log.warning("Translator error", e);
      }

      //            int length = list.getLength();
      //            for (int i = 0; i < length; i++) {
      //                Element element = (Element)list.item(i);
      //                if ("result_box".equals(element.getAttribute("id"))) {
      //                    Node translation = element.getFirstChild();
      //                    if (translation != null) {
      //                        response = translation.getNodeValue();
      //                    }
      //                }
      //            }
    } catch (MalformedURLException e) {
      Log.error("Could not for url: " + e);
    } catch (IOException e) {
      Log.error("Could not get response: " + e);
    } catch (SAXException e) {
      Log.error("Could not parse response content: " + e);
    }

    return response;
  }
Exemplo n.º 5
0
 public void declineDefaultList() {
   try {
     if (hasDefaultList()) {
       privacyManager.declineDefaultList();
       fireListRemovedAsDefault(getDefaultList().getListName());
       for (SparkPrivacyList plist : _privacyLists) {
         plist.setListIsDefault(false);
       }
     }
   } catch (XMPPException e) {
     Log.warning("Could not decline default privacy list");
     e.printStackTrace();
   }
 }
Exemplo n.º 6
0
  public void setListAsDefault(String listname) {

    try {
      privacyManager.setDefaultListName(listname);
      fireListSetAsDefault(listname);
      getPrivacyList(listname).setListIsDefault(true);
      for (SparkPrivacyList plist : _privacyLists) {
        if (!plist.getListName().equals(listname)) plist.setListIsDefault(false);
      }
    } catch (XMPPException e) {
      Log.warning("Could not set PrivacyList " + listname + " as default");
      e.printStackTrace();
    }
  }
Exemplo n.º 7
0
  public void declineActiveList() {
    try {

      if (hasActiveList()) {
        privacyManager.declineActiveList();
        fireListDeActivated(getActiveList().getListName());
        _presenceHandler.removeIconsForList(getActiveList());
      }
      for (SparkPrivacyList plist : _privacyLists) {
        plist.setListAsActive(false);
      }
    } catch (XMPPException e) {
      Log.warning("Could not decline active privacy list");
      e.printStackTrace();
    }
  }
Exemplo n.º 8
0
  public void setListAsActive(String listname) {
    try {
      privacyManager.setActiveListName(listname);
      fireListActivated(listname);
      if (hasActiveList()) {
        _presenceHandler.removeIconsForList(getActiveList());
      }
      getPrivacyList(listname).setListAsActive(true);
      for (SparkPrivacyList plist : _privacyLists) {
        if (!plist.getListName().equals(listname)) plist.setListAsActive(false);
      }
      _presenceHandler.setIconsForList(getActiveList());

    } catch (XMPPException e) {
      Log.warning("Could not activate PrivacyList " + listname);
      e.printStackTrace();
    }
  }
Exemplo n.º 9
0
  public SparkPrivacyList createPrivacyList(String listName) {
    PrivacyItem item = new PrivacyItem(null, true, 999999);
    ArrayList<PrivacyItem> items = new ArrayList<PrivacyItem>();
    items.add(item);
    SparkPrivacyList sparklist = null;
    try {
      privacyManager.createPrivacyList(listName, items);
      privacyManager.getPrivacyList(listName).getItems().remove(item);
      sparklist = new SparkPrivacyList(privacyManager.getPrivacyList(listName));
      _privacyLists.add(sparklist);
      sparklist.addSparkPrivacyListener(_presenceHandler);
    } catch (XMPPException e) {
      Log.warning("Could not create PrivacyList " + listName);
      e.printStackTrace();
    }

    return sparklist;
  }