Example usage for org.jsoup.nodes Element text

List of usage examples for org.jsoup.nodes Element text

Introduction

In this page you can find the example usage for org.jsoup.nodes Element text.

Prototype

public String text() 

Source Link

Document

Gets the combined text of this element and all its children.

Usage

From source file:tr.edu.gsu.nerwip.retrieval.reader.wikipedia.WikipediaReader.java

/**
 * Extract text and hyperlinks from an element
 * supposingly containing only text./*from  w  w  w  . j  a  v a 2 s  . com*/
 * 
 * @param textElement
 *       The element to be processed.
 * @param rawStr
 *       The StringBuffer to contain the raw text.
 * @param linkedStr
 *       The StringBuffer to contain the text with hyperlinks.
 */
private void processTextElement(Element textElement, StringBuilder rawStr, StringBuilder linkedStr) { // we process each element contained in the specified text element
    for (Node node : textElement.childNodes()) { // element node
        if (node instanceof Element) {
            Element element = (Element) node;
            String eltName = element.tag().getName();

            // section headers: same thing
            if (eltName.equals(XmlNames.ELT_H2) || eltName.equals(XmlNames.ELT_H3)
                    || eltName.equals(XmlNames.ELT_H4) || eltName.equals(XmlNames.ELT_H5)
                    || eltName.equals(XmlNames.ELT_H6)) {
                processParagraphElement(element, rawStr, linkedStr);
            }

            // paragraphs inside paragraphs are processed recursively
            else if (eltName.equals(XmlNames.ELT_P)) {
                processParagraphElement(element, rawStr, linkedStr);
            }

            // superscripts are to be avoided
            else if (eltName.equals(XmlNames.ELT_SUP)) { // they are either external references or WP inline notes
                                                         // cf. http://en.wikipedia.org/wiki/Template%3ACitation_needed
            }

            // small caps are placed before phonetic transcriptions of names, which we avoid
            else if (eltName.equals(XmlNames.ELT_SMALL)) { // we don't need them, and they can mess up NER tools
            }

            // we ignore certain types of span (phonetic trancription, WP buttons...) 
            else if (eltName.equals(XmlNames.ELT_SPAN)) {
                processSpanElement(element, rawStr, linkedStr);
            }

            // hyperlinks must be included in the linked string, provided they are not external
            else if (eltName.equals(XmlNames.ELT_A)) {
                processHyperlinkElement(element, rawStr, linkedStr);
            }

            // lists
            else if (eltName.equals(XmlNames.ELT_UL)) {
                processListElement(element, rawStr, linkedStr, false);
            } else if (eltName.equals(XmlNames.ELT_OL)) {
                processListElement(element, rawStr, linkedStr, true);
            } else if (eltName.equals(XmlNames.ELT_DL)) {
                processDescriptionListElement(element, rawStr, linkedStr);
            }

            // list item
            else if (eltName.equals(XmlNames.ELT_LI)) {
                processTextElement(element, rawStr, linkedStr);
            }

            // divisions are just processed recursively
            else if (eltName.equals(XmlNames.ELT_DIV)) {
                processDivisionElement(element, rawStr, linkedStr);
            }

            // quotes are just processed recursively
            else if (eltName.equals(XmlNames.ELT_BLOCKQUOTE)) {
                processQuoteElement(element, rawStr, linkedStr);
            }
            // citation
            else if (eltName.equals(XmlNames.ELT_CITE)) {
                processParagraphElement(element, rawStr, linkedStr);
            }

            // other elements are considered as simple text
            else {
                String text = element.text();
                rawStr.append(text);
                linkedStr.append(text);
            }
        }

        // text node
        else if (node instanceof TextNode) { // get the text
            TextNode textNode = (TextNode) node;
            String text = textNode.text();
            // if at the begining of a new line, or already preceeded by a space, remove leading spaces
            while (rawStr.length() > 0
                    && (rawStr.charAt(rawStr.length() - 1) == '\n' || rawStr.charAt(rawStr.length() - 1) == ' ')
                    && text.startsWith(" "))
                text = text.substring(1);
            // complete string buffers
            rawStr.append(text);
            linkedStr.append(text);
        }
    }
}

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 {/*  ww  w. ja va 2 s  .  co m*/
        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:com.storm.function.GsxtFunction.java

private Map<String, Object> getHtmlInfoMapOfJilin(String area, String keyword, ChannelLogger LOGGER)
        throws Exception {

    Map<String, Object> resultHtmlMap = new LinkedHashMap<String, Object>();

    String[] command = { "casperjs", "/home/ubuntu/nfs-images/casperjscode/jilin.js", "--web-security=no",
            "--keyword=" + keyword };
    String casperjsResult = CommandUtil.runCommand(command);

    Elements divDataItems = Jsoup.parse(casperjsResult).getElementsByClass("list");
    Elements divNoDataItems = Jsoup.parse(casperjsResult).getElementsByClass("list-a");

    if (divDataItems.isEmpty() && !divNoDataItems.isEmpty()) { // ?
        resultHtmlMap.put("statusCodeDef", StatusCodeDef.NO_DATA_FOUND);
    } else if (divDataItems.isEmpty() && divDataItems.isEmpty()) { // ??
        // ????/*from  w w w. j av  a2s .c  o  m*/
        if (casperjsResult.contains("")) {
            resultHtmlMap.put("statusCodeDef", StatusCodeDef.IMAGECODE_ERROR);
        } else {
            resultHtmlMap.put("statusCodeDef", StatusCodeDef.FAILURE);
        }
    } else if (!divDataItems.isEmpty() && divNoDataItems.isEmpty()) { // ?
        // ???????
        Element nowCookies = Jsoup.parse(casperjsResult).getElementById("nextParams");
        Elements tokenEts = Jsoup.parse(casperjsResult).getElementsByAttributeValue("name", "_csrf");
        if (null == nowCookies || null == tokenEts || tokenEts.isEmpty()) {
            resultHtmlMap.put("statusCodeDef", StatusCodeDef.COOKIE_ERROR);
            return resultHtmlMap;
        }
        String nowCookiesJson = nowCookies.text().trim();
        String nowCookiesStr = ((String) new GsonBuilder().create().fromJson(nowCookiesJson, Map.class)
                .get("Cookie")).trim();
        String tokenStr = tokenEts.get(0).attr("content");
        String HOST_OF_JILIN = "http://211.141.74.198:8081/aiccips/pub/";
        String HOST_OF_XQ = "http://211.141.74.198:8081/";
        String htmlAnchorHref = "";
        for (Element divDataItem : divDataItems) {
            Element htmlAnchor = divDataItem.getElementsByTag("a").get(0);
            String htmlAnchorText = htmlAnchor.text();
            if (htmlAnchorText.contains(keyword)) {
                htmlAnchorHref = HOST_OF_JILIN + htmlAnchor.attr("href");
                break;
            }
        }
        if (StringUtils.isEmpty(htmlAnchorHref)) {
            htmlAnchorHref = "http://211.141.74.198:8081/aiccips/pub/"
                    + divDataItems.get(0).getElementsByTag("a").get(0).attr("href");
        }
        String commonUrl = htmlAnchorHref.split("gsgsdetail")[1];
        String commonUrlZ = htmlAnchorHref.substring(htmlAnchorHref.lastIndexOf("/") + 1,
                htmlAnchorHref.length());

        // ?->?
        String[] command11 = { "casperjs", "/home/ubuntu/nfs-images/casperjscode/getSimpleRequestPage.js",
                "--web-security=no", "--url=" + htmlAnchorHref };
        String casperjsResult11 = CommandUtil.runCommand(command11);
        resultHtmlMap.put("gsgsxx", casperjsResult11);
        Thread.sleep(1000);

        // ?->?->??
        String baxxZyryxxUrl = HOST_OF_JILIN + "gsryxx/1151?encrpripid=" + commonUrlZ;
        String[] command121 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + htmlAnchorHref, "--tokenStr=" + tokenStr,
                "--url=" + baxxZyryxxUrl };
        String casperjsResult121 = CommandUtil.runCommand(command121);
        resultHtmlMap.put("gsgsxx_baxx_zyryxx", casperjsResult121);

        // ?->?->?
        String baxxFzjgxxUrl = HOST_OF_JILIN + "gsfzjg/1151?encrpripid=" + commonUrlZ;
        String[] command123 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + htmlAnchorHref, "--tokenStr=" + tokenStr,
                "--url=" + baxxFzjgxxUrl };
        String casperjsResult123 = CommandUtil.runCommand(command123);
        resultHtmlMap.put("gsgsxx_baxx_fzjgxx", casperjsResult123);

        // ?->?->?
        String dcdydjxxDcdydjxxUrl = HOST_OF_JILIN + "gsdcdy?encrpripid=" + commonUrlZ;
        String[] command131 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + htmlAnchorHref, "--tokenStr=" + tokenStr,
                "--url=" + dcdydjxxDcdydjxxUrl };
        String casperjsResult131 = CommandUtil.runCommand(command131);
        resultHtmlMap.put("gsgsxx_dcdydjxx_dcdydjxx", casperjsResult131);

        // ?->??->??
        String gqczdjxxGqczdjxxUrl = HOST_OF_JILIN + "gsgqcz?encrpripid=" + commonUrlZ;
        String[] command141 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + htmlAnchorHref, "--tokenStr=" + tokenStr,
                "--url=" + gqczdjxxGqczdjxxUrl };
        String casperjsResult141 = CommandUtil.runCommand(command141);
        resultHtmlMap.put("gsgsxx_gqczdjxx_gqczdjxx", casperjsResult141);

        // ?->?->?
        String xzcfxxXzcfxxUrl = HOST_OF_JILIN + "gsxzcfxx?encrpripid=" + commonUrlZ;
        String[] command151 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + htmlAnchorHref, "--tokenStr=" + tokenStr,
                "--url=" + xzcfxxXzcfxxUrl };
        String casperjsResult151 = CommandUtil.runCommand(command151);
        resultHtmlMap.put("gsgsxx_xzcfxx_xzcfxx", casperjsResult151);

        // ?->???->???
        String jyycxxJyycxxUrl = HOST_OF_JILIN + "jyyc/1151?encrpripid=" + commonUrlZ;
        String[] command161 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + htmlAnchorHref, "--tokenStr=" + tokenStr,
                "--url=" + jyycxxJyycxxUrl };
        String casperjsResult161 = CommandUtil.runCommand(command161);
        resultHtmlMap.put("gsgsxx_jyycxx_jyycxx", casperjsResult161);

        // ?->???->???
        String yzwfxxYzwfxxUrl = HOST_OF_JILIN + "yzwfqy?encrpripid=" + commonUrlZ;
        String[] command171 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + htmlAnchorHref, "--tokenStr=" + tokenStr,
                "--url=" + yzwfxxYzwfxxUrl };
        String casperjsResult171 = CommandUtil.runCommand(command171);
        resultHtmlMap.put("gsgsxx_yzwfxx_yzwfxx", casperjsResult171);

        // ?->?->?
        String ccjcxxCcjcxxUrl = HOST_OF_JILIN + "ccjcxx?encrpripid=" + commonUrlZ;
        String[] command181 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + htmlAnchorHref, "--tokenStr=" + tokenStr,
                "--url=" + ccjcxxCcjcxxUrl };
        String casperjsResult181 = CommandUtil.runCommand(command181);
        resultHtmlMap.put("gsgsxx_ccjcxx_ccjcxx", casperjsResult181);

        // ??
        String qygsUrl = HOST_OF_JILIN + "qygsdetail" + commonUrl;
        String[] command2 = { "casperjs", "/home/ubuntu/nfs-images/casperjscode/getSimpleRequestPage.js",
                "--web-security=no", "--url=" + qygsUrl };
        String casperjsResult2 = CommandUtil.runCommand(command2);
        resultHtmlMap.put("qygsxx_list", casperjsResult2);

        // ? ??->?->
        Document qygsxxHtml = Jsoup.parseBodyFragment(casperjsResult2);
        Element qynbDiv = qygsxxHtml.getElementById("qiyenianbao");
        if (null != qynbDiv) {
            Elements qynb_trs = qynbDiv.select("tbody").get(0).select("tr");
            if (null != qynb_trs && qynb_trs.size() > 2) {
                List<Map<String, Object>> qygsxx_qynb_infos = new ArrayList<Map<String, Object>>();
                for (int i = 2; i < qynb_trs.size(); i++) {
                    Map<String, Object> qygsxx_qynb_info_map = new LinkedHashMap<String, Object>();
                    Element wdd = qynb_trs.get(i).select("td").get(1).select("a").get(0);
                    String qygsxx_qynb_list_a_text = wdd.text();
                    String qygsxx_qynb_list_pubdate = qynb_trs.get(i).select("td").get(2).text();
                    qygsxx_qynb_info_map.put("qygsxx_qynb_list_a_text", qygsxx_qynb_list_a_text);
                    qygsxx_qynb_info_map.put("qygsxx_qynb_list_pubdate", qygsxx_qynb_list_pubdate);
                    String qynbxqUrl = HOST_OF_XQ + wdd.attr("href");
                    String[] command21 = { "casperjs",
                            "/home/ubuntu/nfs-images/casperjscode/getSimpleRequestPage.js", "--web-security=no",
                            "--url=" + qynbxqUrl };
                    String casperjsResult21 = CommandUtil.runCommand(command21);
                    qygsxx_qynb_info_map.put("qygsxx_qynb_info_page", casperjsResult21);
                    qygsxx_qynb_infos.add(qygsxx_qynb_info_map);
                }
                resultHtmlMap.put("qygsxx_qynb_infos", qygsxx_qynb_infos);
            }
        }
        Thread.sleep(1000);

        // ??->??->??
        String gdjczxxGdjczxxUrl = HOST_OF_JILIN + "qygsjsxxxzczxx?encrpripid=" + commonUrlZ;
        String[] command221 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + qygsUrl, "--tokenStr=" + tokenStr,
                "--url=" + gdjczxxGdjczxxUrl };
        String casperjsResult221 = CommandUtil.runCommand(command221);
        resultHtmlMap.put("qygsxx_gdjczxx_gdjczxx", casperjsResult221);

        // ??->??->??
        String gdjczxxBgxxUrl = HOST_OF_JILIN + "qygsjsxxczxxbgsx?encrpripid=" + commonUrlZ;
        String[] command222 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + qygsUrl, "--tokenStr=" + tokenStr,
                "--url=" + gdjczxxBgxxUrl };
        String casperjsResult222 = CommandUtil.runCommand(command222);
        resultHtmlMap.put("qygsxx_gdjczxx_bgxx", casperjsResult222);

        // ??->???->???
        String gqbgxxGqbgxxUrl = HOST_OF_JILIN + "qygsJsxxgqbg?encrpripid=" + commonUrlZ;
        String[] command231 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + qygsUrl, "--tokenStr=" + tokenStr,
                "--url=" + gqbgxxGqbgxxUrl };
        String casperjsResult231 = CommandUtil.runCommand(command231);
        resultHtmlMap.put("qygsxx_gqbgxx_gqbgxx", casperjsResult231);

        // ??->??->??
        String xzxkxxXzxkxxUrl = HOST_OF_JILIN + "qygsjsxxxzxk?encrpripid=" + commonUrlZ;
        String[] command241 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + qygsUrl, "--tokenStr=" + tokenStr,
                "--url=" + xzxkxxXzxkxxUrl };
        String casperjsResult241 = CommandUtil.runCommand(command241);
        resultHtmlMap.put("qygsxx_xzxkxx_xzxkxx", casperjsResult241);

        // ??->??->??
        String zscqczZscqczUrl = HOST_OF_JILIN + "/qygsjsxxzscqcz?encrpripid=" + commonUrlZ;
        String[] command251 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + qygsUrl, "--tokenStr=" + tokenStr,
                "--url=" + zscqczZscqczUrl };
        String casperjsResult251 = CommandUtil.runCommand(command251);
        resultHtmlMap.put("qygsxx_zscqcz_zscqcz", casperjsResult251);

        // ??->?->?
        String qygsxxXzcfxxUrl = HOST_OF_JILIN + "qygsjsxxxzcfxx?encrpripid=" + commonUrlZ;
        String[] command261 = { "casperjs",
                "/home/ubuntu/nfs-images/casperjscode/postJilinSimpleRequestPage.js", "--web-security=no",
                "--cookieStr=" + nowCookiesStr, "--refererStr=" + qygsUrl, "--tokenStr=" + tokenStr,
                "--url=" + qygsxxXzcfxxUrl };
        String casperjsResult261 = CommandUtil.runCommand(command261);
        resultHtmlMap.put("qygsxx_zscqcz_zscqcz", casperjsResult261);

        // ?
        String qtbmUrl = HOST_OF_JILIN + "qtgsdetail" + commonUrl;
        String[] command3 = { "casperjs", "/home/ubuntu/nfs-images/casperjscode/getSimpleRequestPage.js",
                "--web-security=no", "--url=" + qtbmUrl };
        String casperjsResult3 = CommandUtil.runCommand(command3);
        resultHtmlMap.put("qtbmgsxx", casperjsResult3);

        // ????
        String sfxzUrl = HOST_OF_JILIN + "sfgsdetail" + commonUrl;
        String[] command4 = { "casperjs", "/home/ubuntu/nfs-images/casperjscode/getSimpleRequestPage.js",
                "--web-security=no", "--url=" + sfxzUrl };
        String casperjsResult4 = CommandUtil.runCommand(command4);
        resultHtmlMap.put("sfxzgsxx_list", casperjsResult4);

        resultHtmlMap.put("statusCodeDef", StatusCodeDef.SCCCESS);

    }

    return resultHtmlMap;

}

From source file:com.dalthed.tucan.scraper.SingleEventScraper.java

@Override
public ListAdapter scrapeAdapter(int mode) throws LostSessionException, TucanDownException {
    if (checkForLostSeesion()) {
        if (PREPCall == false) {

            if (checkforModule()) {
                return null;
            }//from   w  w  w.  j a  va 2s.co  m
            String Title = doc.select("h1").text().replace("\n", " ");
            if (fsh != null) {
                fsh.setSubtitle(Title);
            }

            Iterator<Element> captionIt = doc.select("caption").iterator();
            Iterator<Element> dateTable = null;
            Iterator<Element> materialTable = null;
            Iterator<Element> informationTable = null;
            while (captionIt.hasNext()) {
                Element next = captionIt.next();
                if (next.text().equals("Termine")) {

                    dateTable = next.parent().select("tr").iterator();
                } else if (next.text().contains("Material")) {

                    materialTable = next.parent().select("tr").iterator();
                } else if (next.text().contains("Veranstaltungsdetails")) {
                    informationTable = next.parent().select("tr").iterator();
                }
            }

            scrapeInformations(informationTable);
            scrapeAppointments(dateTable);

            scrapeMaterials(materialTable);
            if (mPageAdapter != null) {
                mPageAdapter.initializeData(mPager);
            }

        } else {
            // Es handelt sich um eine bersichtsseite zu einem einzelnen
            // Termin
            callRealEventPage();

        }
    }
    return null;
}

From source file:com.develop.autorus.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Fabric.with(this, new Crashlytics());
    super.onCreate(savedInstanceState);
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

    AnalyticsApplication application = (AnalyticsApplication) getApplication();
    mTracker = application.getDefaultTracker();
    mTracker.setScreenName("Main activity");
    mTracker.send(new HitBuilders.ScreenViewBuilder().build());

    if (pref.getBoolean("notificationIsActive", true)) {
        Intent checkIntent = new Intent(getApplicationContext(), MonitoringWork.class);
        Boolean alrarmIsActive = false;
        if (PendingIntent.getService(getApplicationContext(), 0, checkIntent,
                PendingIntent.FLAG_NO_CREATE) != null)
            alrarmIsActive = true;/*ww w. j a  v a2  s.  c o  m*/
        am = (AlarmManager) getSystemService(ALARM_SERVICE);

        if (!alrarmIsActive) {
            Intent serviceIntent = new Intent(getApplicationContext(), MonitoringWork.class);
            PendingIntent pIntent = PendingIntent.getService(getApplicationContext(), 0, serviceIntent, 0);

            int period = pref.getInt("numberOfActiveMonitors", 0) * 180000;

            if (period != 0)
                am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + period,
                        period, pIntent);
        }
    }

    /*ForEasyDelete
            
    //Danger! Auchtung! ?, !!!
    String base64EncodedPublicKey =
        "<your license key here>";//?   . !!! ? ,    
    // github ?  .         ?!!!
            
    mHelper = new IabHelper(this, base64EncodedPublicKey);
            
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
    public void onIabSetupFinished(IabResult result) {
        if (!result.isSuccess()) {
            Log.d(TAG, "In-app Billing setup failed: " +
                    result);
        } else {
            Log.d(TAG, "In-app Billing is set up OK");
        }
    }
    });
    */

    //Service inapp
    Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    intent.setPackage("com.android.vending");
    blnBind = bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);

    String themeName = pref.getString("theme", "1");

    if (themeName.equals("1")) {
        setTheme(R.style.AppTheme);
        if (android.os.Build.VERSION.SDK_INT >= 21) {
            Window statusBar = getWindow();
            statusBar.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            statusBar.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            statusBar.setStatusBarColor(getResources().getColor(R.color.myPrimaryDarkColor));
        }
    } else if (themeName.equals("2")) {
        setTheme(R.style.AppTheme2);
        if (android.os.Build.VERSION.SDK_INT >= 21) {
            Window statusBar = getWindow();
            statusBar.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            statusBar.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            statusBar.setStatusBarColor(getResources().getColor(R.color.myPrimaryDarkColor2));
        }
    }
    ThemeManager.init(this, 2, 0, null);

    if (isFirstLaunch) {
        SQLiteDatabase db = new DbHelper(this).getWritableDatabase();
        Cursor cursorMonitors = db.query("monitors", null, null, null, null, null, null);
        Boolean monitorsExist = cursorMonitors != null && cursorMonitors.getCount() > 0;
        db.close();

        if (getSupportFragmentManager().findFragmentByTag("MAIN") == null) {
            FragmentTransaction fTrans = getSupportFragmentManager().beginTransaction();
            if (monitorsExist)
                mainFragment = SearchAndMonitorsFragment.newInstance(0);
            else
                mainFragment = SearchAndMonitorsFragment.newInstance(1);
            fTrans.add(R.id.container, mainFragment, "MAIN").commit();
        } else {
            mainFragment = (SearchAndMonitorsFragment) getSupportFragmentManager().findFragmentByTag("MAIN");
            if (getSupportFragmentManager().findFragmentByTag("Second") != null) {
                FragmentTransaction fTrans = getSupportFragmentManager().beginTransaction();
                fTrans.remove(getSupportFragmentManager().findFragmentByTag("Second")).commit();
            }
            pref.edit().remove("NumberOfCallingFragment");
        }
    }

    backToast = Toast.makeText(this, "?   ? ", Toast.LENGTH_SHORT);
    setContentView(R.layout.main_activity);
    mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    mSnackBar = (SnackBar) findViewById(R.id.main_sn);
    setSupportActionBar(mToolbar);

    addMonitorButton = (Button) findViewById(R.id.toolbar_add_monitor_button);

    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.fragment_drawer);
    mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);

    Thread threadAvito = new Thread(new Runnable() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        public void run() {
            Document doc;
            SharedPreferences sPref;
            try {
                String packageName = getApplicationContext().getPackageName();
                doc = Jsoup.connect("https://play.google.com/store/apps/details?id=" + packageName).userAgent(
                        "Mozilla/5.0 (Windows; U; WindowsNT 5.1; ru-RU; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                        .timeout(12000).get();
                //"")

                PackageManager packageManager;
                PackageInfo packageInfo;
                packageManager = getPackageManager();

                packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
                Element mainElems = doc.select(
                        "#body-content > div > div > div.main-content > div.details-wrapper.apps-secondary-color > div > div.details-section-contents > div:nth-child(4) > div.content")
                        .first();

                if (!packageInfo.versionName.equals(mainElems.text())) {
                    sPref = getPreferences(MODE_PRIVATE);
                    SharedPreferences.Editor ed = sPref.edit();
                    ed.putBoolean(SAVED_TEXT_WITH_VERSION, false);
                    ed.commit();
                } else {
                    sPref = getPreferences(MODE_PRIVATE);
                    SharedPreferences.Editor ed = sPref.edit();
                    ed.putBoolean(SAVED_TEXT_WITH_VERSION, true);
                    ed.commit();

                }
                //SharedPreferences sPrefRemind;
                //sPrefRemind = getPreferences(MODE_PRIVATE);
                //sPrefRemind.edit().putBoolean(DO_NOT_REMIND, false).commit();
            } catch (HttpStatusException e) {
                return;
            } catch (IOException e) {
                return;
            } catch (PackageManager.NameNotFoundException e) {

                e.printStackTrace();
            }
        }
    });

    SharedPreferences sPrefVersion;
    sPrefVersion = getPreferences(MODE_PRIVATE);
    Boolean isNewVersion;
    isNewVersion = sPrefVersion.getBoolean(SAVED_TEXT_WITH_VERSION, true);

    threadAvito.start();
    boolean remind = true;
    if (!isNewVersion) {
        Log.d("affa", "isNewVersion= " + isNewVersion);
        SharedPreferences sPref12;
        sPref12 = getPreferences(MODE_PRIVATE);
        String isNewVersion12;

        PackageManager packageManager;
        PackageInfo packageInfo;
        packageManager = getPackageManager();

        try {
            packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
            isNewVersion12 = sPref12.getString("OldVersionName", packageInfo.versionName);

            if (!isNewVersion12.equals(packageInfo.versionName)) {
                SharedPreferences sPref;
                sPref = getPreferences(MODE_PRIVATE);
                SharedPreferences.Editor ed = sPref.edit();
                ed.putBoolean(SAVED_TEXT_WITH_VERSION, false);
                ed.commit();

                SharedPreferences sPrefRemind;
                sPrefRemind = getPreferences(MODE_PRIVATE);
                sPrefRemind.edit().putBoolean(DO_NOT_REMIND, false).commit();
            } else
                remind = false;

            SharedPreferences sPrefRemind;
            sPrefRemind = getPreferences(MODE_PRIVATE);
            sPrefRemind.edit().putString("OldVersionName", packageInfo.versionName).commit();
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        SharedPreferences sPrefRemind;
        sPrefRemind = getPreferences(MODE_PRIVATE);
        Boolean dontRemind;
        dontRemind = sPrefRemind.getBoolean(DO_NOT_REMIND, false);
        Log.d("affa", "dontRemind= " + dontRemind.toString());
        Log.d("affa", "remind= " + remind);
        Log.d("affa", "44444444444444444444444= ");
        if ((!dontRemind) && (!remind)) {
            Log.d("affa", "5555555555555555555555555= ");
            SimpleDialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    super.onPositiveActionClicked(fragment);
                    String packageName = getApplicationContext().getPackageName();
                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/details?id=" + packageName));
                    startActivity(intent);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                }

                @Override
                public void onNeutralActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                    SharedPreferences sPrefRemind;
                    sPrefRemind = getPreferences(MODE_PRIVATE);
                    sPrefRemind.edit().putBoolean(DO_NOT_REMIND, true).commit();
                }
            };

            builder.message(
                    "  ??   ? ? ?")
                    .title(" !").positiveAction("")
                    .negativeAction("").neutralAction("? ");
            DialogFragment fragment = DialogFragment.newInstance(builder);
            fragment.show(getSupportFragmentManager(), null);
        }
    }
}

From source file:com.jp.miaulavirtual.DisplayMessageActivity.java

public void asigsToArray(Elements melem, Boolean isHome, Boolean comun) throws IndexOutOfBoundsException {
    int i = 1;/*  ww w  .j a  v a2s.c  o  m*/
    Elements elem;
    if (isHome) {
        elem = melem.select("td[headers=contents_name] a, td[headers=folders_name] a").not("[href*=/clubs/]"); //Nombre Asignaturas String !"Comunuidades"
        names = new String[(elem.size()) + 1]; //todo-comunidades + 1(carpeta comunidades)
        names[0] = "Comunidades y otros";
        for (Element el : elem) {
            names[i] = el.text();
            i++;
        }
    } else if (comun) {
        elem = melem.select(
                "td[headers=contents_name] a[href*=/clubs/], td[headers=folders_name] a[href*=/clubs/]"); //Nombre Asignaturas String "Comunuidades"
        names = new String[elem.size() + 1]; //comunidades + 1(atrs)
        names[0] = "Atrs " + onData.get(onData.size() - 2)[1];
        for (Element el : elem) {
            names[i] = el.text();
            i++;
        }
    } else {
        elem = melem.select("td[headers=contents_name] a[href], td[headers=folders_name] a[href]"); //Nombre Asignaturas String 
        names = new String[elem.size() + 1]; //todo + 1 (atrs)
        names[0] = "Atrs " + onData.get(onData.size() - 2)[1];
        for (Element el : elem) {
            names[i] = el.text();
            i++;
        }
    }
    Log.d("asigseToArray", String.valueOf(elem.size()));
}

From source file:com.jp.miaulavirtual.DisplayMessageActivity.java

public void typeToArray(Elements melem, Boolean isHome, Boolean comun, int size) {
    Elements elem = melem.select("td[headers=folders_type], td[headers=contents_type]"); //Nombre Asignaturas String
    String[] mtypes = { "carpeta", "Carpeta", "PDF", "Microsoft Excel", "Microsoft PowerPoint",
            "Microsoft Word" };
    int i = 1;//from  www .  j a  v  a  2  s  .c  om
    if (isHome) {
        types = new String[size];
        types[0] = "6";
        while (i < size) {
            types[i] = "1";
            i++;
        }
    } else if (comun && onData.size() < 3) {
        types = new String[size];
        types[0] = "0";
        while (i < size) {
            types[i] = "6";
            i++;
        }
    } else {
        types = new String[elem.size() + 1];
        types[0] = "0";
        for (Element el : elem) {
            String the_types = el.text().trim();
            types[i] = "7"; // Defecto al menos que...:
            if (mtypes[0].equals(the_types.toString()) || mtypes[1].equals(the_types.toString()))
                types[i] = "1"; // 1 = Carpeta
            if (mtypes[2].equals(the_types.toString()))
                types[i] = "2"; // 2 = PDF 
            if (mtypes[3].equals(the_types.toString()))
                types[i] = "3"; // 3 = Excel
            if (mtypes[4].equals(the_types.toString()))
                types[i] = "4"; // 4 = Power Point
            if (mtypes[5].equals(the_types.toString()))
                types[i] = "5"; // 5 = Word
            i++;
        }
    }
}

From source file:com.licubeclub.zionhs.MainActivity.java

void networkTask() {
    SRL.setRefreshing(true);//from w ww . j av a2  s .c o m
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
        }
    };

    final Handler mHandler = new Handler();
    new Thread() {

        public void run() {
            mHandler.post(new Runnable() {

                public void run() {
                    // SRL.setRefreshing(true);
                }
            });
            try {
                lunchstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "2"); //Get Lunch Menu Date
                dinnerstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "3"); //Get Dinner Menu Date
            } catch (Exception e) {
            }

            try {
                int skipcount = 0;
                boolean skipped = false;
                schedulearray = new ArrayList<String>();
                dayarray = new ArrayList<String>();

                //                    ? ?? ? ??  
                Document doc = Jsoup.connect(URL).get();

                Elements rawdaydata = doc.select(".listDay"); //Get contents from the class,"listDay"
                for (Element el : rawdaydata) {
                    String daydata = el.text();
                    if (daydata.equals("") | daydata == null) {
                        if (skipped) {
                        } else {
                            skipcount++;
                        }
                    } else {
                        dayarray.add(daydata); // add value to ArrayList
                        skipped = true;
                    }
                }
                Log.d("Schedule", "Parsed Day Array" + dayarray);

                Elements rawscheduledata = doc.select(".listData"); //Get contents from tags,"a" which are in the class,"ellipsis"
                for (Element el : rawscheduledata) {
                    String scheduledata = el.text();
                    if (skipcount > 0) {
                        skipcount--;
                    } else {
                        schedulearray.add(scheduledata); // add value to ArrayList
                    }
                }
                Log.d("Schedule", "Parsed Schedule Array" + schedulearray);
                //                    SRL.setRefreshing(false);
            } catch (IOException e) {
                e.printStackTrace();
                //                    SRL.setRefreshing(false);

            }
            try {
                titlearray_np = new ArrayList<String>();
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=59")
                        .get();
                Elements rawdata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody"
                String titlestring = rawdata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                for (Element el : rawdata) {
                    String titledata = el.attr("title");
                    titlearray_np.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Array Strings" + titlearray_np);

            } catch (IOException e) {
                e.printStackTrace();

            }
            //Notices URL
            try {
                titlearray_n = new ArrayList<String>();
                // ? URL
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?" + "menugrp=110100&master=bbs&act=list&master_sid=58")
                        .get();
                //Get contents from tags,"a" which are in the class,"listbody"
                Elements rawmaindata = doc.select(".listbody a");
                String titlestring = rawmaindata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                // ??  ?
                for (Element el : rawmaindata) {
                    String titledata = el.attr("title");
                    titlearray_n.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Array Strings" + titlearray_n);

            } catch (IOException e) {
                e.printStackTrace();

            }

            mHandler.post(new Runnable() {
                public void run() {
                    //                        progressDialog.dismiss();
                    //                        SRL.setRefreshing(false);
                    if (AMorPM == Calendar.AM) {
                        MealString = lunchstring[DAYofWEEK - 1];
                    } else {
                        MealString = dinnerstring[DAYofWEEK - 1];
                    }
                    try {
                        ScheduleString = schedulearray.get(DAYofMONTH - 1);
                        NoticesParentString = titlearray_np.get(0);
                        NoticeString = titlearray_n.get(0);
                    } catch (Exception e) {
                        ScheduleString = getResources().getString(R.string.error);
                        NoticesParentString = getResources().getString(R.string.error);
                        NoticeString = getResources().getString(R.string.error);
                    }

                    if (MealString == null) {
                        MealString = getResources().getString(R.string.nodata);
                    } else if (MealString.equals("")) {
                        MealString = getResources().getString(R.string.nodata);
                    }
                    if (ScheduleString == null) {
                        ScheduleString = getResources().getString(R.string.nodata);
                    } else if (ScheduleString.equals("")) {
                        ScheduleString = getResources().getString(R.string.nodata);
                    }
                    SRL.setRefreshing(false);
                    handler.sendEmptyMessage(0);
                    setContentData();
                }
            });

        }
    }.start();

}

From source file:com.licubeclub.zionhs.Notices.java

private void networkTask() {
    NetworkChecker NetCheck = new NetworkChecker(Notices.this);
    if (NetCheck.isNetworkConnected()) {
        final Handler mHandler = new Handler();
        new Thread() {

            public void run() {

                mHandler.post(new Runnable() {

                    public void run() {
                        SRL.setRefreshing(true);
                    }//from  w  ww  . jav  a 2 s .  c o m
                });

                //Task

                //Notices URL
                try {
                    titlearray = new ArrayList<String>();
                    titleherfarray = new ArrayList<String>();
                    authorarray = new ArrayList<String>();
                    datearray = new ArrayList<String>();
                    // ? URL
                    Document doc = Jsoup.connect(url).get();
                    Elements rawmaindata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody"
                    Elements rawauthordata = doc.select("td:eq(3)"); //? ?  - 3 td ? 
                    Elements rawdatedata = doc.select("td:eq(4)"); // ?  - 4 td ? 
                    String titlestring = rawmaindata.toString();
                    Log.i("Notices", "Parsed Strings" + titlestring);

                    // ??  ?
                    for (Element el : rawmaindata) {
                        String titlherfedata = el.attr("href");
                        String titledata = el.attr("title");
                        titleherfarray.add("http://www.zion.hs.kr/" + titlherfedata); // add value to ArrayList
                        titlearray.add(titledata); // add value to ArrayList
                    }
                    Log.i("Notices", "Parsed Link Array Strings" + titleherfarray);
                    Log.i("Notices", "Parsed Array Strings" + titlearray);

                    for (Element el : rawauthordata) {
                        String authordata = el.text();
                        Log.d("Author", el.text());
                        authorarray.add(authordata);
                    }
                    for (Element el : rawdatedata) {
                        String datedata = el.text();
                        Log.d("Date", el.text());
                        datearray.add(datedata);
                    }

                } catch (IOException e) {
                    e.printStackTrace();

                }

                mHandler.post(new Runnable() {
                    public void run() {
                        //UI Task
                        // ? 
                        adapter = new PostListAdapter(Notices.this, titlearray, datearray, authorarray);
                        listview.setAdapter(adapter);
                        listview.setOnItemClickListener(GoToWebPage);
                        handler.sendEmptyMessage(0);
                        SRL.setRefreshing(false);

                        Toast.makeText(getApplicationContext(), getResources().getString(R.string.recent),
                                Toast.LENGTH_LONG).show();
                    }
                });

            }
        }.start();
    } else {
        Toast.makeText(getApplicationContext(), getString(R.string.network_connection_warning),
                Toast.LENGTH_LONG).show();
    }

}

From source file:com.licubeclub.zionhs.Notices_Parents.java

private void networkTask() {
    final Handler mHandler = new Handler();
    new Thread() {

        public void run() {

            mHandler.post(new Runnable() {

                public void run() {
                    SRL.setRefreshing(true);
                }/* w w w. jav a  2 s.  co  m*/
            });

            //Task

            //Notices URL
            try {
                titlearray = new ArrayList<String>();
                titleherfarray = new ArrayList<String>();
                authorarray = new ArrayList<String>();
                datearray = new ArrayList<String>();
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=59")
                        .get();
                Elements rawdata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody"
                Elements rawauthordata = doc.select("td:eq(3)"); //? ?  - 3 td ? 
                Elements rawdatedata = doc.select("td:eq(4)"); // ?  - 4 td ? 

                String titlestring = rawdata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                for (Element el : rawdata) {
                    String titlherfedata = el.attr("href");
                    String titledata = el.attr("title");
                    titleherfarray.add("http://www.zion.hs.kr/" + titlherfedata); // add value to ArrayList
                    titlearray.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Link Array Strings" + titleherfarray);
                Log.i("Notices", "Parsed Array Strings" + titlearray);

                for (Element el : rawauthordata) {
                    String authordata = el.text();
                    Log.d("Author", el.text());
                    authorarray.add(authordata);
                }
                for (Element el : rawdatedata) {
                    String datedata = el.text();
                    Log.d("Date", el.text());
                    datearray.add(datedata);
                }

            } catch (IOException e) {
                e.printStackTrace();

            }

            mHandler.post(new Runnable() {
                public void run() {
                    //UI Task
                    adapter = new PostListAdapter(Notices_Parents.this, titlearray, datearray, authorarray);
                    listview.setAdapter(adapter);
                    listview.setOnItemClickListener(GoToWebPage);
                    handler.sendEmptyMessage(0);
                    SRL.setRefreshing(false);

                    Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.noti_parents_info),
                            Toast.LENGTH_LONG);
                    toast.setGravity(Gravity.TOP, 0, 0);
                    toast.show();
                }
            });

        }
    }.start();

}