Example usage for org.jsoup.nodes Element html

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

Introduction

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

Prototype

public Element html(String html) 

Source Link

Document

Set this element's inner HTML.

Usage

From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImpl.java

private static void reformatXHtmlHeadings(final Document document, final String selector) {
    final Elements elements = document.select(selector);

    for (final Element element : elements) {
        final String text = element.text();
        final String strongHeaderText = String.format("<strong>%s</strong>", text);
        element.html(strongHeaderText);
    }//w w w .ja  va2  s. com
}

From source file:ru.xxlabaza.popa.pack.PackingService.java

private void processCss(Document document) {
    document.select("link[rel=stylesheet]:not([href^=http])").forEach(link -> {
        Path path = build.resolve(createPath(link.attr("href")));
        log.info("Processing style '{}'", path);

        String content = commentRemoveService.removeComments(path);
        content = correctURLs(path, content);

        if (!path.getFileName().toString().endsWith(".min.css")) {
            content = compressService.compress(content, CSS);
        }//from   w w  w . j a va 2  s .c o m

        Element style = document.createElement("style");
        style.html(content);

        link.after(style);
        link.remove();
    });
}

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);
            }//from  ww  w . j  a v a2  s  . c o  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:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImpl.java

private static String reformatXHtml(final String inputXhtml,
        final Map<String, ConfluenceLink> confluenceLinkMap) {
    final Document document = Jsoup.parse(inputXhtml, "utf-8", Parser.xmlParser());
    document.outputSettings().prettyPrint(false);
    document.outputSettings().escapeMode(xhtml);
    document.outputSettings().charset("UTF-8");

    final Elements linkElements = document.select("a");

    for (final Element linkElement : linkElements) {
        final String originalHref = linkElement.attr("href");
        final ConfluenceLink confluenceLink = confluenceLinkMap.get(originalHref);

        if (confluenceLink == null) {
            LOG.debug("NO LINK MAPPING FOUND TO COVERT LINK: {}", originalHref);
            continue;
        }/*  w ww  .j a  v a 2  s  .c  om*/

        final String confluenceLinkMarkup = confluenceLink.getConfluenceLinkMarkup();

        LOG.debug("LINK CONVERSION: {} -> {}", originalHref, confluenceLinkMarkup);

        linkElement.before(confluenceLinkMarkup);

        linkElement.html("");
        linkElement.unwrap();
    }

    reformatXHtmlHeadings(document, "h2");
    reformatXHtmlHeadings(document, "h3");
    reformatXHtmlHeadings(document, "#toctitle");

    final SwaggerConfluenceConfig swaggerConfluenceConfig = SWAGGER_CONFLUENCE_CONFIG.get();

    if (swaggerConfluenceConfig.getPaginationMode() == PaginationMode.SINGLE_PAGE) {
        if (swaggerConfluenceConfig.isIncludeTableOfContentsOnSinglePage()) {
            reformatXHtmlBreakAfterElements(document, "#toc");
        }

        reformatXHtmlBreakAfterElements(document, ".sect1");
    }

    reformatXHtmlSpacing(document.select(".sect2"));
    reformatXHtmlSpacing(document.select(".sect3"));

    return document.html();
}

From source file:com.aestasit.markdown.slidery.converters.TextTemplateConverter.java

private void renderSyntaxHighlightingHtml(final Document slidesDocument, final Configuration config) {
    for (Element code : slidesDocument.select("code")) {
        Charset encoding = config.getInputEncoding();
        ByteArrayInputStream input = new ByteArrayInputStream(code.text().getBytes(encoding));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        String className = code.className();
        if (StringUtils.isBlank(className)) {
            className = "java";
        }//  w w w . j av a2s  . c  o m
        Renderer renderer = XhtmlRendererFactory.getRenderer(className);
        if (renderer != null) {
            try {
                renderer.highlight("slidery", input, out, encoding.name(), true);
                code.html(new String(out.toByteArray(), encoding));
                code.select("br").remove();
                removeComments(code);
                code.html(code.html().trim());
                Element parent = code.parent();
                if (parent.tagName() == "pre") {
                    parent.addClass("code");
                }
            } catch (IOException e) {
                // TODO: Handle exception
            }
        }
    }
}

From source file:com.zacwolf.commons.email.Email.java

private void prepare(final org.jsoup.nodes.Document doc) {
    removeComments(doc);//Remove any comments from the html of the message to reduce the size
    //Change the title to match the subject of the email
    if (doc.getElementsByTag("title").size() > 0)
        doc.getElementsByTag("title").first().html(getSubject());
    //Replace the contents of any tags with class="date" with the current date
    if (doc.getElementsByClass("date").size() > 0) {
        for (org.jsoup.nodes.Element datelem : doc.getElementsByClass("date")) {
            SimpleDateFormat df = new SimpleDateFormat("MMMMMMMMMM d, yyyy");
            if (datelem.hasAttr("format")) {
                try {
                    df = new SimpleDateFormat(datelem.attr("format"));
                } catch (Exception ee) {
                } //throw it away and just go back to the default format;
                datelem.html(df.format(TimeUtils.getGMTtime()));
            }//from w  w  w.ja v a2  s.  com
        }
    }
    //tables need the border-spacing: style attribute; added for GMail compatiblity
    for (org.jsoup.nodes.Element tbl : doc.getElementsByTag("table"))
        if (!tbl.attr("style").contains("border-spacing:"))
            tbl.attr("style",
                    tbl.attr("style") + (!tbl.attr("style").endsWith(";") ? ";" : "") + "border-spacing:0;");
}

From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java

/**
 * Converts some html to plain text, replacing images with their textual counterparts
 *
 * @param html html to be converted/*from w w  w .ja  va 2 s .  c  o m*/
 * @return plain text representation of the input
 */
public String convertHtmlToPlainText(String html) {
    Document document = Jsoup.parse(html);
    Elements images = document.select("img");
    for (Element image : images) {
        image.html("{" + image.attr("src") + "}");
    }
    return document.text();
}

From source file:net.acesinc.convergentui.ConvergentUIResponseFilter.java

@Override
public Object run() {

    String origBody = contentManager.getDownstreamResponse();
    if (origBody == null || origBody.isEmpty()) {
        return null;
    }/*from w  ww  . j ava  2  s.  c  o m*/

    String composedBody = null;
    log.trace("Response from downstream server: " + origBody);

    Document doc = Jsoup.parse(origBody);
    if (hasReplaceableElements(doc)) {
        log.debug("We have replaceable elements. Let's get em!");
        Elements elementsToUpdate = doc.select("div[data-loc]");
        for (Element e : elementsToUpdate) {
            StringBuilder content = new StringBuilder();
            String location = e.dataset().get("loc");
            String fragmentName = e.dataset().get("fragment-name");
            String cacheName = e.dataset().get("cache-name");
            boolean useCaching = !Boolean.valueOf(e.dataset().get("disable-caching"));
            boolean failQuietly = Boolean.valueOf(e.dataset().get("fail-quietly"));
            URL url = null;
            try {
                url = new URL(location);
                String protocol = url.getProtocol();
                String service = url.getHost();

                log.debug("Fetching content at location [ " + location + " ] with cacheName = [ " + cacheName
                        + " ]");

                try {
                    RequestContext context = RequestContext.getCurrentContext();
                    ContentResponse response = contentManager.getContentFromService(location, cacheName,
                            useCaching, context);

                    log.trace(response.toString());

                    if (!response.isError()) {
                        Object resp = response.getContent();
                        if (String.class.isAssignableFrom(resp.getClass())) {
                            String subContentResponse = (String) resp;
                            //TODO You better trust the source of your downstream HTML!
                            //                    String cleanedContent = Jsoup.clean(subContentResponse, Whitelist.basic()); //this totally stripped the html out...
                            Document subDocument = Jsoup.parse(subContentResponse);

                            if (fragmentName != null) {
                                Elements fragments = subDocument
                                        .select("div[data-fragment-name=\"" + fragmentName + "\"]");

                                if (fragments != null && fragments.size() > 0) {
                                    if (fragments.size() == 1) {
                                        Element frag = fragments.first();

                                        //need to see if there are images that we need to replace the urls on
                                        Elements images = frag.select("img");
                                        for (Element i : images) {
                                            String src = i.attr("src");
                                            if (src.startsWith("/") && !src.startsWith("//")) {
                                                i.attr("src", "/cui-req://" + protocol + "://" + service + src);
                                            } //else what do we do about relative urls?
                                        }

                                        content.append(frag.toString());

                                    } else {
                                        for (Element frag : fragments) {
                                            content.append(frag.toString()).append("\n\n");
                                        }
                                    }
                                } else {
                                    log.debug("Found no matching fragments for [ " + fragmentName + " ]");
                                    if (failQuietly) {
                                        content.append("<div class='cui-error'></div>");
                                    } else {
                                        content.append(
                                                "<span class='cui-error'>Failed getting content from remote service. Possible reason in reponse below</span>");
                                        content.append(subDocument.toString());
                                    }
                                }
                            } else {
                                //take the whole thing and cram it in there!
                                content.append(subDocument.toString());
                            }
                        } else {
                            //not text...
                            if (!failQuietly) {
                                content.append(
                                        "<span class='cui-error'>Failed getting content from remote service. Reason: content was not text</span>");
                            } else {
                                content.append("<div class='cui-error'></div>");
                            }
                        }

                    } else {
                        if (!failQuietly) {
                            content.append(
                                    "<span class='cui-error'>Failed getting content from remote service. Reason: "
                                            + response.getMessage() + "</span>");
                        } else {
                            content.append("<div class='cui-error'></div>");
                        }
                    }

                    //now append it to the page
                    if (!content.toString().isEmpty()) {
                        e.html(content.toString());
                    }
                } catch (Throwable t) {
                    if (!failQuietly) {
                        e.html("<span class='cui-error'>Failed getting content from remote service. Reason: "
                                + t.getMessage() + "</span>");
                    }
                    log.warn("Failed replacing content", t);
                }
            } catch (MalformedURLException ex) {
                log.warn("location was invalid: [ " + location + " ]", ex);
                if (!failQuietly) {
                    content.append(
                            "<span class='cui-error'>Failed getting content from remote service. Reason: data-loc was an invalid location.</span>");
                } else {
                    content.append("<div class='cui-error'></div>");
                }
            }

        }

        composedBody = doc.toString();
    } else {
        log.debug("Document has no replaeable elements. Skipping");
    }

    try {
        addResponseHeaders();
        if (composedBody != null && !composedBody.isEmpty()) {
            writeResponse(composedBody, getMimeType(RequestContext.getCurrentContext()));
        } else {
            writeResponse(origBody, getMimeType(RequestContext.getCurrentContext()));
        }
    } catch (Exception ex) {
        log.error("Error sending response", ex);

    }
    return null;
}

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 w  w.java 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();
}