Example usage for org.jsoup.nodes Document html

List of usage examples for org.jsoup.nodes Document html

Introduction

In this page you can find the example usage for org.jsoup.nodes Document html.

Prototype

public String html() 

Source Link

Document

Retrieves the element's inner HTML.

Usage

From source file:com.maxl.java.aips2xml.Aips2Xml.java

static String updateSectionPackungen(String title, Map<String, ArrayList<String>> pack_info, String regnr_str,
        String content_str, List<String> tIndex_list) {
    Document doc = Jsoup.parse(content_str, "UTF-16");
    List<String> pinfo_str = new ArrayList<String>();
    int index = 0;

    // Extract swissmedicno5 registration numbers
    List<String> swissmedicno5_list = Arrays.asList(regnr_str.split("\\s*,\\s*"));
    for (String s : swissmedicno5_list) {
        // Extract original / generika info + Selbstbehalt info from "add_info_map"
        String orggen_str = "";
        String flagsb_str = "";
        String addinfo_str = add_info_map.get(s);
        if (addinfo_str != null) {
            List<String> ai_list = Arrays.asList(addinfo_str.split("\\s*;\\s*"));
            if (ai_list != null) {
                if (!ai_list.get(0).isEmpty())
                    orggen_str = ", " + ai_list.get(0);
                if (!ai_list.get(1).isEmpty())
                    flagsb_str = ", " + ai_list.get(1);
            }//w w w .j ava 2s.co  m
        }
        // Now generate many swissmedicno8 = swissmedicno5 + ***, check if they're keys and retrieve package info         
        String swissmedicno8_key = "";
        for (int n = 0; n < 1000; ++n) {
            if (n < 10)
                swissmedicno8_key = s + String.valueOf(n).format("00%d", n);
            else if (n < 100)
                swissmedicno8_key = s + String.valueOf(n).format("0%d", n);
            else
                swissmedicno8_key = s + String.valueOf(n).format("%d", n);
            // Check if swissmedicno8_key is a key of the map
            if (pack_info.containsKey(swissmedicno8_key)) {
                ArrayList<String> pi_row = package_info.get(swissmedicno8_key);
                if (pi_row != null) {
                    // --> Add "ausser Handel" information
                    String withdrawn_str = "";
                    if (pi_row.get(10).length() > 0)
                        withdrawn_str = ", " + pi_row.get(10);
                    // --> Add public price information
                    if (pi_row.get(7).length() > 0) {
                        // Remove double spaces in title
                        String medtitle = capitalizeFully(pi_row.get(1).replaceAll("\\s+", " "), 1);
                        // Remove [QAP?] -> not an easy one!
                        medtitle = medtitle.replaceAll("\\[(.*?)\\?\\] ", "");
                        pinfo_str.add("<p class=\"spacing1\">" + medtitle + ", " + pi_row.get(7) + withdrawn_str
                                + " [" + pi_row.get(5) + pi_row.get(11) + pi_row.get(12) + flagsb_str
                                + orggen_str + "]</p>");
                    } else {
                        // Remove double spaces in title               
                        String medtitle = capitalizeFully(pi_row.get(1).replaceAll("\\s+", " "), 1);
                        // Remove [QAP?] -> not an easy one!                     
                        medtitle = medtitle.replaceAll("\\[(.*?)\\?\\] ", "");
                        if (DB_LANGUAGE.equals("de")) {
                            pinfo_str.add("<p class=\"spacing1\">" + medtitle + ", " + "k.A." + withdrawn_str
                                    + " [" + pi_row.get(5) + pi_row.get(11) + pi_row.get(12) + flagsb_str
                                    + orggen_str + "]</p>");
                        } else if (DB_LANGUAGE.equals("fr")) {
                            pinfo_str.add("<p class=\"spacing1\">" + medtitle + ", " + "prix n.s."
                                    + withdrawn_str + " [" + pi_row.get(5) + pi_row.get(11) + pi_row.get(12)
                                    + flagsb_str + orggen_str + "]</p>");
                        }
                    }
                    // --> Add "tindex_str" and "application_str" (see SqlDatabase.java)
                    if (index == 0) {
                        tIndex_list.add(pi_row.get(9)); // therapeutic index
                        tIndex_list.add(pi_row.get(6)); // application area                  
                        index++;
                    }
                }
            }
        }
    }
    // In case the pinfo_str is empty due to malformed XML
    /*
    if (pinfo_str.isEmpty())
       html_utils.extractPackSection();
    */
    // In case nothing was found
    if (index == 0) {
        tIndex_list.add("");
        tIndex_list.add("");
    }
    // Replace original package information with pinfo_str
    String p_str = "";
    mPackSection_str = "";
    for (String p : pinfo_str) {
        p_str += p;
    }

    // Generate a html-deprived string file
    mPackSection_str = p_str.replaceAll("\\<p.*?\\>", "");
    mPackSection_str = mPackSection_str.replaceAll("<\\/p\\>", "\n");
    // Remove last \n
    if (mPackSection_str.length() > 0)
        mPackSection_str = mPackSection_str.substring(0, mPackSection_str.length() - 1);

    doc.outputSettings().escapeMode(EscapeMode.xhtml);
    Element div7800 = doc.select("[id=Section7800]").first();
    if (div7800 != null) {
        div7800.html("<div class=\"absTitle\">Packungen</div>" + p_str);
    } else {
        Element div18 = doc.select("[id=section18]").first();
        if (div18 != null) {
            div18.html("<div class=\"absTitle\">Packungen</div>" + p_str);
        } else {
            if (SHOW_ERRORS)
                System.err.println(">> ERROR: elem is null, sections 18/7800 does not exist: " + title);
        }
    }

    return doc.html();
}

From source file:com.romeikat.datamessie.core.base.service.download.ContentDownloader.java

public DownloadResult downloadContent(String url) {
    LOG.debug("Downloading content from {}", url);
    // In case of a new redirection for that source, use redirected URL
    URLConnection urlConnection = null;
    String originalUrl = null;/*from ww  w .ja v a  2 s  . co  m*/
    org.jsoup.nodes.Document jsoupDocument = null;
    Integer statusCode = null;
    final LocalDateTime downloaded = LocalDateTime.now();
    try {
        urlConnection = getConnection(url);
        // Server-side redirection
        final String responseUrl = getResponseUrl(urlConnection);
        if (responseUrl != null) {
            final String redirectedUrl = getRedirectedUrl(url, responseUrl);
            if (isValidRedirection(url, redirectedUrl)) {
                originalUrl = url;
                url = redirectedUrl;
                closeUrlConnection(urlConnection);
                urlConnection = getConnection(url);
                LOG.debug("Redirection (server): {} -> {}", originalUrl, url);
            }
        }
        // Download content for further redirects
        final InputStream urlInputStream = asInputStream(urlConnection, true, false);
        final Charset charset = getCharset(urlConnection);
        jsoupDocument = Jsoup.parse(urlInputStream, charset.name(), url);
        final Elements metaTagsHtmlHeadLink;
        Elements metaTagsHtmlHeadMeta = null;
        // Meta redirection (<link rel="canonical" .../>)
        if (originalUrl == null) {
            metaTagsHtmlHeadLink = jsoupDocument.select("html head link");
            for (final Element metaTag : metaTagsHtmlHeadLink) {
                final Attributes metaTagAttributes = metaTag.attributes();
                if (metaTagAttributes.hasKey("rel")
                        && metaTagAttributes.get("rel").equalsIgnoreCase("canonical")
                        && metaTagAttributes.hasKey("href")) {
                    final String redirectedUrl = metaTagAttributes.get("href").trim();
                    if (isValidRedirection(url, redirectedUrl)) {
                        originalUrl = url;
                        url = redirectedUrl;
                        jsoupDocument = null;
                        LOG.debug("Redirection (<link rel=\"canonical\" .../>): {} -> {}", originalUrl, url);
                        break;
                    }
                }
            }
        }
        // Meta redirection (<meta http-equiv="refresh" .../>)
        if (originalUrl == null) {
            metaTagsHtmlHeadMeta = jsoupDocument.select("html head meta");
            for (final Element metaTag : metaTagsHtmlHeadMeta) {
                final Attributes metaTagAttributes = metaTag.attributes();
                if (metaTagAttributes.hasKey("http-equiv")
                        && metaTagAttributes.get("http-equiv").equalsIgnoreCase("refresh")
                        && metaTagAttributes.hasKey("content")) {
                    final String[] parts = metaTagAttributes.get("content").replace(" ", "").split("=", 2);
                    if (parts.length > 1) {
                        final String redirectedUrl = parts[1];
                        if (isValidRedirection(url, redirectedUrl)) {
                            originalUrl = url;
                            url = redirectedUrl;
                            jsoupDocument = null;
                            LOG.debug("Redirection (<meta http-equiv=\"refresh\" .../>): {} -> {}", originalUrl,
                                    url);
                            break;
                        }
                    }
                }
            }
        }
        // Meta redirection (<meta property="og:url" .../>)
        if (originalUrl == null) {
            for (final Element metaTag : metaTagsHtmlHeadMeta) {
                final Attributes metaTagAttributes = metaTag.attributes();
                if (metaTagAttributes.hasKey("property")
                        && metaTagAttributes.get("property").equalsIgnoreCase("og:url")
                        && metaTagAttributes.hasKey("content")) {
                    final String redirectedUrl = metaTagAttributes.get("content").trim();
                    if (isValidRedirection(url, redirectedUrl)) {
                        originalUrl = url;
                        url = redirectedUrl;
                        jsoupDocument = null;
                        LOG.debug("Redirection (<meta property=\"og:url\" .../>): {} -> {}", originalUrl, url);
                        break;
                    }
                }
            }
        }
    } catch (final Exception e) {
        if (e instanceof HttpStatusException) {
            statusCode = ((HttpStatusException) e).getStatusCode();
        }
        LOG.warn("Could not determine redirected URL for " + url, e);
    } finally {
        closeUrlConnection(urlConnection);
    }
    // Download content (if not yet done)
    String content = null;
    try {
        if (jsoupDocument == null) {
            LOG.debug("Downloading content from {}", url);
            urlConnection = getConnection(url);
            final InputStream urlInputStream = asInputStream(urlConnection, true, false);
            final Charset charset = getCharset(urlConnection);
            jsoupDocument = Jsoup.parse(urlInputStream, charset.name(), url);
        }
    } catch (final Exception e) {
        if (e instanceof HttpStatusException) {
            statusCode = ((HttpStatusException) e).getStatusCode();
        }
        // If the redirected URL does not exist, use the original URL instead
        if (originalUrl == null) {
            LOG.warn("Could not download content from " + url, e);
        }
        // If the redirected URL does not exist and a original URL is available, use the
        // original URL instead
        else {
            try {
                LOG.debug(
                        "Could not download content from redirected URL {}, downloading content from original URL {} instead",
                        url, originalUrl);
                urlConnection = getConnection(originalUrl);
                final InputStream urlInputStream = asInputStream(urlConnection, true, false);
                final Charset charset = getCharset(urlConnection);
                jsoupDocument = Jsoup.parse(urlInputStream, charset.name(), url);
                url = originalUrl;
                originalUrl = null;
                statusCode = null;
            } catch (final Exception e2) {
                LOG.warn("Could not download content from original URL " + url, e);
            }
        }
    } finally {
        closeUrlConnection(urlConnection);
    }
    if (jsoupDocument != null) {
        content = jsoupDocument.html();
    }
    // Strip non-valid characters as specified by the XML 1.0 standard
    final String validContent = xmlUtil.stripNonValidXMLCharacters(content);
    // Unescape HTML characters
    final String unescapedContent = StringEscapeUtils.unescapeHtml4(validContent);
    // Done
    final DownloadResult downloadResult = new DownloadResult(originalUrl, url, unescapedContent, downloaded,
            statusCode);
    return downloadResult;
}

From source file:com.maxl.java.aips2sqlite.RealExpertInfo.java

private String updateSectionPackungen(String title, String atc_code, Map<String, ArrayList<String>> pack_info,
        String regnr_str, String content_str, List<String> tIndex_list) {
    Document doc = Jsoup.parse(content_str, "UTF-16");
    // package info string for original
    List<String> pinfo_originals_str = new ArrayList<String>();
    // package info string for generika
    List<String> pinfo_generics_str = new ArrayList<String>();
    // package info string for the rest
    List<String> pinfo_str = new ArrayList<String>();
    // String containg all barcodes
    List<String> barcode_list = new ArrayList<String>();

    int index = 0;

    // Extract swissmedicno5 registration numbers
    List<String> swissmedicno5_list = Arrays.asList(regnr_str.split("\\s*,\\s*"));
    for (String smno5 : swissmedicno5_list) {
        // Extract original / generika info + Selbstbehalt info from
        // "add_info_map"
        String orggen_str = ""; // O=Original, G=Generika
        String flagsb_str = ""; // SB=Selbstbehalt 
        String addinfo_str = m_add_info_map.get(smno5);
        if (addinfo_str != null) {
            List<String> ai_list = Arrays.asList(addinfo_str.split("\\s*;\\s*"));
            if (ai_list != null) {
                if (!ai_list.get(0).isEmpty())
                    orggen_str = ", " + ai_list.get(0); // O + G
                if (!ai_list.get(1).isEmpty())
                    flagsb_str = ", " + ai_list.get(1); // SB
            }//from  w  ww. j a v  a 2 s.  c om
        }
        // Now generate many swissmedicno8 = swissmedicno5 + ***, check if they're keys and retrieve package info
        String swissmedicno8_key = "";
        for (int n = 0; n < 1000; ++n) {
            swissmedicno8_key = getSwissmedicNo8(smno5, n);
            // Check if swissmedicno8_key is a key of the map
            if (pack_info.containsKey(swissmedicno8_key)) {
                ArrayList<String> pi_row = m_package_info.get(swissmedicno8_key);
                if (pi_row != null) {
                    // This string is used for "shopping carts" and contatins:
                    // Prparatname | Package size | Package unit | Public price
                    // | Exfactory price | Spezialittenliste, Swissmedic Kategorie, Limitations
                    // | EAN code | Pharma code
                    String barcode_html = "";
                    String pup = pi_row.get(7); // public price
                    String efp = pi_row.get(8); // exfactory price      
                    String fep = "";
                    String fap = "";
                    String vat = "";
                    String eancode = pi_row.get(14);
                    int visible = 0xff; // by default visible to all!
                    int has_free_samples = 0x00; // by default no free samples
                    // Exctract fep and fap pricing information
                    // FAP = Fabrikabgabepreis = EFP?
                    // FEP = Fachhandelseinkaufspreis
                    // EFP = FAP < FEP < PUP
                    if (m_map_products != null && eancode != null && m_map_products.containsKey(eancode)) {
                        Product product = m_map_products.get(eancode);
                        // Correct these prices, if necessary... the m_map_products info comes from the owner directly!
                        // @maxl: Added on 30.08.2015
                        if (product.efp > 0.0f)
                            efp = String.format("CHF %.2f", product.efp);
                        if (product.pp > 0.0f)
                            pup = String.format("CHF %.2f", product.pp);
                        if (product.fap > 0.0f)
                            fap = String.format("CHF %.2f", product.fap);
                        if (product.fep > 0.0f)
                            fep = String.format("CHF %.2f", product.fep);
                        if (product.vat > 0.0f)
                            vat = String.format("%.2f", product.vat);
                        visible = product.visible;
                        has_free_samples = product.free_sample;
                    }

                    // Some articles are listed in swissmedic_packages file but are not in the refdata file
                    if (pi_row.get(10).equals("a.H.")) {
                        pi_row.set(10, "ev.nn.i.H.");
                    }
                    if (pi_row.get(10).equals("p.c.")) {
                        pi_row.set(10, "ev.ep.e.c.");
                    }

                    // Add only if medication is "in Handel" -> check pi_row.get(10)                  
                    if (pi_row.get(10).isEmpty() || pi_row.get(10).equals("ev.nn.i.H.")
                            || pi_row.get(10).equals("ev.ep.e.c.")) {
                        // --> Extract EAN-13 or EAN-12 and generate barcodes                     
                        try {
                            if (!eancode.isEmpty()) {
                                BarCode bc = new BarCode();
                                if (eancode.length() == 12) {
                                    int cs = bc.getChecksum(eancode);
                                    eancode += cs;
                                }
                                String barcodeImg64 = bc.encode(eancode);
                                barcode_html = "<p class=\"barcode\">" + barcodeImg64 + "</p>";
                                barcode_list.add(barcode_html);
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        m_list_of_packages.add(pi_row.get(1) + "|" + pi_row.get(3) + "|" + pi_row.get(4) + "|"
                                + efp + "|" + pup + "|" + fap + "|" + fep + "|" + vat + "|" + pi_row.get(5)
                                + ", " + pi_row.get(11) + ", " + pi_row.get(12) + "|" + eancode + "|"
                                + pi_row.get(15) + "|" + visible + "|" + has_free_samples + "\n");
                        m_list_of_eancodes.add(eancode);
                    }

                    // Remove double spaces in title and capitalize
                    String medtitle = capitalizeFully(pi_row.get(1).replaceAll("\\s+", " "), 1);
                    // Remove [QAP?] -> not an easy one!
                    medtitle = medtitle.replaceAll("\\[(.*?)\\?\\] ", "");
                    // --> Add "ausser Handel" information
                    String withdrawn_str = "";
                    if (pi_row.get(10).length() > 0)
                        withdrawn_str = ", " + pi_row.get(10);
                    // --> Add ex factory price information
                    String price_efp = !efp.isEmpty() ? "EFP" + efp.replace("CHF", "")
                            : "FEP" + fep.replace("CHF", "");
                    String price_pp = !pup.isEmpty() ? ", PP" + pup.replace("CHF", "") : "";
                    if (efp.length() > 0 || fep.length() > 0) {
                        // The rest of the package information
                        String append_str = ", " + price_efp + price_pp + withdrawn_str + " [" + pi_row.get(5)
                                + pi_row.get(11) + pi_row.get(12) + flagsb_str + orggen_str + "]";
                        // Generate package info string
                        if (orggen_str.equals(", O"))
                            pinfo_originals_str.add(
                                    "<p class=\"spacing1\">" + medtitle + append_str + "</p>" + barcode_html);
                        else if (orggen_str.equals(", G"))
                            pinfo_generics_str.add(
                                    "<p class=\"spacing1\">" + medtitle + append_str + "</p>" + barcode_html);
                        else
                            pinfo_str.add(
                                    "<p class=\"spacing1\">" + medtitle + append_str + "</p>" + barcode_html);
                    } else {
                        //
                        // @maxl (10.01.2014): Price for swissmedicNo8 pack is not listed in bag_preparations.xml!!
                        //
                        pinfo_str.add("<p class=\"spacing1\">" + medtitle + withdrawn_str + " [" + pi_row.get(5)
                                + "]</p>" + barcode_html);
                    }

                    // --> Add "tindex_str" and "application_str" (see
                    // SqlDatabase.java)
                    if (index == 0) {
                        tIndex_list.add(pi_row.get(9)); // therapeutic index
                        tIndex_list.add(pi_row.get(6)); // application area
                        index++;
                    }
                }
            }
        }
    }
    // Re-order the string alphabetically
    if (!m_list_of_packages.isEmpty()) {
        Collections.sort(m_list_of_packages, new AlphanumComp());
    }
    if (!pinfo_originals_str.isEmpty()) {
        Collections.sort(pinfo_originals_str, new AlphanumComp());
    }
    if (!pinfo_generics_str.isEmpty()) {
        Collections.sort(pinfo_generics_str, new AlphanumComp());
    }
    if (!pinfo_str.isEmpty()) {
        Collections.sort(pinfo_str, new AlphanumComp());
    }
    // Concatenate lists...
    pinfo_originals_str.addAll(pinfo_generics_str);
    pinfo_originals_str.addAll(pinfo_str);
    // Put everything in pinfo_str
    pinfo_str = pinfo_originals_str;

    // In case nothing was found
    if (index == 0) {
        tIndex_list.add("");
        tIndex_list.add("");
    }

    /*
    * Replace package information
    */
    if (CmlOptions.PLAIN == false) {
        // Replace original package information with pinfo_str   
        String p_str = "";
        for (String p : pinfo_str) {
            p_str += p;
        }

        // Generate a html-deprived string file
        m_pack_info_str = p_str.replaceAll("<p class=\"spacing1\">[<](/)?img[^>]*[>]</p>", "");
        m_pack_info_str = m_pack_info_str.replaceAll("<p class=\"barcode\">[<](/)?img[^>]*[>]</p>", "");
        m_pack_info_str = m_pack_info_str.replaceAll("\\<p.*?\\>", "");
        m_pack_info_str = m_pack_info_str.replaceAll("<\\/p\\>", "\n");

        // Remove last \n
        if (m_pack_info_str.length() > 0)
            m_pack_info_str = m_pack_info_str.substring(0, m_pack_info_str.length() - 1);

        doc.outputSettings().escapeMode(EscapeMode.xhtml);
        Element div7800 = doc.select("[id=Section7800]").first();

        // Initialize section titles
        String packages_title = "Packungen";
        String swiss_drg_title = "Swiss DRG";
        if (CmlOptions.DB_LANGUAGE.equals("fr")) {
            packages_title = "Prsentation";
            swiss_drg_title = "Swiss DRG";
        }

        // Generate html for chapter "Packagungen" and subchapter "Swiss DRGs"
        // ** Chapter "Packungen"
        String section_html = "<div class=\"absTitle\">" + packages_title + "</div>" + p_str;
        // ** Subchapter "Swiss DRGs"
        // Loop through list of dosages for a particular atc code and format appropriately
        if (atc_code != null) {
            // Update DRG footnote super scripts
            String footnotes = "1";
            String fn = m_swiss_drg_footnote.get(atc_code);
            if (fn != null)
                footnotes += (", " + fn);
            // Generate Swiss DRG string
            String drg_str = "";
            ArrayList<String> dosages = m_swiss_drg_info.get(atc_code);
            // For most atc codes, there are NO special DRG sanctioned dosages...
            if (dosages != null) {
                System.out.println(title + " (DRG)");
                for (String drg : dosages)
                    drg_str += "<p class=\"spacing1\">" + drg + "</p>";
                if (!drg_str.isEmpty()) {
                    section_html += ("<p class=\"paragraph\"></p><div class=\"absTitle\">" + swiss_drg_title
                            + "<sup>" + footnotes + "</sup></div>" + drg_str);
                }

                section_html += "<p class=\"noSpacing\"></p>";
                if (CmlOptions.DB_LANGUAGE.equals("de")) {
                    section_html += "<p class=\"spacing1\"><sup>1</sup> Alle Spitler mssen im Rahmen der jhrlichen Datenerhebung (Detaillieferung) die SwissDRG AG zwingend ber die Hhe der in Rechnung gestellten Zusatzentgelte informieren.</p>";
                    section_html += "<p class=\"spacing1\"><sup>2</sup> Eine zustzliche Abrechnung ist im Zusammenhang mit einer Fallpauschale der Basis-DRGs L60 oder L71 nicht mglich.</p>";
                    section_html += "<p class=\"spacing1\"><sup>3</sup> Eine Abrechnung des Zusatzentgeltes ist nur ber die in der Anlage zum Fallpauschalenkatalog aufgefhrten Dosisklassen mglich.</p>";
                    section_html += "<p class=\"spacing1\"><sup>4</sup> Dieses Zusatzentgelt ist nur abrechenbar fr Patienten mit einem Alter < 15 Jahre.</p>";
                    section_html += "<p class=\"spacing1\"><sup>5</sup> Dieses Zusatzentgelt darf nicht zustzlich zur DRG A91Z abgerechnet werden, da in dieser DRG Apheresen die Hauptleistung darstellen. "
                            + "Die Verfahrenskosten der  Apheresen sind in dieser DRG bereits vollumfnglich enthalten.</p>";
                } else if (CmlOptions.DB_LANGUAGE.equals("fr")) {
                    section_html += "<p class=\"spacing1\"><sup>1</sup> Tous les hpitaux doivent imprativement informer SwissDRG SA lors du relev (relev dtaill) sur le montant des rmunrations supplmentaires factures.</p>";
                    section_html += "<p class=\"spacing1\"><sup>2</sup> Une facturation supplmentaire aux forfaits par cas des DRG de base L60 ou L71 nest pas possible.</p>";
                    section_html += "<p class=\"spacing1\"><sup>3</sup> Une facturation des rmunration supplmentaires n'est possible que pour les classes de dosage dfinies dans cette annexe.</p>";
                    section_html += "<p class=\"spacing1\"><sup>4</sup> Cette rmunration supplmentaire n'est facturable que pour les patients gs de moins de 15 ans.</p>";
                    section_html += "<p class=\"spacing1\"><sup>5</sup> Cette rmunration supplmentaire ne peut pas tre facture en plus du DRG A91Z, la prestation principale de ce DRG tant l'aphrse. "
                            + "Les cots du traitement par aphrse sont dj intgralement compris dans le DRG.</p>";
                }
            }
        }

        if (div7800 != null) {
            div7800.html(section_html);
        } else {
            Element div18 = doc.select("[id=section18]").first();
            if (div18 != null) {
                div18.html(section_html);
            } else {
                if (CmlOptions.SHOW_ERRORS)
                    System.err.println(">> ERROR: elem is null, sections 18/7800 does not exist: " + title);
            }
        }
    }

    return doc.html();
}

From source file:com.lloydtorres.stately.issues.IssuesFragment.java

/**
 * Process the HTML contents of the issues into actual Issue objects
 * @param d/*from w  w w.  j  av a2s .  c om*/
 */
private void processIssues(View v, Document d) {
    issues = new ArrayList<Object>();

    Element issuesContainer = d.select("ul.dilemmalist").first();

    if (issuesContainer == null) {
        // safety check
        mSwipeRefreshLayout.setRefreshing(false);
        SparkleHelper.makeSnackbar(v, getString(R.string.login_error_parsing));
        return;
    }

    Elements issuesRaw = issuesContainer.children();

    for (Element i : issuesRaw) {
        Issue issueCore = new Issue();

        Elements issueContents = i.children();

        // Get issue ID and name
        Element issueMain = issueContents.select("a").first();

        if (issueMain == null) {
            continue;
        }

        String issueLink = issueMain.attr("href");
        issueCore.id = Integer.valueOf(issueLink.replace("page=show_dilemma/dilemma=", ""));
        Matcher chainMatcher = CHAIN_ISSUE_REGEX.matcher(issueMain.text());
        if (chainMatcher.find()) {
            issueCore.chain = chainMatcher.group(1);
            issueCore.title = chainMatcher.group(2);
        } else {
            issueCore.title = issueMain.text();
        }

        issues.add(issueCore);
    }

    Element nextIssueUpdate = d.select("p.dilemmanextupdate").first();
    if (nextIssueUpdate != null) {
        String nextUpdate = nextIssueUpdate.text();
        issues.add(nextUpdate);
    }

    if (issuesRaw.size() <= 0) {
        String nextUpdate = getString(R.string.no_issues);

        Matcher m = NEXT_ISSUE_REGEX.matcher(d.html());
        if (m.find()) {
            long nextUpdateTime = Long.valueOf(m.group(1)) / 1000L;
            nextUpdate = String.format(Locale.US, getString(R.string.next_issue),
                    SparkleHelper.getReadableDateFromUTC(getContext(), nextUpdateTime));
        }

        issues.add(nextUpdate);
    }

    if (mRecyclerAdapter == null) {
        mRecyclerAdapter = new IssuesRecyclerAdapter(getContext(), issues, mNation);
        mRecyclerView.setAdapter(mRecyclerAdapter);
    } else {
        ((IssuesRecyclerAdapter) mRecyclerAdapter).setIssueCards(issues);
    }
    mSwipeRefreshLayout.setRefreshing(false);
}

From source file:com.microsoft.artcurator.ui.emaildetails.EmailDetailsFragment.java

private String sanitizeComments(String desc) {
    Document doc = Jsoup.parse(desc);
    doc.select("script, style, meta, link, comment, CDATA, #comment").remove();
    return doc.html();
}

From source file:com.semfapp.adamdilger.semf.hazardIdActivity.java

public void createPdf() {
    Document documentTemplate = Pdf.getTemplate(getApplicationContext(), data.getProjectNumber());

    try {//from w  w  w  .  ja va2  s.  c  o m
        Document body = Jsoup.parse(getAssets().open("hazardIdentification.html"), "utf-8",
                "http://www.example.com");

        Elements lists = body.select(".list_box"); //Lists html Elements
        ArrayList<String[]> arrayList = data.getArray(); //editText string arrays

        //for each Element in lists, add each bullet from arrayList.string[] as a <p>
        for (int x = 0; x < lists.size(); x++) {
            String f = "";

            for (String bullet : arrayList.get(x)) {
                f += "<p>" + bullet + "</p>";
            }

            lists.get(x).html(f);
        }

        documentTemplate.getElementById("main").html(body.html());
    } catch (Exception e) {

    }

    //create filename / subject for email
    name = Emailer.getSubject(Emailer.HAZARD_ID_CODE, data.getProjectNumber());

    String filePath = MainActivity.pdf.createFilePath(this, name);
    MainActivity.pdf.createPdfToFile(this, documentTemplate.html(), filePath, data.getImageArray());

    pdfAttatchment = new File(filePath);
}

From source file:com.semfapp.adamdilger.semf.NonConformanceActivity.java

public void createPdf() {
    Document document = Pdf.getTemplate(getApplicationContext(), data.getJobNumber());

    try {// w  ww. j  a  va2  s  .c om
        Document body = Jsoup.parse(getAssets().open("nonConformance.html"), "utf-8", "http://www.example.com");

        Element site = body.getElementById("site");
        Element siteLocation = body.getElementById("site_location");
        Element recipient = body.getElementById("recipient");
        Element recipientEmail = body.getElementById("recipient_email");
        Element description = body.getElementById("description_list");
        Element actions = body.getElementById("actions_list");

        String[] descriptionArray, actionsArray;
        descriptionArray = data.getDescription().split(System.lineSeparator());
        actionsArray = data.getActions().split(System.lineSeparator());

        site.text(data.getSite());
        siteLocation.text(data.getLocation());
        recipient.html("<p>" + data.getRecipient() + "</p>");
        recipientEmail.html("<p>" + data.getRecipientEmail() + "</p>");

        //add each bullet from arrays as a <p>
        for (int x = 0; x < descriptionArray.length; x++) {
            String f = "";

            for (String bullet : descriptionArray) {
                f += "<p>" + bullet + "</p>";
            }

            description.html(f);
        }

        for (int x = 0; x < actionsArray.length; x++) {
            String f = "";

            for (String bullet : actionsArray) {
                f += "<p>" + bullet + "</p>";
            }

            actions.html(f);
        }

        document.getElementById("main").html(body.html());

    } catch (Exception e) {
        System.out.println("ERROR: " + e.toString());
    }

    String filePath = MainActivity.pdf.createFilePath(this, "Non Conformance");

    MainActivity.pdf.createPdfToFile(this, document.html(), filePath, null);

    pdfAttatchment = new File(filePath);
}

From source file:com.semfapp.adamdilger.semf.protectPlanActivity.java

public void createPdf() {
    Document documentTemplate = null;
    Element body = null;/*from   w  w w . j av a  2 s  . c om*/

    try {
        documentTemplate = Pdf.getTemplate(getApplicationContext(), null);

        body = Jsoup.parse(getAssets().open("protectPlan.html"), "utf-8", "http://www.example.com");

        Elements lists = body.select(".list_box"); //Lists html Elements
        ArrayList<String[]> arrayList = data.getArray(); //editText string arrays

        //for each Element in lists, add each bullet from arrayList.string[] as a <p>
        for (int x = 0; x < lists.size(); x++) {
            String f = "";

            for (String bullet : arrayList.get(x)) {
                f += "<p>" + bullet + "</p>";
            }

            lists.get(x).html(f);
        }
    } catch (Exception e) {
        System.out.println("ERROR: " + e.toString());
    }

    documentTemplate.getElementById("main").html(body.html());

    String filePath = MainActivity.pdf.createFilePath(this, "Protect Plan");

    MainActivity.pdf.createPdfToFile(this, documentTemplate.html(), filePath, null);

    pdfAttatchment = new File(filePath);

}

From source file:com.semfapp.adamdilger.semf.SiteInstructionActivity.java

public void createPdf() {
    Document documentTemplate = Pdf.getTemplate(getApplicationContext(), data.getJobNumber());
    try {/*from  w  w w.  j  a  v  a  2s.c o  m*/
        Document body = Jsoup.parse(getAssets().open("siteInstruction.html"), "utf-8",
                "http://www.example.com");

        Element site = body.getElementById("site");
        Element siteLocation = body.getElementById("site_location");
        Element recipient = body.getElementById("recipient");
        Element recipientEmail = body.getElementById("recipient_email");
        Element description = body.getElementById("description_list");

        String[] descriptionArray;
        descriptionArray = data.getDescription().split(System.lineSeparator());

        site.text(data.getSite());
        siteLocation.text(data.getLocation());
        recipient.html("<p>" + data.getRecipient() + "</p>");
        recipientEmail.html("<p>" + data.getRecipientEmail() + "</p>");

        //add each bullet from arrays as a <p>
        for (int x = 0; x < descriptionArray.length; x++) {
            String f = "";

            for (String bullet : descriptionArray) {
                f += "<p>" + bullet + "</p>";
            }

            description.html(f);
        }

        documentTemplate.getElementById("main").html(body.html());
    } catch (Exception e) {
        System.out.println("ERROR: " + e.toString());
    }

    name = Emailer.getSubject(Emailer.SITE_INSTRUCTION_CODE, data.getJobNumber());
    String filePath = MainActivity.pdf.createFilePath(this, name);

    MainActivity.pdf.createPdfToFile(this, documentTemplate.html(), filePath, data.getImageArray());

    pdfAttatchment = new File(filePath);
}