Ejemplo n.º 1
0
  public List<String> doExecute(String rValue) {
    //		System.out.println("==============rValue="+rValue);
    List<String> dataList = new ArrayList<String>();
    // TODO Auto-generated method stub
    if (!ErrorCode.isEmpty(rValue) && !rValue.equals(this.CODE)) {
      rValue = rValue.trim();
    } else {
      log4.info(this.CODE + ", " + this.HELP_INFO);
      dataList.add(this.CODE + ", " + this.HELP_INFO);
      return dataList;
    }
    if (rValue.startsWith("-f")) {
      try {
        List<String> pathList = this.loadFilePath(rValue);
        for (String path : pathList) {
          rValue = this.doFile(path);
          dataList.add(rValue);
        }
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        dataList.add(e.getMessage());
        return dataList;
      }

    } else {
      dataList.addAll(this.doWeb(rValue));
    }
    return dataList;
  }
Ejemplo n.º 2
0
  private List doWeb(String rValue) {
    boolean isByCookie = false;
    if (rValue.indexOf("-cookie") >= 0) {
      isByCookie = true;
      rValue = rValue.replaceAll("-cookie", "");
      rValue = rValue.trim();
    }

    //		System.out.println("------doWeb-------"+rValue);
    List<String> dataList = new ArrayList<String>();

    if (rValue.startsWith("login")) {
      rValue = rValue.substring("login".length()).trim();
      String[] strs = rValue.split(",");
      String url = strs[0];
      String loginUrl = url.substring(url.lastIndexOf("/"));
      url = url.substring(0, url.lastIndexOf("/"));
      //			System.out.println("-------------03-"+strs.length);
      //			System.out.println("---baseUrl="+url+" loginUrl="+loginUrl);
      webUtil.setBase_url(url);
      webUtil.setLogin_url(loginUrl);
      if (strs.length >= 3) {
        webUtil.setUsername(strs[1]);
        webUtil.setPassword(strs[2]);
      }
      //			System.out.println("-------------04-");
      try {
        //				System.out.println("-------------0-");
        webUtil.login();
        //				System.out.println("--------------1=");
        dataList.add("do login finish");
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        dataList.add(e.getMessage());
      }

    } else {
      //			System.out.println("--------------2=");
      String url = rValue;
      String filter = null;
      if (rValue.indexOf(" ") > 0) {
        url = url.substring(0, url.indexOf(" "));
        filter = rValue.substring(rValue.indexOf(" ")).trim();
      }
      String visitUrl = url.substring(url.lastIndexOf("/"));
      url = url.substring(0, url.lastIndexOf("/"));
      webUtil.setUrl(visitUrl);
      webUtil.setBase_url(url);
      List<String> htmlList = null;
      try {
        htmlList = webUtil.visit(isByCookie);
        if (!ErrorCode.isEmpty(filter)) {
          htmlList = CommMethod.filterValue(htmlList, filter);
        }
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (htmlList != null) dataList = htmlList;
    }
    return dataList;
  }