List of usage examples for org.jsoup.nodes Element select
public Elements select(String cssQuery)
From source file:com.adarshahd.indianrailinfo.donate.TrainDetails.java
private void createTableLayoutTrainAvailability() { if (mPage.contains("SORRY")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Not a valid class, Please select a different class and try again."); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews();/*from w ww . j a v a2s .com*/ mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ISL Of")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Station is not in ISL Of the Train. \nPlease modify the source/destination!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ERROR")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Your request resulted in an error.\nPlease check!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("Network Connectivity")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Looks like the server is busy.\nPlease try later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("unavailable")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText( "Response from server:\n\nYour request could not be processed now.\nPlease try again later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mDetails == null || !mDetails.getTrainNumber().equals(mTrainNumber)) { Iterator iterator = null; try { iterator = mElements.first().parent().parent().parent().getElementsByTag("tr").iterator(); } catch (Exception e) { Log.i("TrainDetails", mPage); e.printStackTrace(); return; } mListAv = new ArrayList<List<String>>(); List<String> list; Element tmp; tmp = (Element) iterator.next(); list = new ArrayList<String>(); list.add(tmp.select("th").get(0).text()); list.add("Date"); list.add(tmp.select("th").get(2).text()); //list.add(tmp.select("th").get(3).text()); mListAv.add(list); while (iterator.hasNext()) { tmp = (Element) iterator.next(); if (!tmp.hasText()) { continue; } list = new ArrayList<String>(); list.add(tmp.select("td").get(0).text()); list.add(tmp.select("td").get(1).text()); list.add(tmp.select("td").get(2).text()); //list.add(tmp.select("td").get(3).text()); mListAv.add(list); } mDetails = new Details(mListAv, TrainEnquiry.AVAILABILITY, mTrainNumber); } else { mListAv = mDetails.getList(); } mTblLayoutAv = new TableLayout(mActivity); TableRow row; TextView tv1, tv2, tv3; mTblLayoutAv.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); for (int i = 0; i < mListAv.size(); i++) { row = new TableRow(mActivity); tv1 = new TextView(mActivity); tv2 = new TextView(mActivity); tv3 = new TextView(mActivity); //tv4 = new TextView(mActivity); tv1.setText(" " + mListAv.get(i).get(0)); tv2.setText(" " + mListAv.get(i).get(1)); tv3.setText(" " + mListAv.get(i).get(2)); //tv4.setText(" " + mListAv.get(i).get(3)); tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv3.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); //tv4.setTextAppearance(mActivity,android.R.style.TextAppearance_DeviceDefault_Medium); tv1.setPadding(5, 5, 5, 5); tv2.setPadding(5, 5, 5, 5); tv3.setPadding(5, 5, 5, 5); //tv4.setPadding(5,5,5,5); /*tv2.setBackgroundResource(R.drawable.card_divider); tv3.setBackgroundResource(R.drawable.card_divider); tv4.setBackgroundResource(R.drawable.card_divider);*/ row.addView(tv1); row.addView(tv2); row.addView(tv3); //row.addView(tv4); row.setBackgroundResource(R.drawable.button_selector); row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); row.setOnClickListener(this); mTblLayoutAv.addView(row); } LinearLayout ll = new LinearLayout(mActivity); ScrollView scrollView = new ScrollView(mActivity); TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Availability details:"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(textViewTrnDtls); ll.addView(mTblLayoutAv); scrollView.addView(ll); mFrameLayout.removeAllViews(); mFrameLayout.addView(scrollView); if (mDialog.isShowing()) { mDialog.cancel(); } }
From source file:de.geeksfactory.opacclient.apis.Open.java
protected SearchRequestResult parse_search(Document doc, int page) throws OpacErrorException { searchResultDoc = doc;/*from w ww.ja va 2s . com*/ if (doc.select("#Label1, span[id$=LblInfoMessage]").size() > 0) { String message = doc.select("#Label1, span[id$=LblInfoMessage]").text(); if (message.contains("keine Treffer")) { return new SearchRequestResult(new ArrayList<SearchResult>(), 0, 1, page); } else { throw new OpacErrorException(message); } } int totalCount = Integer.parseInt(doc.select("span[id$=TotalItemsLabel]").first().text()); Elements elements = doc.select("div[id$=divMedium], div[id$=divComprehensiveItem]"); List<SearchResult> results = new ArrayList<>(); int i = 0; for (Element element : elements) { SearchResult result = new SearchResult(); // Cover if (element.select("input[id$=mediumImage]").size() > 0) { result.setCover(element.select("input[id$=mediumImage]").first().attr("src")); } else if (element.select("img[id$=CoverView_Image]").size() > 0) { result.setCover(getCoverUrl(element.select("img[id$=CoverView_Image]").first())); } Element catalogueContent = element.select(".catalogueContent").first(); // Media Type if (catalogueContent.select("#spanMediaGrpIcon").size() > 0) { String mediatype = catalogueContent.select("#spanMediaGrpIcon").attr("class"); if (mediatype.startsWith("itemtype ")) { mediatype = mediatype.substring("itemtype ".length()); } SearchResult.MediaType defaulttype = defaulttypes.get(mediatype); if (defaulttype == null) defaulttype = SearchResult.MediaType.UNKNOWN; if (data.has("mediatypes")) { try { result.setType(SearchResult.MediaType .valueOf(data.getJSONObject("mediatypes").getString(mediatype))); } catch (JSONException e) { result.setType(defaulttype); } } else { result.setType(defaulttype); } } else { result.setType(SearchResult.MediaType.UNKNOWN); } // Text String title = catalogueContent.select("a[id$=LbtnShortDescriptionValue], a[id$=LbtnTitleValue]") .text(); String subtitle = catalogueContent.select("span[id$=LblSubTitleValue]").text(); String author = catalogueContent.select("span[id$=LblAuthorValue]").text(); String year = catalogueContent.select("span[id$=LblProductionYearValue]").text(); String publisher = catalogueContent .select("span[id$=LblManufacturerValue], span[id$=LblPublisherValue]").text(); String series = catalogueContent.select("span[id$=LblSeriesValue]").text(); StringBuilder text = new StringBuilder(); text.append("<b>").append(title).append("</b>"); if (!subtitle.equals("")) text.append("<br/>").append(subtitle); if (!author.equals("")) text.append("<br/>").append(author); if (!year.equals("")) text.append("<br/>").append(year); if (!publisher.equals("")) text.append("<br/>").append(publisher); if (!series.equals("")) text.append("<br/>").append(series); result.setInnerhtml(text.toString()); // ID Pattern idPattern = Pattern.compile("\\$mdv(\\d+)\\$"); Matcher matcher = idPattern.matcher(catalogueContent.html()); if (matcher.find()) { result.setId(matcher.group(1)); } // Availability if (result.getId() != null) { String url = opac_url + "/DesktopModules/OCLC.OPEN.PL.DNN.SearchModule/SearchService" + ".asmx/GetAvailability"; String culture = element.select("input[name$=culture]").val(); JSONObject data = new JSONObject(); try { // Determine portalID value int portalId = 1; for (Element scripttag : doc.select("script")) { String scr = scripttag.html(); if (scr.contains("LoadSharedCatalogueViewAvailabilityAsync")) { Pattern portalIdPattern = Pattern .compile(".*LoadSharedCatalogueViewAvailabilityAsync\\([^,]*,[^,]*," + "[^0-9,]*([0-9]+)[^0-9,]*,.*\\).*"); Matcher portalIdMatcher = portalIdPattern.matcher(scr); if (portalIdMatcher.find()) { portalId = Integer.parseInt(portalIdMatcher.group(1)); } } } data.put("portalId", portalId).put("mednr", result.getId()).put("culture", culture) .put("requestCopyData", false).put("branchFilter", ""); StringEntity entity = new StringEntity(data.toString()); entity.setContentType(ContentType.APPLICATION_JSON.getMimeType()); String json = httpPost(url, entity, getDefaultEncoding()); JSONObject availabilityData = new JSONObject(json); String isAvail = availabilityData.getJSONObject("d").getString("IsAvail"); switch (isAvail) { case "true": result.setStatus(SearchResult.Status.GREEN); break; case "false": result.setStatus(SearchResult.Status.RED); break; case "digital": result.setStatus(SearchResult.Status.UNKNOWN); break; } } catch (JSONException | IOException e) { e.printStackTrace(); } } result.setNr(i); results.add(result); } return new SearchRequestResult(results, totalCount, page); }
From source file:com.weavers.duqhan.business.impl.ProductServiceImpl.java
@Override public void loadTempProducts(List<StatusBean> statusBeans) { boolean isSuccess = true; String startDate = new Date().toString(); Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE, "(==I==)DATE: " + startDate + "Store product details in temp product table start....."); try {/*from ww w .ja v a 2 s. com*/ String status = ""; for (StatusBean statusBean : statusBeans) { status = "Link duplicate"; Temtproductlinklist temtproductlinklist = temtproductlinklistDao.loadById(statusBean.getId()); if (temtproductlinklist != null && temtproductlinklist.getStatus() == 0) { Product testProduct = productDao.getProductByExternelLink(temtproductlinklist.getLink()); if (testProduct == null) { String value = ""; Elements detailMain; Elements detailSub; Elements specifics; double votes = 0.0; double stars = 0.0; double feedback = 0.0; String url = temtproductlinklist.getLink(); try { testProduct = new Product(); Product savedTestProduct; //=================== Random sleep START ===================// // TimeUnit.SECONDS.sleep(30 + (int) (Math.random() * 100)); Random randomObj = new Random(); TimeUnit.SECONDS.sleep(randomObj.ints(30, 60).findFirst().getAsInt()); //=================== Random sleep END =====================// Document doc = Jsoup.connect(url).get(); detailMain = doc.select("#j-detail-page"); if (!detailMain.isEmpty()) { //=================== Criteria Block START==================// detailMain = doc.select(".rantings-num"); if (!detailMain.isEmpty()) { votes = Double.valueOf(detailMain.text().split(" votes")[0].split("\\(")[1]); } detailMain = doc.select(".percent-num"); if (!detailMain.isEmpty()) { stars = Double.valueOf(detailMain.text()); } detailMain = doc.select("ul.ui-tab-nav li[data-trigger='feedback'] a"); if (!detailMain.isEmpty()) { feedback = Double.valueOf(detailMain.text().split("\\(")[1].split("\\)")[0]); } //=================== Criteria Block END==================// if (votes > 10.0 && stars > 4.0 && feedback > 4.0) { detailMain = doc.select(".detail-wrap .product-name"); testProduct.setName(detailMain .text());/*.substring(0, Math.min(detailMain.text().length(), 50))*/ detailMain = doc.select(".detail-wrap .product-name"); testProduct.setDescription(detailMain.text()); testProduct.setExternalLink(url); testProduct.setVendorId(1l);//?????????????????????? //=================== Packaging block START==================// Double weight = 1.0; Double width = 1.0; Double height = 1.0; Double length = 1.0; detailMain = doc.select( "div#j-product-desc div.pnl-packaging-main ul li.packaging-item"); for (Element element : detailMain) { String packagingTitle = element.select("span.packaging-title").text(); String packagingDesc = element.select("span.packaging-des").text(); if (packagingTitle.trim().equals("Package Weight:")) { String str = packagingDesc; str = str.replaceAll("[^.?0-9]+", " "); if (Arrays.asList(str.trim().split(" ")) != null) { if (!Arrays.asList(str.trim().split(" ")).isEmpty()) { try { weight = Double.parseDouble( Arrays.asList(str.trim().split(" ")).get(0)); } catch (Exception e) { weight = 1.0; } } } System.out.println("weight == " + weight); } else if (packagingTitle.trim().equals("Package Size:")) { String str = packagingDesc; str = str.replaceAll("[^.?0-9]+", " "); if (Arrays.asList(str.trim().split(" ")) != null) { if (!Arrays.asList(str.trim().split(" ")).isEmpty()) { try { width = Double.parseDouble( Arrays.asList(str.trim().split(" ")).get(0)); height = Double.parseDouble( Arrays.asList(str.trim().split(" ")).get(1)); length = Double.parseDouble( Arrays.asList(str.trim().split(" ")).get(2)); } catch (Exception e) { width = 1.0; height = 1.0; length = 1.0; } } } System.out.println("width == " + width); System.out.println("height == " + height); System.out.println("length == " + length); } } //=================== Packaging block END==================// //=================== Category block START==================// detailMain = doc.select("div.ui-breadcrumb div.container a"); Long productCategoryId = 0L; String parentPath = ""; String thisCategory = detailMain.last().text().trim(); System.out.println("thisCategory == " + thisCategory); Category parentCategory = new Category(); parentCategory.setId(0L); parentCategory.setParentPath(""); for (Element element : detailMain) { String newCategory; newCategory = element.text().trim(); System.out.println("newCategory======" + newCategory); if (newCategory.equals("Home") || newCategory.equals("All Categories")) { } else { Category category = categoryDao.getCategoryByName(newCategory); if (category != null) { if (category.getName().equals(thisCategory)) { productCategoryId = category.getId(); parentPath = category.getParentPath(); } parentCategory = category; } else { category = new Category(); category.setId(null); category.setName(newCategory); category.setParentId(parentCategory.getId()); category.setParentPath(parentCategory.getParentPath() + parentCategory.getId() + "="); category.setQuantity(0); category.setImgUrl("-"); category.setDisplayText(newCategory); Category category2 = categoryDao.save(category); if (category.getName().equals(thisCategory)) { productCategoryId = category2.getId(); parentPath = category2.getParentPath(); } parentCategory = category2; } } } //=================== Category block END==================// //=============== Specifications block START==============// detailMain = doc.select(".product-property-list .property-item"); String specifications = ""; for (Element element : detailMain) { specifications = specifications + element.select(".propery-title").get(0).text().replace(",", "/") .replace(":", "-") + ":" + element.select(".propery-des").get(0).text() .replace(",", "/").replace(":", "-") + ",";//TODO:, check } //=============== Specifications Block END==============// //=============== Shipping Time Block START==============// String shippingTime = ""; detailMain = doc.select(".shipping-days[data-role='delivery-days']"); System.out.println("value detailMain" + detailMain.toString()); shippingTime = detailMain.text(); //=============== Shipping Time Block END==============// //=============== Shipping Cost Block START==============// detailMain = doc.select(".logistics-cost"); value = detailMain.text(); if (!value.equalsIgnoreCase("Free Shipping")) { // f = 0.00; } else { // f = Double.parseDouble(value.replaceAll(".*?([\\d.]+).*", "$1")); } //=============== Shipping Cost Block END==============// //=================Product save 1st START==============// testProduct.setCategoryId(productCategoryId); testProduct.setLastUpdate(new Date()); testProduct.setParentPath(parentPath); testProduct.setImgurl("-"); testProduct.setProperties("-"); testProduct.setProductWidth(width); testProduct.setProductLength(length); testProduct.setProductWeight(weight); testProduct.setProductHeight(height); testProduct.setShippingRate(0.0); testProduct.setShippingTime("45"); testProduct.setSpecifications(specifications); savedTestProduct = productDao.save(testProduct); //====================Product save 1st END==============// //========= Property, Property Value, Property Product Map Block START ========// double discountPrice = 0.0; double actualPrice = 0.0; double markupPrice = 0.0; String id = ""; String allProperties = ""; //------------------------Read Color css START---------------------// specifics = doc.select("#j-product-info-sku dl.p-property-item"); Elements cssdetailMain = doc.select("link[href]"); Document cssdoc = new Document(""); System.out.println( "====================================================cssdetailMain" + cssdetailMain.size()); for (Element element : cssdetailMain) { String cssurl = element.attr("abs:href"); if (cssurl.contains("??main-detail")) { try { cssdoc = Jsoup.connect(cssurl).get(); } catch (IOException ex) { } break; } } //-----------------------Read Color css END--------------------------// //-----------Product Property, Property Value START--------// Map<String, ProductPropertyvalues> propertyValuesMap = new HashMap<>(); if (!specifics.isEmpty()) { ProductProperties testPorperties; ProductProperties saveTestPorperties; ProductPropertyvalues testPropertyValues; for (Element specific : specifics) { System.out.println("head ==== " + specific.select("dt").text()); testPorperties = productPropertiesDao .loadByName(specific.select("dt").text()); if (testPorperties == null) { testPorperties = new ProductProperties(); testPorperties.setPropertyName(specific.select("dt").text()); saveTestPorperties = productPropertiesDao.save(testPorperties); } else { saveTestPorperties = testPorperties; } allProperties = allProperties + saveTestPorperties.getId().toString() + "-"; detailSub = specific.select("dd ul li"); String valu = "-"; for (Element element : detailSub) { testPropertyValues = new ProductPropertyvalues(); id = element.select("a[data-sku-id]").attr("data-sku-id").trim(); testPropertyValues.setRefId(id); if (element.hasClass("item-sku-image")) { valu = element.select("a img[src]").get(0).absUrl("src") .split(".jpg")[0] + ".jpg"; String title = element.select("a img").get(0).attr("title"); String imgUrl = GoogleBucketFileUploader .uploadProductImage(valu, savedTestProduct.getId()); valu = "<img src='" + imgUrl + "' title='" + title + "' style='height:40px; width:40px;'/>"; } else if (element.hasClass("item-sku-color")) { String style = cssdoc.html().split("sku-color-" + id)[1] .split("}")[0].substring(1); valu = "<span style='" + style + "' ; height:40px; width:40px; display:block;'></span>"; } else { valu = element.select("a span").toString(); } System.out.println("valu === " + valu); testPropertyValues.setProductId(savedTestProduct.getId()); testPropertyValues.setPropertyId(saveTestPorperties.getId()); testPropertyValues.setValueName(valu); propertyValuesMap.put(id, productPropertyvaluesDao.save(testPropertyValues)); } } savedTestProduct.setProperties(allProperties); } //-----------Product Property, Property Value END--------// //----------------------Read json START------------------// List<AxpProductDto> axpProductDtos = new ArrayList<>(); Elements scripts = doc.select("script"); // Get the script part for (Element script : scripts) { if (script.html().contains("var skuProducts=")) { String jsonData = ""; jsonData = script.html().split("var skuProducts=")[1] .split("var GaData")[0].trim(); jsonData = jsonData.substring(0, jsonData.length() - 1); Gson gsonObj = new Gson(); axpProductDtos = Arrays .asList(gsonObj.fromJson(jsonData, AxpProductDto[].class)); break; } } //----------------------Read json END------------------// //-------------Product Properties Map START------------// for (AxpProductDto thisAxpProductDto : axpProductDtos) { SkuVal skuVal = thisAxpProductDto.getSkuVal(); if (skuVal.getActSkuCalPrice() != null) { value = skuVal.getActSkuCalPrice().trim(); discountPrice = CurrencyConverter.usdTOinr( Double.parseDouble(value.replaceAll(".*?([\\d.]+).*", "$1"))); value = skuVal.getSkuCalPrice().trim(); actualPrice = CurrencyConverter.usdTOinr( Double.parseDouble(value.replaceAll(".*?([\\d.]+).*", "$1"))); markupPrice = discountPrice * 0.15 + 100; discountPrice = Math.ceil((discountPrice + markupPrice) / 10) * 10; actualPrice = Math.round(actualPrice + markupPrice); } else { discountPrice = 0.0; value = skuVal.getSkuCalPrice().trim(); actualPrice = CurrencyConverter.usdTOinr( Double.parseDouble(value.replaceAll(".*?([\\d.]+).*", "$1"))); markupPrice = actualPrice * 0.15 + 100; discountPrice = Math.round(actualPrice + markupPrice); actualPrice = Math.round(actualPrice + markupPrice); } ProductPropertiesMap productPropertyMap = new ProductPropertiesMap(); String myPropValueIds = ""; if (thisAxpProductDto.getSkuAttr() != null) { String[] skuPropIds = thisAxpProductDto.getSkuPropIds().split(","); for (String skuPropId : skuPropIds) { myPropValueIds = myPropValueIds + propertyValuesMap.get(skuPropId).getId().toString() + "_"; } productPropertyMap.setPropertyvalueComposition(myPropValueIds); } else { productPropertyMap.setPropertyvalueComposition("_"); } productPropertyMap.setDiscount(discountPrice); productPropertyMap.setPrice(actualPrice); productPropertyMap.setProductId(savedTestProduct); productPropertyMap.setQuantity(5l); productPropertiesMapDao.save(productPropertyMap); } //-------------Product Properties Map START------------// //========= Property, Property Value, Property Product Map Block END ========// //============= Multiple Image Block START =============// detailMain = doc.select("ul.image-thumb-list span.img-thumb-item img[src]"); int flg = 0; String imgUrl = ""; for (Element element : detailMain) { imgUrl = GoogleBucketFileUploader.uploadProductImage( element.absUrl("src").split(".jpg")[0] + ".jpg", savedTestProduct.getId()); if (flg == 0) { flg++; savedTestProduct.setImgurl(imgUrl); } else { ProductImg productImg = new ProductImg(); productImg.setId(null); productImg.setImgUrl(imgUrl); productImg.setProductId(savedTestProduct.getId()); productImgDao.save(productImg); } } //============= Multiple Image Block END =============// //=================Product save final START==============// if (productDao.save(savedTestProduct) != null) { temtproductlinklist.setStatus(1);// temtproductlinklistDao.save(temtproductlinklist); status = "Success"; } //=================Product save final START==============// } else { temtproductlinklist.setStatus(2);// temtproductlinklistDao.save(temtproductlinklist); status = "criteria mismatch"; } } else { status = "Page not found"; } } catch (Exception ex) { System.out.println( "=============================================================Exception1" + ex); temtproductlinklist.setStatus(4);// temtproductlinklistDao.save(temtproductlinklist); System.out.println("Exception === " + ex); status = "Failure"; Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE, "(==E==)DATE: " + new Date().toString() + "Store product details in temp product table get error in sub process.....\n Link Id: " + statusBean.getId() + "\n Started on" + startDate, ex); } } else { temtproductlinklist.setStatus(3);// temtproductlinklistDao.save(temtproductlinklist); status = "Product exsist"; } } // String body = "Id: " + temtproductlinklist.getId() + "<br/> Status: " + status; // MailSender.sendEmail("krisanu.nandi@pkweb.in", "Product captured", body, "subhendu.sett@pkweb.in"); statusBean.setStatus(status); } System.out.println("=============================================================status" + status); } catch (Exception e) { System.out.println("=============================================================Exception2" + e); isSuccess = false; String body = "(==E==)DATE: " + new Date().toString() + "Store product details in temp product table get error.....<br/> Started on" + startDate + "<br/>"; Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE, body, e); // MailSender.sendEmail("krisanu.nandi@pkweb.in", "Stopped store product details", body + e.getLocalizedMessage(), "subhendu.sett@pkweb.in"); } if (isSuccess) { String body = "(==I==)DATE: " + new Date().toString() + "Store product details in temp product table end.....<br/> Started on" + startDate; Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE, body); /*ObjectMapper mapper = new ObjectMapper(); try { MailSender.sendEmail("krisanu.nandi@pkweb.in", "Completed store product details", body + "=============<br/><br/>" + mapper.writeValueAsString(statusBeans), "subhendu.sett@pkweb.in"); } catch (JsonProcessingException ex) { Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE, null, ex); }*/ } // return statusBeans; System.out.println("=============================================================end"); }
From source file:de.geeksfactory.opacclient.apis.Pica.java
protected SearchRequestResult parse_search(String html, int page) throws OpacErrorException { Document doc = Jsoup.parse(html); updateSearchSetValue(doc);/*w w w . j a v a 2 s. c om*/ if (doc.select(".error").size() > 0) { String error = doc.select(".error").first().text().trim(); if (error.equals("Es wurde nichts gefunden.") || error.equals("Nothing has been found") || error.equals("Er is niets gevonden.") || error.equals("Rien n'a t trouv.")) { // nothing found return new SearchRequestResult(new ArrayList<SearchResult>(), 0, 1, 1); } else { // error throw new OpacErrorException(error); } } reusehtml = html; int results_total; String resultnumstr = doc.select(".pages").first().text(); Pattern p = Pattern.compile("[0-9]+$"); Matcher m = p.matcher(resultnumstr); if (m.find()) { resultnumstr = m.group(); } if (resultnumstr.contains("(")) { results_total = Integer.parseInt(resultnumstr.replaceAll(".*\\(([0-9]+)\\).*", "$1")); } else if (resultnumstr.contains(": ")) { results_total = Integer.parseInt(resultnumstr.replaceAll(".*: ([0-9]+)$", "$1")); } else { results_total = Integer.parseInt(resultnumstr); } List<SearchResult> results = new ArrayList<>(); if (results_total == 1) { // Only one result DetailledItem singleResult = parse_result(html); SearchResult sr = new SearchResult(); sr.setType(getMediaTypeInSingleResult(html)); sr.setInnerhtml( "<b>" + singleResult.getTitle() + "</b><br>" + singleResult.getDetails().get(0).getContent()); results.add(sr); } Elements table = doc.select("table[summary=hitlist] tbody tr[valign=top]"); // identifier = null; Elements links = doc.select("table[summary=hitlist] a"); boolean haslink = false; for (int i = 0; i < links.size(); i++) { Element node = links.get(i); if (node.hasAttr("href") & node.attr("href").contains("SHW?") && !haslink) { haslink = true; try { List<NameValuePair> anyurl = URLEncodedUtils.parse(new URI(node.attr("href")), getDefaultEncoding()); for (NameValuePair nv : anyurl) { if (nv.getName().equals("identifier")) { // identifier = nv.getValue(); break; } } } catch (Exception e) { e.printStackTrace(); } } } for (int i = 0; i < table.size(); i++) { Element tr = table.get(i); SearchResult sr = new SearchResult(); if (tr.select("td.hit img").size() > 0) { String[] fparts = tr.select("td img").get(0).attr("src").split("/"); String fname = fparts[fparts.length - 1]; if (data.has("mediatypes")) { try { sr.setType(MediaType.valueOf(data.getJSONObject("mediatypes").getString(fname))); } catch (JSONException | IllegalArgumentException e) { sr.setType(defaulttypes.get(fname.toLowerCase(Locale.GERMAN).replace(".jpg", "") .replace(".gif", "").replace(".png", ""))); } } else { sr.setType(defaulttypes.get(fname.toLowerCase(Locale.GERMAN).replace(".jpg", "") .replace(".gif", "").replace(".png", ""))); } } Element middlething = tr.child(2); List<Node> children = middlething.childNodes(); int childrennum = children.size(); List<String[]> strings = new ArrayList<>(); for (int ch = 0; ch < childrennum; ch++) { Node node = children.get(ch); if (node instanceof TextNode) { String text = ((TextNode) node).text().trim(); if (text.length() > 3) { strings.add(new String[] { "text", "", text }); } } else if (node instanceof Element) { List<Node> subchildren = node.childNodes(); for (int j = 0; j < subchildren.size(); j++) { Node subnode = subchildren.get(j); if (subnode instanceof TextNode) { String text = ((TextNode) subnode).text().trim(); if (text.length() > 3) { strings.add(new String[] { ((Element) node).tag().getName(), "text", text, ((Element) node).className(), node.attr("style") }); } } else if (subnode instanceof Element) { String text = ((Element) subnode).text().trim(); if (text.length() > 3) { strings.add(new String[] { ((Element) node).tag().getName(), ((Element) subnode).tag().getName(), text, ((Element) node).className(), node.attr("style") }); } } } } } StringBuilder description = new StringBuilder(); int k = 0; for (String[] part : strings) { if (part[0].equals("a") && k == 0) { description.append("<b>").append(part[2]).append("</b>"); } else if (k < 3) { description.append("<br />").append(part[2]); } k++; } sr.setInnerhtml(description.toString()); sr.setNr(10 * (page - 1) + i); sr.setId(null); results.add(sr); } resultcount = results.size(); return new SearchRequestResult(results, results_total, page); }
From source file:de.geeksfactory.opacclient.apis.IOpac.java
private SearchField createSearchField(Element descTd, Element inputTd) { String name = descTd.select("span, blockquote").text().replace(":", "").trim().replace("\u00a0", ""); if (inputTd.select("select").size() > 0 && !name.equals("Treffer/Seite") && !name.equals("Medientypen") && !name.equals("Medientyp") && !name.equals("Treffer pro Seite")) { Element select = inputTd.select("select").first(); DropdownSearchField field = new DropdownSearchField(); field.setDisplayName(name);/*from w w w. j a v a2 s .c om*/ field.setId(select.attr("name")); for (Element option : select.select("option")) { field.addDropdownValue(option.attr("value"), option.text()); } return field; } else if (inputTd.select("input").size() > 0) { TextSearchField field = new TextSearchField(); Element input = inputTd.select("input").first(); field.setDisplayName(name); field.setId(input.attr("name")); field.setHint(""); return field; } else { return null; } }
From source file:com.adarshahd.indianrailinfo.donate.TrainDetails.java
private void createTableLayoutTrainFare() { if (mPage.contains("SORRY")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Not a valid class, Please select a different class and try again."); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews();// w ww. j a v a 2s .co m mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ISL Of")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Station is not in ISL Of the Train. \nPlease modify the source/destination!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("ERROR")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Your request resulted in an error.\nPlease check!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("Network Connectivity")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Looks like the server is busy.\nPlease try later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mPage.contains("unavailable")) { TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText( "Response from server:\n\nYour request could not be processed now. \nPlease try again later!"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); textViewTrnDtls.setTextColor(Color.RED); mFrameLayout.removeAllViews(); mFrameLayout.addView(textViewTrnDtls); if (mDialog.isShowing()) { mDialog.cancel(); } return; } if (mDetails == null || !mDetails.getTrainNumber().equals(mTrainNumber)) { Iterator iterator = null; try { iterator = mElements.first().parent().parent().parent().getElementsByTag("tr").iterator(); } catch (Exception e) { Log.i("TrainDetails", mPage); } mListFr = new ArrayList<List<String>>(); List<String> list; Element tmp; while (iterator.hasNext()) { tmp = (Element) iterator.next(); list = new ArrayList<String>(); list.add(tmp.select("td").get(0).text()); list.add(tmp.select("td").get(1).text()); mListFr.add(list); } mDetails = new Details(mListFr, TrainEnquiry.FARE, mTrainNumber); } else { mListFr = mDetails.getList(); } mTblLayoutFr = new TableLayout(mActivity); TableRow row; TextView tv1, tv2; mTblLayoutFr.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); for (int i = 0; i < mListFr.size(); i++) { row = new TableRow(mActivity); tv1 = new TextView(mActivity); tv2 = new TextView(mActivity); tv1.setText(" " + mListFr.get(i).get(0)); tv2.setText(" " + mListFr.get(i).get(1)); tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv1.setPadding(5, 5, 5, 5); tv2.setPadding(5, 5, 5, 5); /*tv2.setBackgroundResource(R.drawable.card_divider); tv3.setBackgroundResource(R.drawable.card_divider); tv4.setBackgroundResource(R.drawable.card_divider);*/ row.addView(tv1); row.addView(tv2); row.setBackgroundResource(R.drawable.button_selector); row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); mTblLayoutFr.addView(row); } LinearLayout ll = new LinearLayout(mActivity); ScrollView scrollView = new ScrollView(mActivity); TextView textViewTrnDtls = new TextView(mActivity); textViewTrnDtls.setText("Fare details:"); textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large); textViewTrnDtls.setPadding(10, 10, 10, 10); ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(textViewTrnDtls); ll.addView(mTblLayoutFr); scrollView.addView(ll); mFrameLayout.removeAllViews(); mFrameLayout.addView(scrollView); if (mDialog.isShowing()) { mDialog.cancel(); } }
From source file:de.geeksfactory.opacclient.apis.Zones.java
private String getValue(Element node) { if (version18) { return node.child(4).text().trim(); } else {//from w w w . j a v a 2s. c o m return node.select(".SummaryFieldData").text(); } }
From source file:de.geeksfactory.opacclient.apis.Zones.java
private String getName(Element node) { if (version18) { return node.child(0).text().trim(); } else {/*w ww . j a va 2s . co m*/ return node.select(".SummaryFieldLegend").text(); } }
From source file:de.geeksfactory.opacclient.apis.IOpac.java
@Override public CancelResult cancel(String media, Account account, int useraction, String selection) throws IOException, OpacErrorException { String html = httpGet(opac_url + "/" + media, getDefaultEncoding()); Document doc = Jsoup.parse(html); try {// w w w . j a va 2s. co m Element form = doc.select("form[name=form1]").first(); String sessionid = form.select("input[name=sessionid]").attr("value"); String kndnr = form.select("input[name=kndnr]").attr("value"); String mednr = form.select("input[name=mednr]").attr("value"); httpGet(opac_url + "/cgi-bin/di.exe?mode=9&kndnr=" + kndnr + "&mednr=" + mednr + "&sessionid=" + sessionid + "&psh100=Stornieren", getDefaultEncoding()); return new CancelResult(MultiStepResult.Status.OK); } catch (Throwable e) { e.printStackTrace(); throw new NotReachableException(e.getMessage()); } }
From source file:de.geeksfactory.opacclient.apis.Heidi.java
private SearchRequestResult parse_search(String html, int page) { Document doc = Jsoup.parse(html); doc.setBaseUri(opac_url);/*from ww w . j a va2 s.c o m*/ int results_total = 0; if (doc.select("#heiditreffer").size() > 0) { String resstr = doc.select("#heiditreffer").text(); String resnum = resstr.replaceAll("\\(([0-9.]+)([^0-9]*)\\)", "$1").replace(".", ""); results_total = Integer.parseInt(resnum); } Elements table = doc.select("table.treffer tr"); List<SearchResult> results = new ArrayList<>(); for (int i = 0; i < table.size(); i++) { Element tr = table.get(i); SearchResult sr = new SearchResult(); StringBuilder description = null; String author = ""; for (Element link : tr.select("a")) { String kk = getQueryParamsFirst(link.absUrl("href")).get("katkey"); if (kk != null) { sr.setId(kk); break; } } if (tr.select("span.Z3988").size() == 1) { // Luckily there is a <span class="Z3988"> item which provides // data in a standardized format. List<NameValuePair> z3988data; boolean hastitle = false; try { description = new StringBuilder(); z3988data = URLEncodedUtils .parse(new URI("http://dummy/?" + tr.select("span.Z3988").attr("title")), "UTF-8"); for (NameValuePair nv : z3988data) { if (nv.getValue() != null) { if (!nv.getValue().trim().equals("")) { if (nv.getName().equals("rft.btitle") && !hastitle) { description.append("<b>").append(nv.getValue()).append("</b>"); hastitle = true; } else if (nv.getName().equals("rft.atitle") && !hastitle) { description.append("<b>").append(nv.getValue()).append("</b>"); hastitle = true; } else if (nv.getName().equals("rft.au")) { author = nv.getValue(); } else if (nv.getName().equals("rft.aufirst")) { author = author + ", " + nv.getValue(); } else if (nv.getName().equals("rft.aulast")) { author = nv.getValue(); } else if (nv.getName().equals("rft.date")) { description.append("<br />").append(nv.getValue()); } } } } } catch (URISyntaxException e) { description = null; } } if (!"".equals(author)) { author = author + "<br />"; } sr.setInnerhtml(author + description.toString()); if (tr.select(".kurzstat").size() > 0) { String stattext = tr.select(".kurzstat").first().text(); if (stattext.contains("ausleihbar")) { sr.setStatus(Status.GREEN); } else if (stattext.contains("online")) { sr.setStatus(Status.GREEN); } else if (stattext.contains("entliehen")) { sr.setStatus(Status.RED); } else if (stattext.contains("Prsenznutzung")) { sr.setStatus(Status.YELLOW); } else if (stattext.contains("bestellen")) { sr.setStatus(Status.YELLOW); } } if (tr.select(".typbild").size() > 0) { String typtext = tr.select(".typbild").first().text(); if (typtext.contains("Buch")) { sr.setType(MediaType.BOOK); } else if (typtext.contains("DVD-ROM")) { sr.setType(MediaType.CD_SOFTWARE); } else if (typtext.contains("Online-Ressource")) { sr.setType(MediaType.EDOC); } else if (typtext.contains("DVD")) { sr.setType(MediaType.DVD); } else if (typtext.contains("Film")) { sr.setType(MediaType.MOVIE); } else if (typtext.contains("Zeitschrift")) { sr.setType(MediaType.MAGAZINE); } else if (typtext.contains("Musiknoten")) { sr.setType(MediaType.SCORE_MUSIC); } else if (typtext.contains("Bildliche Darstellung")) { sr.setType(MediaType.ART); } else if (typtext.contains("Zeitung")) { sr.setType(MediaType.NEWSPAPER); } else if (typtext.contains("Karte")) { sr.setType(MediaType.MAP); } else if (typtext.contains("Mehrteilig")) { sr.setType(MediaType.PACKAGE_BOOKS); } } results.add(sr); } // TODO return new SearchRequestResult(results, results_total, page); }