/* * 通过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(); } }
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; } }