Example usage for org.jsoup.nodes Document body

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

Introduction

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

Prototype

public Element body() 

Source Link

Document

Accessor to the document's body element.

Usage

From source file:elaborate.util.XmlUtil.java

public static String fixXhtml(String badxml) {
    Document doc = Jsoup.parse(badxml);
    doc.outputSettings().indentAmount(0).prettyPrint(false).escapeMode(Entities.EscapeMode.xhtml)
            .charset("UTF-8");
    return doc.body().html().replaceAll(" />", "/>").replace("\u00A0", " ");
    // return Jsoup.clean(badxml, Whitelist.relaxed());
}

From source file:cognition.common.utils.StringTools.java

public static boolean noContentInHtml(String text) {
    if (StringUtils.isBlank(text)) {
        return true;
    }//from ww w  .  j  a v a 2s  . c  o  m
    try {
        Document doc = Jsoup.parse(text);

        String bodyText = doc.body().text();

        return StringUtils.isBlank(bodyText);
    } catch (Exception ex) {
        return false;
    }
}

From source file:net.a2bsoft.buss.http.SendQuery.java

public static String sendQueryBusstuc(String query) {

    String ans = "No answer";

    try {/*from   ww  w.  ja v a 2  s  . c  o  m*/

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("lang", "nor"));
        nameValuePairs.add(new BasicNameValuePair("quest", query));

        Document doc = Jsoup.connect("http://www.idi.ntnu.no:80/~tagore/cgi-bin/busstuc/busq.cgi")
                .data("lang", "nor").data("quest", query).timeout(30000)
                .header("Content-type", "application/x-www-form-urlencoded").header("Accept", "text/plain")
                .post();

        ans = doc.body().text();
    } catch (IOException e) {
        ans = e.toString();
        e.printStackTrace();
    }

    return ans;
}

From source file:net.noday.core.dnspod.Dnspod.java

/**
 * ???//from w w  w .j a  v a 2s  . com
 * @return
 * @throws IOException
 */
public static String domainList() throws IOException {
    Document doc = Jsoup.connect(urlDomainList).data(data).data("type", "all")
            //            .data("offset", "")
            //            .data("length", "")
            //            .data("group_id", "")
            .userAgent(user_agent).post();
    JSONObject o = JSON.parseObject(doc.body().text());
    return o.toString();
}

From source file:net.noday.core.dnspod.Dnspod.java

/**
 * /*w  w w . j a  v a2 s .  c o  m*/
 * domain_id ??ID 
 * sub_domain - ,  www 
 * record_type APIA 
 * record_line API 
 * value - ,  IP:200.200.200.200, CNAME: cname.dnspod.com., MX: mail.dnspod.com.
 * mx {1-20} - MX,  MX 1-20 
 * ttl {1-604800} - TTL1-604800???????
 */
public static String recordCreate(DnsRecord obj) {
    Document doc;
    try {
        doc = Jsoup.connect(urlRecordCreate).data(data).data("domain_id", obj.getDnspodDomainId())
                .data("sub_domain", obj.getSubDomain()).data("record_type", obj.getRecordTypeE().name())
                .data("record_line", "").data("value", obj.getValue()).data("mx", "1")
                .data("ttl", obj.getTtl() + "").userAgent(user_agent).post();
        JSONObject o = JSON.parseObject(doc.body().text());
        String code = o.getJSONObject("status").getString("code");
        if (StringUtils.equals(code, "1")) {
            return o.getJSONObject("record").getString("id");
        }
        throw new DnspodException(o.getJSONObject("status").getString("message"));
    } catch (IOException e) {
        throw new DnspodException(e.getMessage());
    }
}

From source file:net.noday.core.dnspod.Dnspod.java

/**
 * // w w  w. jav a 2  s  . c  o  m
 * domain_id ??ID 
 * record_id ID 
 * sub_domain - ,  www 
 * record_type APIA 
 * record_line API 
 * value - ,  IP:200.200.200.200, CNAME: cname.dnspod.com., MX: mail.dnspod.com.
 * mx {1-20} - MX,  MX 1-20 
 * ttl {1-604800} - TTL1-604800???????
 */
public static String recordModify(DnsRecord obj) {
    try {
        Document doc = Jsoup.connect(urlRecordModify).data(data).data("domain_id", obj.getDnspodDomainId())
                .data("record_id", obj.getDnspodRecordId()).data("sub_domain", obj.getSubDomain())
                .data("record_type", obj.getRecordTypeE().name()).data("record_line", "")
                .data("value", obj.getValue()).data("mx", "1").data("ttl", obj.getTtl() + "")
                .userAgent(user_agent).post();
        JSONObject o = JSON.parseObject(doc.body().text());
        String code = o.getJSONObject("status").getString("code");
        if (StringUtils.equals(code, "1")) {
            return o.getJSONObject("record").getString("id");
        }
        throw new DnspodException(o.getJSONObject("status").getString("message"));
    } catch (IOException e) {
        throw new DnspodException(e.getMessage());
    }
}

From source file:io.andyc.papercut.api.PrintApi.java

/**
 * Parses the HTML returned from the final upload form submission and checks
 * to see if the file was uploaded successfully
 *
 * @param prevElement {Element} - the HTML returned from submitting the
 *                    final file upload form
 *
 * @return {boolean} - true if the file uploaded successfully
 *//*from ww  w.j a  va2s.  co m*/
static boolean didUpload(Document prevElement) {
    return prevElement.body().select("div#main").toString().contains("successfully submitted");
}

From source file:com.sfs.DataFilter.java

/**
 * Strip html comments.//from ww  w  .j a  va2s .  c  o  m
 *
 * @param original the original
 *
 * @return the string
 */
public static String stripHtmlComments(final String original) {

    String html = "";

    if (StringUtils.isNotBlank(original)) {

        String input = StringUtils.replace(original, "--&gt;", "-->");
        input = StringUtils.replace(input, "&lt;!--", "<!--");

        Document doc = Jsoup.parse(input);
        removeComments(doc);
        html = doc.body().html();
    }
    html = Jsoup.clean(html, Whitelist.relaxed());

    return StringUtils.replace(html, "&nbsp;", " ");
}

From source file:com.screenslicer.common.CommonUtil.java

public static Element parseFragment(String string, boolean ascii) {
    Document doc = Jsoup.parseBodyFragment(string);
    sanitize(doc, ascii);/*w  w w.j  a v a  2 s  .com*/
    if (!doc.body().children().isEmpty()) {
        return doc.body().child(0);
    }
    return doc.body();
}

From source file:io.andyc.papercut.api.PrintApi.java

/**
 * Parses the upload from HTML and returns the URL path that the file should
 * be uploaded to./*from w ww.j a  v  a 2  s .c  om*/
 *
 * @param prevElement {Element} - the html to parse
 *
 * @return {String } - the url path to upload a file to e.g. /upload/123
 */
static String getUploadFileUrl(Document prevElement) throws PrintingException {

    Matcher jsMatcher = PrintApi.jsPattern.matcher(prevElement.body().select("script").first().data());
    jsMatcher.find();
    Matcher urlMatcher = PrintApi.urlPattern.matcher(jsMatcher.group());
    if (!urlMatcher.find()) {
        throw new PrintingException("Error parsing out the file upload URL path");
    }
    return urlMatcher.group().replaceAll("\'", "").trim();
}