コード例 #1
0
ファイル: AgentLogger.java プロジェクト: JvJ/Fatima
  public void initialize(String logName, boolean debugMode) throws IOException {

    if (VersionChecker.runningOnAndroid())
      outFile =
          new BufferedWriter(
              new FileWriter(ConfigurationManager.getMindPath() + logName + "-Log.txt"));
    else
      outFile =
          new BufferedWriter(
              new FileWriter(ConfigurationManager.getMindPath() + logName + "-log.txt"));

    this._debugMode = debugMode;
    this._initialized = true;
  }
コード例 #2
0
ファイル: UpdateReader.java プロジェクト: bl0c/BeardStat
  public boolean checkUpdate() {
    try {
      // load config
      YamlConfiguration config = YamlConfiguration.loadConfiguration((new URL(url)).openStream());
      log.info("Parsing update file");

      String updateSiteName = config.getString("name", "[]");
      log.info("Reading updates from " + updateSiteName);

      ConfigurationSection updatePage =
          config.getConfigurationSection("plugin." + plugin.getDescription().getName());
      if (updatePage == null) {
        log.info("Update file does not have information on our plugin");
        return false;
      }
      String newVersion = updatePage.getString("version", plugin.getDescription().getVersion());
      checker.checkVersion(plugin.getDescription().getVersion(), newVersion);
    } catch (MalformedURLException e) {
      log.severe("Update URL specified could not be understood");
    } catch (IOException e) {
      log.severe("An I/O error occured while trying to read the update");
    }
    return false;
  }
コード例 #3
0
  public boolean initialize(String[] args) {
    if (m_initialized) {
      return false;
    }

    if (args != null && args.length > 0 && args[0] != null) {
      String temp = args[0].trim();
      if (temp.length() > 0) {
        settings.settingsFileName = temp;
      }
    }

    if (settings.load()) {
      console.writeLine("Settings successfully loaded from file: " + settings.settingsFileName);
    } else {
      console.writeLine("Failed to load settings from file: " + settings.settingsFileName);

      if (settings.settingsFileName != null
          && !SettingsManager.defaultSettingsFileName.equalsIgnoreCase(settings.settingsFileName)) {
        boolean loaded = false;

        while (!loaded) {
          int choice =
              JOptionPane.showConfirmDialog(
                  null,
                  "Unable to load settings from custom settings file. Use alternate settings file?\nNote that when the program is closed, this settings file will be generated if it does not exist.",
                  "Settings Loading Failed",
                  JOptionPane.YES_NO_CANCEL_OPTION);
          if (choice == JOptionPane.YES_OPTION) {
            String newSettingsFileName =
                JOptionPane.showInputDialog(
                    null, "Enter a settings file name:", SettingsManager.defaultSettingsFileName);
            if (newSettingsFileName != null) {
              settings.settingsFileName = newSettingsFileName;
              loaded = settings.load();

              if (loaded) {
                console.writeLine(
                    "Settings successfully loaded from file: " + settings.settingsFileName);
              }
            } else {
              break;
            }
          } else {
            break;
          }
        }
      }
    }

    if (!pluginManager.initialize(paletteEditorWindow.getFrame())) {
      JOptionPane.showMessageDialog(
          paletteEditorWindow.getFrame(),
          "Failed to initialize plugin manager!",
          "Initialization Failed",
          JOptionPane.ERROR_MESSAGE);

      return false;
    }

    if (settings.autoLoadPlugins) {
      pluginManager.loadPlugins();
    }

    m_initialized = true;

    boolean error = false;

    console.addTarget(paletteEditorWindow);

    if (!paletteEditorWindow.initialize()) {
      JOptionPane.showMessageDialog(
          paletteEditorWindow.getFrame(),
          "Failed to initialize palette editor window!",
          "Palette Editor Init Failed",
          JOptionPane.ERROR_MESSAGE);

      return false;
    }

    if (!error) {
      console.writeLine("Palette Editor initialized successfully!");
    }

    VersionChecker.checkVersion(false);

    return true;
  }
コード例 #4
0
ファイル: Util.java プロジェクト: OpenRoberta/robertalab
public class Util {
  private static final Logger LOG = LoggerFactory.getLogger(Util.class);
  private static final String openRobertaVersion =
      VersionChecker.retrieveVersionOfOpenRobertaServer();

  private Util() {
    // no objects
  }

  public static void addResultInfo(JSONObject response, AbstractProcessor processor)
      throws JSONException {
    String realKey = processor.getMessage().getKey();
    response.put("rc", processor.getRC());
    response.put("message", realKey);
    response.put("cause", realKey);
    response.put(
        "parameter",
        processor.getParameter()); // if getParameters returns null, nothing bad happens :-)
  }

  public static JSONObject addSuccessInfo(JSONObject response, Key key) throws JSONException {
    Util.addResultInfo(response, "ok", key);
    return response;
  }

  public static JSONObject addErrorInfo(JSONObject response, Key key) throws JSONException {
    Util.addResultInfo(response, "error", key);
    return response;
  }

  private static void addResultInfo(JSONObject response, String rc, Key key) throws JSONException {
    String realKey = key.getKey();
    response.put("rc", rc);
    response.put("message", realKey);
    response.put("cause", realKey);
  }

  /**
   * add information for the Javascript client to the result json, especially about the state of the
   * robot.<br>
   * This method must be <b>total</b>, i.e. must <b>never</b> throw exceptions.
   *
   * @param response the response object to enrich with data
   * @param httpSessionState needed to access the token
   * @param brickCommunicator needed to access the robot's state
   */
  public static void addFrontendInfo(
      JSONObject response, HttpSessionState httpSessionState, RobotCommunicator brickCommunicator) {
    try {
      response.put("serverTime", new Date());
      response.put("server.version", Util.openRobertaVersion);
      if (httpSessionState != null) {
        String token = httpSessionState.getToken();
        if (token != null) {
          RobotCommunicationData state = brickCommunicator.getState(token);
          if (state != null) {
            response.put("robot.wait", state.getRobotConnectionTime());
            response.put("robot.battery", state.getBattery());
            response.put("robot.name", state.getRobotName());
            response.put("robot.version", state.getMenuVersion());
            response.put("robot.firmwareName", state.getFirmwareName());
            response.put("robot.sensorvalues", state.getSensorValues());
            response.put("robot.nepoexitvalue", state.getNepoExitValue());
            State communicationState = state.getState();
            String infoAboutState;
            if (communicationState == State.ROBOT_IS_BUSY) {
              infoAboutState = "busy";
            } else if (state.isRobotProbablyDisconnected() || communicationState == State.GARBAGE) {
              infoAboutState = "disconnected";
            } else {
              infoAboutState =
                  "wait"; // is there a need to distinguish the communication state more detailed?
            }
            response.put("robot.state", infoAboutState);
          }
        }
      }
    } catch (Exception e) {
      Util.LOG.error(
          "when adding info for the client, an unexpected exception occurred. Some info for the client may be missing",
          e);
    }
  }
}