Exemple #1
0
  public String get_settings_array() {

    String jsontext = new String("");

    try {

      JSONObject obj = new JSONObject();

      for (int loop = 0; loop < network.settingsx.length; loop++) { // ******

        obj.put(loop, network.settingsx[loop]);
      } // *****************************************************************

      StringWriter out = new StringWriter();
      obj.writeJSONString(out);
      jsontext = out.toString();
      System.out.println(jsonText);

    } catch (Exception e) {
      e.printStackTrace();
      statex = "0";
      jsontext = "error";
    }

    return jsontext;
  } // ******************************
Exemple #2
0
 private String getFileText(File file) throws Exception {
   BufferedReader br =
       new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
   StringWriter sw = new StringWriter();
   int n;
   char[] cbuf = new char[1024];
   while ((n = br.read(cbuf, 0, cbuf.length)) != -1) sw.write(cbuf, 0, n);
   br.close();
   return sw.toString();
 }
Exemple #3
0
    @Override
    protected Transferable createTransferable(JComponent c) {
      JTextPane aTextPane = (JTextPane) c;

      SikuliEditorKit kit = ((SikuliEditorKit) aTextPane.getEditorKit());
      Document doc = aTextPane.getDocument();
      int sel_start = aTextPane.getSelectionStart();
      int sel_end = aTextPane.getSelectionEnd();

      StringWriter writer = new StringWriter();
      try {
        _copiedImgs.clear();
        kit.write(writer, doc, sel_start, sel_end - sel_start, _copiedImgs);
        return new StringSelection(writer.toString());
      } catch (Exception e) {
        Debug.error(me + "createTransferable: Problem creating text to copy\n%s", e.getMessage());
      }
      return null;
    }
  private void dumpData(BeanTableSorted from) {
    Variable v = getCurrentVariable(from);
    if (v == null) return;

    dumpPane.clear();
    String spec;

    try {
      spec = ParsedSectionSpec.makeSectionSpecString(v, null);
      dumpPane.setContext(ds, spec);

    } catch (Exception ex) {
      StringWriter s = new StringWriter();
      ex.printStackTrace(new PrintWriter(s));
      dumpPane.setText(s.toString());
    }

    dumpWindow.show();
  }
Exemple #5
0
  public String get_status() {

    String jsontext = new String("");

    try {

      JSONObject obj = new JSONObject();

      obj.put("version", network.versionx);
      obj.put("status", "active");
      obj.put("program_status", network.programst);
      obj.put("listing_size", network.listing_size);
      obj.put("buffer_size", network.send_buffer_size);
      obj.put("mining_status", network.mining_status);
      obj.put("key", network.base58_id);
      obj.put("tor_active", Integer.toString(network.tor_active));
      obj.put("last_block", network.last_block_id);
      obj.put("last_block_timestamp", network.last_block_timestamp);
      obj.put("last_block_hash", network.last_block_idx);
      obj.put("difficulty", Long.toString(network.difficultyx));
      obj.put("last_mining_id", network.last_block_mining_idx);
      obj.put("prev_mining_id", network.prev_block_mining_idx);
      obj.put("blocktimesx", network.blocktimesx);
      obj.put("my_token_total", Integer.toString(network.database_listings_owner));
      obj.put("last_block_time", network.last_block_time);
      obj.put("database_listings_total", network.database_listings_total);
      obj.put("database_unconfirmed_total", network.database_unconfirmed_total);

      StringWriter out = new StringWriter();
      obj.writeJSONString(out);
      jsontext = out.toString();
      // System.out.println(jsonText);

    } catch (Exception e) {
      e.printStackTrace();
      statex = "0";
      jsontext = "error";
    }

    return jsontext;
  } // ***************************************
  // Set exception string with current exception content.
  protected void setExceptionString(Throwable eThrowable) {
    // Initialize a StringWriter.
    eStringWriter = new StringWriter();

    // Initialize a PrintWriter.
    ePrintWriter = new PrintWriter(eStringWriter);

    // Pass contents from Throwable object to a StringWriter object.
    eThrowable.printStackTrace(ePrintWriter);

    // Assign String from StringWriter.
    eString = new String(eStringWriter.toString());
  } // End of setExceptionString() method.
Exemple #7
0
    public void
        run() { // ************************************************************************************

      String jsonText2 = new String("");

      JSONObject obj_out = new JSONObject();

      ServerSocket welcomeSocket;

      while (true) {

        try { // *********************************************************

          welcomeSocket = new ServerSocket(network.api_port, 0, InetAddress.getByName("localhost"));
          Socket connectionSocket = welcomeSocket.accept();
          BufferedReader inFromClient =
              new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
          DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
          clientSentence = inFromClient.readLine();

          JSONParser parser = new JSONParser();

          try { // *********************************************************

            statex = "0";
            responsex = "e00";
            jsonText = "";

            if (!clientSentence.contains("")) {
              throw new EmptyStackException();
            }
            Object obj = parser.parse(clientSentence);

            jsonObject = (JSONObject) obj;

            String request = (String) jsonObject.get("request");

            String item_id = new String("");
            String item_array = new String("");
            String old_key = new String("");
            String node = new String("");
            try {
              item_id = (String) jsonObject.get("item_id").toString();
            } catch (Exception e) {
              System.out.println("extra info no item_id...");
            }
            try {
              item_array = (String) jsonObject.get("item_array").toString();
            } catch (Exception e) {
              System.out.println("extra info no item_array...");
            }
            try {
              old_key = (String) jsonObject.get("key").toString();
            } catch (Exception e) {
              System.out.println("extra info no key...");
            }
            try {
              node = (String) jsonObject.get("node").toString();
            } catch (Exception e) {
              System.out.println("extra info no node...");
            }

            while (network.database_in_use == 1 && !request.equals("status")) {

              System.out.println("Database in use...");
              try {
                Thread.sleep(1000);
              } catch (InterruptedException e) {
              }
            } // **************************************************************

            if (request.equals("status")) {
              statex = "1";
              responsex = get_status();
            } // ***************************
            else if (request.equals("get_version")) {
              statex = "1";
              responsex = network.versionx;
            } //
            else if (request.equals("get_tor_active")) {
              statex = "1";
              responsex = Integer.toString(network.tor_active);
            } //
            else if (request.equals("get_last_block")) {
              statex = "1";
              responsex = network.last_block_id;
            } //
            else if (request.equals("get_last_block_timestamp")) {
              statex = "1";
              responsex = network.last_block_timestamp;
            } //
            else if (request.equals("get_last_block_hash")) {
              statex = "1";
              responsex = network.last_block_idx;
            } //
            else if (request.equals("get_difficulty")) {
              statex = "1";
              responsex = Long.toString(network.difficultyx);
            } //
            else if (request.equals("get_last_mining_id")) {
              statex = "1";
              responsex = network.last_block_mining_idx;
            } //
            else if (request.equals("get_prev_mining_id")) {
              statex = "1";
              responsex = network.prev_block_mining_idx;
            } //
            else if (request.equals("get_last_unconfirmed_id")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_my_token_total")) {
              statex = "1";
              responsex = Integer.toString(network.database_listings_owner);
            } //
            else if (request.equals("get_my_id_list")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_my_ids_limit")) {
              statex = "1";
              responsex = get_item_ids();
            } //
            else if (request.equals("get_token")) {
              statex = "1";
              responsex = get_item_array(item_id);
            } //
            else if (request.equals("get_settings")) {
              statex = "1";
              responsex = get_settings_array();
            } //
            else if (request.equals("get_mining_info")) {
              statex = "1";
              responsex = get_item_array(item_id);
            } //
            else if (request.equals("get_new_keys")) {
              statex = "1";
              responsex = build_keysx();
            } //
            else if (request.equals("delete_node")) {
              statex = "1";
              responsex = delete_node(node);
            } //
            else if (request.equals("delete_all_nodes")) {
              statex = "1";
              responsex = delete_all_nodes();
            } //
            else if (request.equals("set_new_node")) {
              statex = "1";
              responsex = set_new_node(node);
            } //
            else if (request.equals("set_old_key")) {
              statex = "1";
              responsex = set_old_key(old_key);
            } //
            else if (request.equals("set_new_block")) {
              statex = "1";
              responsex = set_new_block(item_array);
            } //
            else if (request.equals("set_edit_block")) {
              statex = "1";
              update_state = "set_edit_block";
              responsex = update_token(item_array);
            } //
            else if (request.equals("set_transfer_block")) {
              statex = "1";
              update_state = "set_transfer_block";
              responsex = update_token(item_array);
            } //
            else if (request.equals("system_restart")) {
              statex = "1";
              responsex = "restarting";
              toolkit = Toolkit.getDefaultToolkit();
              xtimerx = new Timer();
              xtimerx.schedule(new RemindTask_restart(), 0);
            } //
            else if (request.equals("system_exit")) {
              statex = "1";
              System.exit(0);
            } //
            else {
              statex = "0";
              responsex = "e01 UnknownRequestException";
            }

          } // try
          catch (ParseException e) {
            e.printStackTrace();
            statex = "0";
            responsex = "e02 ParseException";
          } catch (Exception e) {
            e.printStackTrace();
            statex = "0";
            responsex = "e03 Exception";
          }

          JSONObject obj = new JSONObject();
          obj.put("response", statex);
          try {
            obj.put("message", responsex);
          } catch (Exception e) {
            e.printStackTrace();
          }

          StringWriter outs = new StringWriter();
          obj.writeJSONString(outs);
          jsonText = outs.toString();
          System.out.println("SEND RESPONSE " + responsex);

          outToClient.writeBytes(jsonText + '\n');
          welcomeSocket.close();

        } catch (Exception e) {
          e.printStackTrace();
          System.out.println("Server ERROR x3");
        }
      } // **********while
    } // runx***************************************************************************************************
Exemple #8
0
  public String get_item_array(String id) {

    String jsonarry;

    try {

      krypton_database_get_token getxt = new krypton_database_get_token();

      String token_array[] = new String[network.listing_size];
      token_array = getxt.get_token(id);

      JSONObject obj = new JSONObject();

      obj.put("id", token_array[0]);
      obj.put("hash_id", token_array[1]);
      obj.put("sig_id", token_array[2]);
      obj.put("date_id", token_array[3]);
      obj.put("owner_id", token_array[4]);
      obj.put("owner_rating", token_array[5]);
      obj.put("currency", token_array[6]);
      obj.put("custom_template", token_array[7]);
      obj.put("custom_1", token_array[8]);
      obj.put("custom_2", token_array[9]);
      obj.put("custom_3", token_array[10]);
      obj.put("item_errors", token_array[11]);
      obj.put("item_date_listed", token_array[12]);
      obj.put("item_date_listed_day", token_array[13]);
      obj.put("item_date_listed_int", token_array[14]);
      obj.put("item_hits", token_array[15]);
      obj.put("item_confirm_code", token_array[16]);
      obj.put("item_confirmed", token_array[17]);
      obj.put("item_cost", token_array[18]);
      obj.put("item_description", token_array[19]);
      obj.put("item_id", token_array[20]);
      obj.put("item_price", token_array[21]);
      obj.put("item_weight", token_array[22]);
      obj.put("item_listing_id", token_array[23]);
      obj.put("item_notes", token_array[24]);
      obj.put("item_package_d", token_array[25]);
      obj.put("item_package_l", token_array[26]);
      obj.put("item_package_w", token_array[27]);
      obj.put("item_part_number", token_array[28]);
      obj.put("item_title", token_array[29]);
      obj.put("item_title_url", token_array[30]);
      obj.put("item_type", token_array[31]);
      obj.put("item_search_1", token_array[32]);
      obj.put("item_search_2", token_array[33]);
      obj.put("item_search_3", token_array[34]);
      obj.put("item_site_id", token_array[35]);
      obj.put("item_site_url", token_array[36]);
      obj.put("item_picture_1", token_array[37]);
      obj.put("item_total_on_hand", token_array[38]);
      obj.put("sale_payment_address", token_array[39]);
      obj.put("sale_payment_type", token_array[40]);
      obj.put("sale_fees", token_array[41]);
      obj.put("sale_id", token_array[42]);
      obj.put("sale_seller_id", token_array[43]);
      obj.put("sale_status", token_array[44]);
      obj.put("sale_tax", token_array[45]);
      obj.put("sale_shipping_company", token_array[46]);
      obj.put("sale_shipping_in", token_array[47]);
      obj.put("sale_shipping_out", token_array[48]);
      obj.put("sale_source_of_sale", token_array[49]);
      obj.put("sale_total_sale_amount", token_array[50]);
      obj.put("sale_tracking_number", token_array[51]);
      obj.put("sale_transaction_id", token_array[52]);
      obj.put("sale_transaction_info", token_array[53]);
      obj.put("seller_address_1", token_array[54]);
      obj.put("seller_address_2", token_array[55]);
      obj.put("seller_address_city", token_array[56]);
      obj.put("seller_address_state", token_array[57]);
      obj.put("seller_address_zip", token_array[58]);
      obj.put("seller_address_country", token_array[59]);
      obj.put("seller_id", token_array[60]);
      obj.put("seller_ip", token_array[61]);
      obj.put("seller_email", token_array[62]);
      obj.put("seller_first_name", token_array[63]);
      obj.put("seller_last_name", token_array[64]);
      obj.put("seller_notes", token_array[65]);
      obj.put("seller_phone", token_array[66]);
      obj.put("seller_logo", token_array[67]);
      obj.put("seller_url", token_array[68]);

      StringWriter out = new StringWriter();
      obj.writeJSONString(out);
      String jsonText = out.toString();
      System.out.println(jsonText);

      jsonarry = JSONValue.toJSONString(obj);

    } catch (Exception e) {

      e.printStackTrace();
      statex = "0";
      jsonarry = "Error";
    } // *****************

    return jsonarry;
  } // *************************************
Exemple #9
0
 public UServerManager() {
   try {
     ULogoWindow logow = new ULogoWindow();
     logow.setVisible(true);
     Thread.sleep(2500);
     logow.dispose();
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   fParam.setConnectionType(UParameters.CONNECTION_TYPE_NETWORK);
   fParamDialog = new UServerManagerParamDialog();
   fParamDialog.setLocationRelativeTo((Frame) null);
   fParamDialog.setVisible(true);
   if (!fParamDialog.getStatus()) {
     System.exit(0);
     // 以下の部分はサーバの初期化による出力を拾えないための方策.
     // 非常にまずいが仕方ない.標準出力タブは必ず入れる.
   }
   System.setOut(UParameters.fPrintStream);
   fUpdateTimer = new javax.swing.Timer(fInterval * 1000, this);
   fUpdateTimer.setInitialDelay(0);
   fServer =
       new UMartNetwork(
           fParam.getMemberLog(),
           fParam.getPriceInfoDB(),
           fParam.getStartPoint(),
           fParam.getSeed(),
           fParam.getDays(),
           fParam.getBoardPerDay(),
           fParamNet.getPort());
   if (fParam.isLogCreate()) {
     try {
       fServer.initLog();
     } catch (IOException ioex) {
       JOptionPane.showMessageDialog(
           null,
           fRb.getString("ERROR_CANNOT_CREATE_LOGS"),
           fRb.getString("ERROR_DIALOG_TITLE"),
           JOptionPane.ERROR_MESSAGE);
       System.exit(5);
     } catch (Exception ex) {
       StringWriter sw = new StringWriter();
       PrintWriter pw = new PrintWriter(sw);
       ex.printStackTrace(pw);
       JOptionPane.showMessageDialog(
           null,
           fRb.getString("ERROR_FATAL") + "\n" + sw.toString(),
           fRb.getString("ERROR_DIALOG_TITLE"),
           JOptionPane.ERROR_MESSAGE);
       System.exit(5);
     }
   }
   fServer.startLoginManager();
   initAgents(fParam.getMachineAgentArray());
   fGui = new UServerManagerMainWindow(this, fParam.getTabs());
   fParam.setMainComponet(fGui);
   fGui.setTimer(fUpdateTimer);
   fGui.mainImpl();
   ActionListener guiUpdater =
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           fGui.gUpdate();
         }
       };
   fGuiUpdateTimer = new javax.swing.Timer(TIMER_INTERVAL * 1000, guiUpdater);
   fGuiUpdateTimer.start();
   // 1日目の1回目の注文期間に進めておく
   fUpdateTimer.setRepeats(false);
   fUpdateTimer.start();
 }