示例#1
0
  public static void upload(List<ArgumentWrapper> argsArray, Session currentSession) {
    // Get path from arguments
    String path = Common.getParamString(argsArray, "path");
    byte[] data = Common.getParam(argsArray, "data");

    File file = new File(path);
    BufferedOutputStream out = null;

    try {
      out = new BufferedOutputStream(new FileOutputStream(file, true));
      out.write(data);

      currentSession.sendFullTransmission("", "");

    } catch (Exception e) {
      currentSession.sendFullTransmission("", e.getMessage());
    } finally {
      // Close file
      if (out != null) {
        try {
          out.close();
        } catch (Exception e) {
        }
      }
    }
  }
示例#2
0
  private void send_client_DH_inner_data(long retry_id) {
    byte[] b_data = new byte[256];
    Common.random.nextBytes(b_data);

    BigInteger b = new BigInteger(1, b_data);
    BigInteger g_b = g.modPow(b, dh_prime);
    Common.logError(
        "g_b length: " + g_b.toByteArray().length + " -> " + Common.toBytes(g_b).length);

    BigInteger akey = g_a.modPow(b, dh_prime);
    Common.logError("auth_key: " + akey.toString());
    setAuthKey(Common.toBytes(akey));

    // gen data (client_DH_inner_data)
    TL.Object data_obj = TL.newObject("client_DH_inner_data", cl_nonce, sv_nonce, retry_id, g_b);
    byte[] data = data_obj.serialize();
    byte[] hash = Common.getSHA1(data);

    byte[] data_with_hash = new byte[(hash.length + data.length + 15) / 16 * 16];
    System.arraycopy(hash, 0, data_with_hash, 0, hash.length);
    System.arraycopy(data, 0, data_with_hash, hash.length, data.length);

    // send set_client_DH_params
    TL.Object req_obj =
        TL.newObject("set_client_DH_params", cl_nonce, sv_nonce, aes.IGE(data_with_hash, true));
    send(req_obj, false, false);
  }
示例#3
0
  public void onAuthorized() {
    dcState.set("auth_key", auth_key);
    dcState.set("server_salt", server_salt);

    long upd_delta = (long) Common.getUnixTime() - (long) dc_date;
    if (Main.mtp == this && upd_delta > 5 * 60) api_help_getConfig();

    if (!bind && this != Main.mtp) {
      final MTProto m = this;
      Common.logError("exportAuthorization");
      Main.mtp.api(
          new TL.OnResultRPC() {
            @Override
            public void onResultRPC(TL.Object result, Object param, boolean error) {
              if (!error) return;
              if (result.id != 0xdf969c2d) return; // auth.ExportedAuthorization
              Common.logError("importAuthorization");
              m.api(
                  null,
                  null,
                  "auth.importAuthorization",
                  result.getInt("id"),
                  result.getBytes("bytes"));
            }
          },
          null,
          "auth.exportAuthorization",
          dcState.getInt("id"));
      return;
    }

    if (bind) cb.onBind();
    send_queue();
  }
示例#4
0
 /**
  * evaluate recall of blocking
  *
  * @param blockFile
  * @param stdAns
  * @throws Exception
  */
 public static void evaluate(String blockFile, String stdAns, String output) throws Exception {
   HashSet<String> stdSet = Common.getStringSet(stdAns);
   HashSet<String> resSet = new HashSet<String>();
   BufferedReader br = IOFactory.getBufferedReader(blockFile);
   int overlap = 0;
   int maxBlockSize = 0;
   int blockNum = 0;
   for (String line = br.readLine(); line != null; line = br.readLine()) {
     int[] docNums = Common.getNumsInLineSorted(line);
     if (docNums.length > maxBlockSize) maxBlockSize = docNums.length;
     //			System.out.println(docNums.length);
     blockNum++;
     for (int i = 0; i < docNums.length; i++)
       for (int j = 0; j < i; j++) {
         String toTest = docNums[i] + " " + docNums[j];
         if (stdSet.contains(toTest)) {
           overlap++;
           stdSet.remove(toTest); // to avoid duplicate counting
         }
         resSet.add(toTest);
       }
   }
   br.close();
   Common.printResult(overlap, stdAns, resSet.size(), output);
 }
示例#5
0
  private void TL_BadMsgNotification(TL.Object obj) {
    int error_code = obj.getInt("error_code");

    Message msg = TLMessage.get(obj.getLong("bad_msg_id"));
    Common.logError("bad_msg: " + error_code + " " + msg.obj.name + ":" + msg.obj.type);

    if (error_code == 16 || error_code == 17) {
      time_delta = (int) ((cur_message_id >> 32) - Common.getUnixTime());
      last_message_id = 0;
    }

    if (error_code == 32 || error_code == 33) {
      Common.logError("cur seq: " + cur_msg_seq);
      Common.logError("old seq: " + seqno);
      if (!bad_seq) {
        session = GEN_session_id();
        seqno = 0;
        send_ping();
        bad_seq = true;
      }

      // seqno = cur_msg_seq + (cur_msg_seq % 2) + 100;
      //	session = GEN_session_id();
      //	seqno = 0;
    }

    if (obj.id == 0xedab447b) { // bad_server_salt
      server_salt = obj.getLong("new_server_salt");
      dcState.set("server_salt", server_salt);
    }

    retry(obj.getLong("bad_msg_id"));
  }
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   int minutes = 60;
   String keyword = "all";
   try {
     if (request.getParameter("minutes") != null && request.getParameter("keyword") != null) {
       minutes = Integer.parseInt(request.getParameter("minutes"));
       keyword = request.getParameter("keyword");
     }
   } catch (Exception e) {
     Common.writeLog("Incorrect data from front end", e);
   }
   List<WebData> data = odb.getDataByMinutes(minutes, keyword);
   PrintWriter pr = response.getWriter();
   if (data.size() == 0) {
     pr.write("no_matching");
   } else {
     pr.write("start\n");
     for (WebData ele : data) {
       JSONObject obj = new JSONObject();
       try {
         obj.put("statusId", String.valueOf(ele.statusId));
         obj.put("longitude", String.valueOf(ele.longitude));
         obj.put("latitude", String.valueOf(ele.latitude));
         obj.put("content", ele.content);
         obj.put("keyword", ele.keyword);
       } catch (JSONException e) {
         Common.writeLog("JSON Error", e);
       }
       pr.write(obj.toString() + "\n");
     }
     pr.write("end");
   }
   pr.close();
 }
  /**
   * Append a timestamp component and a random value component to interest's name. This ensures that
   * the timestamp is greater than the timestamp used in the previous call. Then use keyChain to
   * sign the interest which appends a SignatureInfo component and a component with the signature
   * bits. If the interest lifetime is not set, this sets it.
   *
   * @param interest The interest whose name is append with components.
   * @param keyChain The KeyChain for calling sign.
   * @param certificateName The certificate name of the key to use for signing.
   * @param wireFormat A WireFormat object used to encode the SignatureInfo and to encode interest
   *     name for signing.
   */
  public void generate(
      Interest interest, KeyChain keyChain, Name certificateName, WireFormat wireFormat)
      throws SecurityException {
    double timestamp;
    synchronized (lastTimestampLock_) {
      timestamp = Math.round(Common.getNowMilliseconds());
      while (timestamp <= lastTimestamp_) timestamp += 1.0;
      // Update the timestamp now while it is locked. In the small chance that
      //   signing fails, it just means that we have bumped the timestamp.
      lastTimestamp_ = timestamp;
    }

    // The timestamp is encoded as a TLV nonNegativeInteger.
    TlvEncoder encoder = new TlvEncoder(8);
    encoder.writeNonNegativeInteger((long) timestamp);
    interest.getName().append(new Blob(encoder.getOutput(), false));

    // The random value is a TLV nonNegativeInteger too, but we know it is 8 bytes,
    //   so we don't need to call the nonNegativeInteger encoder.
    ByteBuffer randomBuffer = ByteBuffer.allocate(8);
    // Note: SecureRandom is thread safe.
    Common.getRandom().nextBytes(randomBuffer.array());
    interest.getName().append(new Blob(randomBuffer, false));

    keyChain.sign(interest, certificateName, wireFormat);

    if (interest.getInterestLifetimeMilliseconds() < 0)
      // The caller has not set the interest lifetime, so set it here.
      interest.setInterestLifetimeMilliseconds(1000.0);
  }
  /**
   * Recommendation location name that you can not enter more than 51 characters
   *
   * @throws InterruptedException
   */
  public void Recommend_Name_Max() throws InterruptedException {
    String over_str = "1234567890123456789012345678901234567890123456789E-------";
    String value;

    wr.Position_Add();

    wr.Type_Rule();

    wr.Edit_Positionname(over_str);

    value = Common.Element_Value("bp_text#name", 0);

    if (!value.equals("1234567890123456789012345678901234567890123456789E")) {
      System.out.println("TEST FAILED!!\n\n" + StackTrace.calledFrom());
    }

    over_str = "樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛~~~";

    wr.Edit_Positionname(over_str);

    value = Common.Element_Value("bp_text#name", 0);

    if (!value.equals("樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創")) {
      System.out.println("TEST FAILED!!\n\n" + StackTrace.calledFrom());
    }

    wr.Edit_Positionname("樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛創意樂愛");

    wr.Position_Cancel();

    return;
  }
示例#9
0
  @Override
  public String getAllPageString(String urlString) {
    String indexName = Common.getStoredFileName(SetUp.getTempDirectory(), "index_178_", "html");
    Common.downloadGZIPInputStreamFile(urlString, SetUp.getTempDirectory(), indexName, false, "");

    return Common.getFileString(SetUp.getTempDirectory(), indexName);
  }
示例#10
0
  private void TL_Set_client_DH_params_answer(TL.Object obj) {
    if (obj.name.equals("dh_gen_ok")) {
      // check auth key
      /*
      if (!Arrays.equals( obj.getBytes("new_nonce_hash1"), GEN_nonce_hash(1))) {
      	Common.logError("auth_key check failed");
      	setAuthKey(null);
      	auth();
      //	transport.disconnect();
      	return;
      }
      */

      // done MTProto authorization
      server_salt =
          Common.toLong(Common.AXOR(Common.ASUB(new_nonce, 0, 8), Common.ASUB(sv_nonce, 0, 8)));

      // clean temporary data
      cl_nonce = sv_nonce = new_nonce = null;
      g = g_a = dh_prime = null;
      fp = 0;
      onAuthorized();
    }

    if (obj.name.equals("dh_gen_retry")) send_client_DH_inner_data(auth_key_aux_hash);

    if (obj.name.equals("dh_gen_fail")) transport.disconnect();
  }
示例#11
0
  @Test
  @Category({NoIgnoreTestCategory.class, SmokeTestCategory.class})
  public void testRenameFile() throws Exception {
    FileListView fileListView =
        Actions.login(Config.URL, Config.user, Config.password, Config.isTrusted, driver);
    common.assertIsInFileListView();

    // TODO. if the file already exists, do not upload
    FileListView fileListViewAfterUploadFile = Actions.uploadFile(OLD_FILE_NAME, fileListView);

    // check if the file with the new name already exists, if true delete it
    Actions.deleteElement(FILE_NAME, fileListView, driver);

    fileListViewAfterUploadFile.scrollTillFindElement(OLD_FILE_NAME);
    assertTrue(fileHasBeenCreated = fileListViewAfterUploadFile.getFileElement().isDisplayed());
    CurrentCreatedFile = OLD_FILE_NAME;
    Common.waitTillElementIsNotPresentWithoutTimeout(
        fileListViewAfterUploadFile.getProgressCircular(), 1000);
    common.wait.until(
        ExpectedConditions.visibilityOf(
            fileListViewAfterUploadFile
                .getFileElementLayout()
                .findElement(By.id(FileListView.getLocalFileIndicator()))));
    ElementMenuOptions menuOptions = fileListViewAfterUploadFile.longPressOnElement(OLD_FILE_NAME);
    NewFolderPopUp newFolderPopUp = menuOptions.clickOnRename();
    newFolderPopUp.typeNewFolderName(FILE_NAME);
    WaitAMomentPopUp waitAMomentPopUp = newFolderPopUp.clickOnNewFolderOkButton();
    Common.waitTillElementIsNotPresentWithoutTimeout(
        waitAMomentPopUp.getWaitAMomentTextElement(), 100);
    fileListViewAfterUploadFile.scrollTillFindElement(FILE_NAME);
    assertNotNull(fileListViewAfterUploadFile.getFileElement());
    assertTrue(fileListViewAfterUploadFile.getFileElement().isDisplayed());
    assertEquals(FILE_NAME, fileListViewAfterUploadFile.getFileElement().getText());
    CurrentCreatedFile = FILE_NAME;
  }
      @Override
      protected String doInBackground(Void... unsued) {
        try {
          String response = "";
          String FileName = Common.getNowTime("yyyyMMddHHmmss") + ".csv";

          /*if (isOnline()) {
          	//Response
          	Map<String, String> map = new HashMap<String, String>();
          	map.put("data", sContent);
          	response = NetTool.sendPostRequest(PostDataUrl, map,
          			"UTF-8");
          } else {
          	response = Common.getResText(BarcodeDemoActivity.this, R.string.save_msg) + FileName;
          }*/
          response =
              Common.getResText(BarcodeDemoActivity.this, R.string.save_msg) + " " + FileName;
          writeFile(sContent, FileName);
          return response;
        } catch (Exception e) {
          if (pDialog.isShowing()) pDialog.dismiss();
          Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
          Log.e(e.getClass().getName(), e.getMessage(), e);
          return null;
        }
      }
  private Vector addAnchorString(Vector list, String field, double diff) {
    Vector topIndex = new Vector();
    Hashtable topIndexParms, currEntry;
    double lastValue, currValue;

    if (list.size() == 0) return null;

    currEntry = (Hashtable) list.get(0);
    lastValue = Common.parseDouble((String) currEntry.get(field)) + diff;

    for (int i = 1; i < list.size(); i++) {
      currEntry = (Hashtable) list.get(i);
      currValue = Common.parseDouble((String) currEntry.get(field));
      if (currValue >= lastValue) {
        // Values for navigation line
        topIndexParms = new Hashtable();
        topIndexParms.put("HREF", Convert.toString(i));
        topIndexParms.put("TEXT", Convert.toString(lastValue));
        topIndex.add(topIndexParms);
        // add anchor entry to list
        currEntry.put("ANCHORNAME", Convert.toString(i));
        currEntry.put("ANCHORTEXT", Convert.toString(lastValue));
        lastValue = currValue + diff;
      } else {
        // clear value from previous run
        currEntry.put("ANCHORNAME", "");
        currEntry.put("ANCHORTEXT", "");
      }
      list.set(i, currEntry);
    }
    return topIndex;
  }
示例#14
0
  @Override
  public String getTitleOnMainPage(String urlString, String allPageString) {
    if (needTsukkomiMode(urlString)) {
      tsukkomiMode = true;
      return "Tsukkomi";
    }

    tsukkomiMode = false;

    int beginIndex = allPageString.indexOf("<h1>") + 4;
    int endIndex = allPageString.indexOf("</h1>", beginIndex);
    if (urlString.indexOf("mh.") > 0) {
      beginIndex = allPageString.indexOf("g_comic_name");
      beginIndex = allPageString.indexOf("\"", beginIndex) + 1;
      endIndex = allPageString.indexOf("\"", beginIndex);
    }

    // Common.debugPrintln( "B: " + beginIndex + "  E: " + endIndex );

    if (beginIndex < 0 || endIndex < 0) {
      return null;
    }

    String title = allPageString.substring(beginIndex, endIndex).trim();

    return Common.getStringRemovedIllegalChar(Common.getTraditionalChinese(title));
  }
示例#15
0
  /** Start the DTD parsing (called by GenBeans class) */
  public void process() throws java.io.IOException, Schema2BeansException {
    if (this.filename == null && this.schemaIn == null)
      throw new IllegalArgumentException(Common.getMessage("FilenameNotSpecified_msg", errHeader));

    if (this.handler == null)
      throw new IllegalArgumentException(Common.getMessage("HandlerNotSpecified_msg", errHeader));

    if (config.isTraceParse()) {
      config.messageOut.println(
          "Parsing file "
              + this.filename.toString()
              + // NOI18N
              " with handler "
              + this.handler.getClass()); // NOI18N
    }

    try {
      startupReader();
      this.handler.startDocument(config.getDocRoot());
      this.parse();
      shutdownReader();
      this.handler.endDocument();
    } catch (FileNotFoundException e) {
      config.messageOut.println("Error: file " + this.filename.toString() + " not found"); // NOI18N
      throw e;
      /*
          } catch (IllegalStateException e) {
          throw e;
      } catch (RuntimeException e) {
              TraceLogger.error(e);
          throw e;
           */
    }
  }
示例#16
0
  private void TL_RpcError(TL.Object obj) {
    int code = obj.getInt("error_code");
    String msg = obj.getString("error_message");

    Common.logError(String.format("rpc_error: %s (%d)\n", msg, code));

    Message req_msg = TLMessage.get(req_msg_id);
    if (req_msg == null) return;
    Common.logError("message object: " + req_msg.obj.name + ":" + req_msg.obj.type);

    int idx = msg.indexOf("_MIGRATE_");
    if (idx > 0) {
      String type = msg.substring(0, idx);

      String num = msg.substring(idx + 9);
      if ((idx = num.indexOf(":")) > 0) num = num.substring(0, idx);
      int dc_id = Integer.parseInt(num);
      Common.logError("redirect to dc: " + dc_id);

      MTProto m = MTProto.getConnection(dc_id, cb, reuseFlag);
      cb.onRedirect(m);
      if (type.equals("PHONE") || type.equals("NETWORK") || type.equals("USER")) dc_this = dc_id;

      m.sendMessage(req_msg);
    }
  }
示例#17
0
  private void buildIndexFile(String tagName) {
    String dirPath = getBaseOutputDirectory() + tagName + Common.getSlash();
    String path = "";
    String text = "";
    List<String> volumeTagList = new ArrayList<String>();
    File dir = new File(dirPath); // 你的log檔路徑
    File fileList[] = dir.listFiles(); // 得出檔案清單
    String volumeTitle = "";

    // 取得代號清單
    for (int i = 0; i < fileList.length; i++) {
      if (fileList[i].isFile()) { // 過濾檔案
        String[] temps = fileList[i].toString().split("\\\\");
        String volumeTag = temps[temps.length - 1].split("\\.")[0];
        if (!volumeTag.matches("comment")) volumeTagList.add(volumeTag);
        // print(i + " TAG : " + volumeTag);
      }
    }

    for (int i = 0; i < volumeTagList.size(); i++) {
      path = dirPath + volumeTagList.get(i) + ".js";
      text = Common.getFileString(path);

      if (text.split("'").length <= 1) continue;

      volumeTitle = text.split("'")[1];
    }

    System.exit(0);
  }
示例#18
0
 public ValidaAccesoResponse getValidaAcceso(Operacion request)
     throws Exception, ResponseException {
   Common obj = new Common();
   if (request.getOperacion() == null) {
     request.setOperacion("VIST");
   }
   return obj.getValidaAcceso(request);
 }
示例#19
0
  @Override
  public String getTitleOnSingleVolumePage(String urlString) {
    String allPageString = getAllPageString(urlString);
    int beginIndex = Common.getIndexOfOrderKeyword(allPageString, ">>", 3) + 2;
    int endIndex = Common.getSmallerIndexOfTwoKeyword(allPageString, beginIndex, "[", ">>");
    String title = allPageString.substring(beginIndex, endIndex).trim();

    return Common.getStringRemovedIllegalChar(Common.getTraditionalChinese(title));
  }
示例#20
0
  @Override
  public String getTitleOnMainPage(String urlString, String allPageString) {
    int beginIndex = allPageString.indexOf("valign=\"middle\"><b>");
    beginIndex = allPageString.indexOf("<b>", beginIndex) + 3;
    int endIndex = allPageString.indexOf("</b>", beginIndex);
    String title = allPageString.substring(beginIndex, endIndex).trim();

    return Common.getStringRemovedIllegalChar(Common.getTraditionalChinese(title));
  }
示例#21
0
  /**
   * set lat and lon by using GK coordinates
   *
   * @param strEasting Easting component
   * @param strNorthing Northing component
   */
  public void set(String strEasting, String strNorthing) {
    GkPoint gk =
        new GkPoint(
            Common.parseDouble(strEasting), Common.parseDouble(strNorthing), GkPoint.GERMAN_GK);

    this.latDec = TransformCoordinates.germanGkToWgs84(gk).latDec;
    this.lonDec = TransformCoordinates.germanGkToWgs84(gk).lonDec;
    this.utmValid = false;
  }
示例#22
0
 private String getBaseOutputDirectory() {
   return Common.getNowAbsolutePath()
       + "down"
       + Common.getSlash()
       + "SVN"
       + Common.getSlash()
       + "Tsukkomi1"
       + Common.getSlash();
 }
示例#23
0
  @Override
  public String getTitleOnMainPage(String urlString, String allPageString) {
    int beginIndex = allPageString.indexOf("<title>");
    beginIndex = allPageString.indexOf(">", beginIndex) + 1;
    int endIndex = allPageString.indexOf("</title", beginIndex);
    String title = allPageString.substring(beginIndex, endIndex).split("-")[0].trim();

    return Common.getStringRemovedIllegalChar(Common.getTraditionalChinese(title));
  }
示例#24
0
  @Override
  public List<List<String>> getVolumeTitleAndUrlOnMainPage(String urlString, String allPageString) {
    // combine volumeList and urlList into combinationList, return it.

    List<List<String>> combinationList = new ArrayList<List<String>>();
    List<String> urlList = new ArrayList<String>();
    List<String> volumeList = new ArrayList<String>();

    if (tsukkomiMode) {
      urlList.add(urlString);
      volumeList.add("tsukkomi");
      combinationList.add(volumeList);
      combinationList.add(urlList);

      return combinationList;
    }

    int beginIndex = allPageString.indexOf("class=\"cartoon_online_border\"");
    int endIndex = allPageString.indexOf("document.write", beginIndex);

    if (urlString.indexOf("mh.") > 0) {
      beginIndex = allPageString.indexOf("chapter_list");
      endIndex = allPageString.indexOf("</script>", beginIndex);
    }

    String tempString = allPageString.substring(beginIndex, endIndex);

    int volumeCount = tempString.split("href=\"").length - 1;

    String volumeTitle = "";
    beginIndex = endIndex = 0;
    for (int i = 0; i < volumeCount; i++) {
      // 取得單集位址
      beginIndex = tempString.indexOf("href=\"", beginIndex) + 6;
      endIndex = tempString.indexOf("\"", beginIndex);
      urlList.add(baseURL + tempString.substring(beginIndex, endIndex));

      // 取得單集名稱
      beginIndex = tempString.indexOf(">", beginIndex) + 1;
      endIndex = tempString.indexOf("<", beginIndex);
      volumeTitle = tempString.substring(beginIndex, endIndex);

      volumeList.add(
          getVolumeWithFormatNumber(
              Common.getStringRemovedIllegalChar(
                  Common.getTraditionalChinese(volumeTitle.trim()))));
    }

    totalVolume = volumeCount;
    Common.debugPrintln("共有" + totalVolume + "集");

    combinationList.add(volumeList);
    combinationList.add(urlList);

    return combinationList;
  }
示例#25
0
  /** Send a message. */
  public static void send(String msg, String to) throws IOException {
    // Log.i(TAG, "sending message (msg = " + msg + ")");
    String serverUrl = Common.getServerUrl() + "/send";
    Map<String, String> params = new HashMap<String, String>();
    params.put(Common.MSG, msg);
    params.put(Common.FROM, Common.getPreferredEmail());
    params.put(Common.TO, to);

    post(serverUrl, params, MAX_ATTEMPTS);
  }
示例#26
0
  @Override
  public String getTitleOnMainPage(String urlString, String allPageString) {
    String[] lines = allPageString.split("\n");

    int beginIndex = lines[0].indexOf("<title>", 1) + 7;
    int endIndex = lines[0].indexOf("_", beginIndex) - 4;

    return Common.getStringRemovedIllegalChar(
        Common.getTraditionalChinese(lines[0].substring(beginIndex, endIndex)));
  }
 public Common getCommon(String code) {
   if (this.commons != null) {
     for (Common c : this.commons) {
       if (c.getCode() != null && c.getCode().equals(code)) {
         return c;
       }
     }
   }
   return null;
 }
示例#28
0
  @Override
  public String getAllPageString(String urlString) {
    String indexName = Common.getStoredFileName(SetUp.getTempDirectory(), "index_xindm_", "html");
    String indexEncodeName =
        Common.getStoredFileName(SetUp.getTempDirectory(), "index_xindm_encode_", "html");
    Common.downloadFile(urlString, SetUp.getTempDirectory(), indexName, false, "");
    Common.newEncodeFile(SetUp.getTempDirectory(), indexName, indexEncodeName);

    return Common.getFileString(SetUp.getTempDirectory(), indexEncodeName);
  }
示例#29
0
  private String processQueueMsg(MsgObject msgObject, Keyword keyword) {
    ContentAbstract delegate = null;
    try {
      String classname = "";
      if (keyword.getClassname().startsWith("~")) {
        classname = "MyProcess.InvalidProcess";

        // Cau hinh tra loi luon
        // $msgtype$info
        String sInfo = keyword.getClassname();
        String[] arrInfo = sInfo.split("~");
        String mtreply = "";
        int msgtype = 2;
        if (arrInfo.length > 2) {
          mtreply = arrInfo[2];
          if (LocalConfig.MT_CHARGING.equals(arrInfo[1])) {
            msgtype = 1;
          } else if (LocalConfig.MT_PUSH.equals(arrInfo[1])) {
            msgtype = 3;
          } else if (LocalConfig.MT_REFUND_SYNTAX.equals(arrInfo[1])) {
            msgtype = 21;
          } else if (LocalConfig.MT_REFUND_CONTENT.equals(arrInfo[1])) {
            msgtype = 22;
          } else {
            msgtype = 2;
          }

        } else {
          mtreply = arrInfo[1];
          msgtype = 2;
        }
        msgObject.setUsertext(mtreply);
        msgObject.setMsgtype(msgtype);
      } else {
        classname = keyword.getClassname();
      }

      // Ghi log xem class nào xử lý MO này
      mLog.log.info(
          Common.GetStringLog("Call Class Process Keyword", "ClassName:" + classname, msgObject));

      // Khởi tạo đối tượng process xử lý keyword
      Class<?> delegateClass = Class.forName(classname);
      Object delegateObject = delegateClass.newInstance();
      delegate = (ContentAbstract) delegateObject;

      delegate.start(msgObject, keyword);
      return "OK";

    } catch (Exception e) {
      mLog.log.error(Common.GetStringLog(msgObject), e);

      return msgObject.getUserid() + ":" + e.toString();
    }
  }
示例#30
0
  private List<String> getTagNameList(String url) {
    int beginIndex = 0;
    int endIndex = 0;
    int index = 0;
    List<String> urlList = new ArrayList<String>();
    String temp = "";

    String dummyTagName = "ghdxj";
    Common.deleteFile(getBaseOutputDirectory(), dummyTagName + ".js");
    Common.deleteFolder(getBaseOutputDirectory() + dummyTagName);
    urlList.add(dummyTagName); // 因為第一個都會取得錯誤的評論資料,所以想把錯都推給東方

    String allPageString = getAllPageString(url);

    while (true) {
      beginIndex = allPageString.indexOf(" href=", beginIndex);
      if (beginIndex < 0) break;
      beginIndex = allPageString.indexOf("=", beginIndex) + 2;
      if (beginIndex < 0) break;

      temp = allPageString.substring(beginIndex, beginIndex + 30);
      if (temp.indexOf(baseURL) >= 0) {
        // print("with BASE");
        // ex. href='http://manhua.dmzj.com/lianaibaojun/
        beginIndex = allPageString.indexOf(".com", beginIndex);
        if (beginIndex < 0) break;
        beginIndex = allPageString.indexOf("/", beginIndex);
        if (beginIndex < 0) break;
      }
      beginIndex++; // 從"/"之後開始
      endIndex = allPageString.indexOf("/", beginIndex);
      if (endIndex < 0) break;
      temp = allPageString.substring(beginIndex, endIndex);

      boolean existed = false;
      for (int i = 0; i < urlList.size(); i++) {
        if (urlList.get(i).equals(temp)) {
          existed = true;
          break;
        }
      }

      if (existed || isIllegalPage(temp)) {
        continue;
      }

      urlList.add(temp);
      // print("" + index + " : " + temp);
      index++;
      beginIndex = endIndex;
    }

    return urlList;
  }