コード例 #1
0
  /** 得到下一个商品节点 */
  @Override
  public Node next() {
    if (hasNext()) {
      if (point == productList.size() - 1) {
        pageIndex++;
        map.put("pg", String.valueOf(pageIndex));
        map.put("ps", String.valueOf(pageSize));
        String url = URLBuilder.buildURL(map);
        String xml = SearchRequester.get(url);
        try {
          productList = XMLParser.getProductNodes(XMLParser.read(xml));
        } catch (MalformedURLException | DocumentException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        //				productList = URLBuilder.getXML(verifyPoint, keyWord, media);
        point = 0;
        return productList.get(point);
      } else {
        point++;
        return productList.get(point);
      }

    } else {
      return null;
    }
  }
コード例 #2
0
 /*
  * 	通过Map参数拼URL获取XML数据,再获取productList
  */
 public ProdIterator(Map<String, String> map, int maxIndex) {
   this.map = map;
   this.maxIndex = maxIndex;
   this.map.put("pg", String.valueOf(pageIndex));
   this.map.put("ps", String.valueOf(pageSize));
   String url = URLBuilder.buildURL(this.map);
   String xml = SearchRequester.get(url);
   logger.debug(url);
   try {
     Document doc = XMLParser.read(xml);
     productList = XMLParser.getProductNodes(doc);
     pageCount = Integer.valueOf(XMLParser.PageCount(doc));
     totalCount = Integer.valueOf(XMLParser.totalCount(doc));
     setTerm(XMLParser.term(doc));
     if (totalCount < maxIndex) {
       this.maxIndex = totalCount;
     }
     // logger.debug(" - [Iterator] - init the product List!");
   } catch (MalformedURLException | DocumentException e) {
     ByteArrayOutputStream buf = new ByteArrayOutputStream();
     e.printStackTrace(new PrintWriter(buf, true));
     String expMessage = buf.toString();
     logger.error(" - [LOG_EXCEPTION] - " + expMessage);
     //			 logger.error(expMessage);
     //			e.printStackTrace();
   }
 }
コード例 #3
0
 public boolean reSet() {
   this.pageIndex = 1;
   this.point = -1;
   this.map.put("pg", String.valueOf(pageIndex));
   this.map.put("ps", String.valueOf(pageSize));
   String url = URLBuilder.buildURL(this.map);
   String xml = SearchRequester.get(url);
   try {
     Document doc = XMLParser.read(xml);
     productList = XMLParser.getProductNodes(doc);
     pageCount = Integer.valueOf(XMLParser.PageCount(doc));
     totalCount = Integer.valueOf(XMLParser.totalCount(doc));
     // logger.debug(" - [Iterator] - reSet the product List!");
     return true;
   } catch (MalformedURLException | DocumentException e) {
     // TODO Auto-generated catch block
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     e.printStackTrace(new PrintStream(baos));
     String exception = baos.toString();
     logger.error(" - [LOG_EXCEPTION] - " + exception);
     e.printStackTrace();
     return false;
   }
 }