Example usage for org.jsoup.nodes Element append

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

Introduction

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

Prototype

public Element append(String html) 

Source Link

Document

Add inner HTML to this element.

Usage

From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java

/**
 * Prepare and load data to WebView.//www .  jav a2s.co  m
 */
private void showHtml() {
    try {

        if (isOnline) {

            if (currentUrl.length() > 0 && !currentUrl.equals("about:blank")) {
                url = currentUrl;
            }
            if (url.length() > 0)
                html = "<html><body><a href=\"" + url + "\" id=\"link\" /></body></html>";

            Document doc = Jsoup.parse(html);
            Element iframe = doc.select("iframe").first();

            boolean isGoogleCalendar = false;
            boolean isGoogleForms = false;
            String iframeSrc = "";
            try {
                if (iframe != null) {
                    iframeSrc = iframe.attr("src");
                }
            } catch (Exception e) {
            }
            if (iframeSrc.length() > 0) {
                isGoogleCalendar = iframeSrc.contains("www.google.com/calendar")
                        || iframeSrc.contains("calendar.google.com/calendar");
                isGoogleForms = iframeSrc.contains("google.com/forms");
            }
            if (isGoogleCalendar) {
                webView.loadUrl(iframeSrc);
            } else if (isGoogleForms) {
                webView.getSettings().setBuiltInZoomControls(false);

                DisplayMetrics metrix = getResources().getDisplayMetrics();
                int width = metrix.widthPixels;
                int height = metrix.heightPixels;
                float density = metrix.density;

                iframe.attr("width", (int) (width / density) + "");
                iframe.attr("height", (int) (height / density - (75 /*+ (hasAdView() ? 50 : 0)*/)) + "");

                iframe.attr("style", "margin: 0; padding: 0");

                Element body = doc.select("body").first();
                body.attr("style", "margin: 0; padding: 0");

                html = doc.outerHtml();

                webView.loadDataWithBaseURL("http://", html, "text/html", "utf-8", "");
            } else {
                Elements forms = doc.select("form");
                Iterator<Element> iterator = forms.iterator();
                for (; iterator.hasNext();) {
                    Element form = iterator.next();
                    String action = form.attr("action");

                    if (action.contains("paypal.com")) {
                        form.append("<input type=\"hidden\" name=\"bn\" value=\"ibuildapp_SP\">");
                    }

                    html = doc.html();
                }

                hideProgress = true;

                if (Build.VERSION.SDK_INT >= 20 && html.contains("ibuildapp") && html.contains("powr")) {
                    int height = getResources().getDisplayMetrics().heightPixels;
                    html = "<iframe width=\"" + 420 + "\" height=\"" + height + "\"  frameBorder=\"0\" src="
                            + url + "></iframe>";
                    webView.loadData(html, "text/html", "utf-8");
                } else
                    webView.loadDataWithBaseURL("http://", html, "text/html", "utf-8", "");
            }
        } else {
            if (html.length() > 0) {
                webView.loadDataWithBaseURL("http://", html, "text/html", "utf-8", "");
            }
        }

        handler.sendEmptyMessageDelayed(HIDE_PROGRESS, 10000);

    } catch (Exception ex) { // Error Logging
    }
}

From source file:im.ene.lab.attiq.ui.activities.ItemDetailActivity.java

@SuppressWarnings("unused")
public void onEventMainThread(ItemDetailEvent event) {
    Article article = event.article;//from ww w  .jav a2 s .  c o m
    String userName = null;
    if (article != null) {
        mArticle = article;
        mRealm.beginTransaction();
        mRealm.copyToRealmOrUpdate(mArticle);
        mRealm.commitTransaction();

        User user = article.getUser();

        mArticleName.setText(article.getTitle());
        mSpannableTitle = new SpannableString(article.getTitle());
        userName = user.getId();
        mSpannableSubtitle = new SpannableString(userName);

        updateTitle();

        buildArticleComments(article);

        buildArticleMenu(article);

        final String html;
        try {
            if (PrefUtil.isMathJaxEnabled()) {
                html = IOUtil.readAssets("html/article_mathjax.html");
            } else {
                html = IOUtil.readAssets("html/article.html");
            }

            Document doc = Jsoup.parse(html);
            Element elem = doc.getElementById("content");
            elem.append(article.getRenderedBody());
            String result = doc.outerHtml();
            mContentView.loadDataWithBaseURL(article.getUrl(), result, "text/html", "utf-8", null);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    final CharSequence subTitle;
    if (article != null && !UIUtil.isEmpty(userName)) {
        subTitle = Html.fromHtml(getString(R.string.item_user_info, userName, userName,
                TimeUtil.beautify(article.getCreatedAt())));
    } else {
        subTitle = getString(R.string.item_detail_subtitle, userName);
    }

    mArticleDescription.setText(subTitle);
}

From source file:org.asqatasun.rules.doc.utils.rga33.extractor.Rgaa3Extractor.java

private static void createTestcaseFiles() throws IOException {
    File srcDir = new File(RGAA3_TESTCASE_PATH);
    for (File file : srcDir.listFiles()) {
        String fileName = file.getName().replace("Rgaa30Rule", "").replace(".java", "");
        String theme = fileName.substring(0, 2);
        String crit = fileName.substring(2, 4);
        String test = fileName.substring(4, 6);
        String testKey = Integer.valueOf(theme).toString() + "-" + Integer.valueOf(crit).toString() + "-"
                + Integer.valueOf(test).toString();
        String wrongKey = theme + "." + crit + "." + test;
        for (File testcase : file.listFiles()) {
            if (testcase.isFile() && testcase.getName().contains("html")) {
                Document doc = Jsoup.parse(FileUtils.readFileToString(testcase));
                Element detail = doc.select(".test-detail").first();
                if (detail == null) {
                    System.out.println(doc.outerHtml());
                } else {
                    detail.tagName("div");
                    detail.text("");
                    for (Element el : detail.children()) {
                        el.remove();//ww  w  .j  a  v a  2  s  .c o m
                    }
                    if (!detail.hasAttr("lang")) {
                        detail.attr("lang", "fr");
                    }
                    detail.append("\n" + RGAA3.get(testKey).ruleRawHtml + "\n");
                    doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
                    doc.outputSettings().outline(false);
                    doc.outputSettings().indentAmount(4);
                    String outputHtml = doc.outerHtml();
                    if (outputHtml.contains(wrongKey)) {
                        outputHtml = outputHtml.replaceAll(wrongKey, RGAA3.get(testKey).getRuleDot());
                    }
                    FileUtils.writeStringToFile(testcase, outputHtml);
                }
            }
        }
    }
}