Ejemplo n.º 1
0
 public static List<TradingPriceTracking> getPriceTrackingItem(String res, String title)
     throws Exception {
   List<TradingPriceTracking> list = new ArrayList<TradingPriceTracking>();
   Document document = formatStr2Doc(res);
   Element rootElt = document.getRootElement();
   Element searchResult = rootElt.element("searchResult");
   Iterator items = searchResult.elementIterator("item");
   while (items.hasNext()) {
     TradingPriceTracking priceTracking = new TradingPriceTracking();
     Element item = (Element) items.next();
     priceTracking.setItemid(SamplePaseXml.getSpecifyElementText(item, "itemId"));
     priceTracking.setCategoryid(
         SamplePaseXml.getSpecifyElementText(item, "primaryCategory", "categoryId"));
     priceTracking.setCategoryname(
         SamplePaseXml.getSpecifyElementText(item, "primaryCategory", "categoryName"));
     priceTracking.setCurrentprice(
         SamplePaseXml.getSpecifyElementText(item, "sellingStatus", "currentPrice"));
     priceTracking.setSellerusername(
         SamplePaseXml.getSpecifyElementText(item, "sellerInfo", "sellerUserName"));
     priceTracking.setTitle(SamplePaseXml.getSpecifyElementText(item, "title"));
     priceTracking.setBidcount(
         SamplePaseXml.getSpecifyElementText(item, "sellingStatus", "bidCount"));
     priceTracking.setPictureurl(SamplePaseXml.getSpecifyElementText(item, "galleryURL"));
     String starttime = SamplePaseXml.getSpecifyElementText(item, "listingInfo", "startTime");
     String endtime = SamplePaseXml.getSpecifyElementText(item, "listingInfo", "endTime");
     if (StringUtils.isNotBlank(starttime)) {
       priceTracking.setStarttime(DateUtils.returnDate(starttime));
     }
     if (StringUtils.isNotBlank(endtime)) {
       priceTracking.setEndtime(DateUtils.returnDate(endtime));
     }
     Element sellingStatus = item.element("sellingStatus");
     String currencyId1 = "";
     if (sellingStatus != null) {
       Element currentPrice = sellingStatus.element("currentPrice");
       if (currentPrice != null) {
         Attribute currencyId = currentPrice.attribute("currencyId");
         if (currencyId != null) {
           currencyId1 = currencyId.getValue();
         }
       }
     }
     priceTracking.setCurrencyid(currencyId1);
     Element shippingInfo = item.element("shippingInfo");
     if (shippingInfo != null) {
       Element shippingServiceCost = shippingInfo.element("shippingServiceCost");
       if (shippingServiceCost != null) {
         Attribute shippingcurrencyId = shippingServiceCost.attribute("currencyId");
         if (shippingcurrencyId != null) {
           priceTracking.setShippingcurrencyid(shippingcurrencyId.getValue());
         }
         priceTracking.setShippingservicecost(shippingServiceCost.getTextTrim());
       }
     }
     priceTracking.setQuerytitle(title);
     list.add(priceTracking);
   }
   return list;
 }
Ejemplo n.º 2
0
 public static String getVFromXmlString(String xml, String nodeName) throws Exception {
   // ByteArrayInputStream is = new ByteArrayInputStream(res.getBytes());//文件
   Document document = formatStr2Doc(xml);
   // Document document = DocumentHelper.parseText(xml);
   Element rootElt = document.getRootElement();
   // Iterator iter = rootElt.elementIterator("SessionID");
   Element e = rootElt.element(nodeName);
   if (e == null) {
     return null;
   }
   return e.getTextTrim();
 }
Ejemplo n.º 3
0
 /** 获取指定元素下面的某层指定元素内容 */
 public static String getSpecifyElementText(Element root, String... firstElement)
     throws Exception {
   String text = null;
   String[] nodes = firstElement;
   int length = nodes.length;
   for (int i = 0; i < length; i++) {
     String node = nodes[i];
     if (i == (length - 1)) {
       if (root == null) {
         return null;
       }
       Element last = root.element(node);
       if (last != null) {
         text = last.getTextTrim();
       }
     } else {
       if (root == null) {
         return null;
       }
       root = root.element(node);
     }
   }
   return text;
 }
Ejemplo n.º 4
0
  /** 将商品目录属性api返回的xml解析为List<PublicDataDict> */
  public static List<PublicDataDict> getListForPublicDataDict(String xml) throws Exception {
    List<PublicDataDict> publicDataDictList = new ArrayList<PublicDataDict>();
    Document document = formatStr2Doc(xml);
    Element rootElt = document.getRootElement();
    Element recommend = rootElt.element("Recommendations");

    Element cad = recommend.element("CategoryID");
    String categoryID = cad.getTextTrim();

    Iterator<Element> iter = recommend.elementIterator("NameRecommendation");
    while (iter.hasNext()) {

      Element element = iter.next();
      String itemId = element.element("Name").getText();
      Iterator<Element> valueIter = element.elementIterator("ValueRecommendation");
      while (valueIter.hasNext()) {
        Element element1 = valueIter.next();
        PublicDataDict publicDataDict = new PublicDataDict();
        publicDataDict.setItemId(itemId);
        publicDataDict.setItemParentId(categoryID);
        String val = element1.element("Value").getText();
        publicDataDict.setItemEnName(val);
        publicDataDict.setItemType(DictCollectionsUtil.categorySpecifics);
        publicDataDictList.add(publicDataDict);
      }
    }
    if (publicDataDictList.isEmpty()) {
      PublicDataDict publicDataDict = new PublicDataDict();
      publicDataDict.setItemId(DictCollectionsUtil.categorySpecifics + categoryID);
      publicDataDict.setItemParentId(categoryID);
      publicDataDict.setItemEnName("noval");
      publicDataDict.setItemType(DictCollectionsUtil.categorySpecifics);
      publicDataDictList.add(publicDataDict);
    }
    return publicDataDictList;
  }