Example usage for org.jsoup.nodes Document append

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

Introduction

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

Prototype

public Element append(String html) 

Source Link

Document

Add inner HTML to this element.

Usage

From source file:org.jasig.portlet.proxy.service.proxy.document.HeaderFooterFilter.java

@Override
public void filter(Document document, IContentResponse proxyResponse, RenderRequest portletRequest,
        RenderResponse portletResponse) {

    // get any configured header / footer content from the portlet preferences
    final PortletPreferences preferences = portletRequest.getPreferences();
    final String header = preferences.getValue(HEADER_KEY, null);
    final String footer = preferences.getValue(FOOTER_KEY, null);

    // If both a header and footer have been specified, there's some chance they 
    // could be intended to wrap the proxied content.  We can't wrap content 
    // using the prepend / append methods, since those would automatically 
    // close partial elements in each header / footer
    if (StringUtils.isNotBlank(header) && StringUtils.isNotBlank(footer)) {
        document.html(header.concat(document.html()).concat(footer));
    }//from w w w.j  ava 2  s .  c  om

    else if (StringUtils.isNotBlank(header)) {
        document.prepend(header);
    }

    else if (StringUtils.isNotBlank(footer)) {
        document.append(footer);
    }

}

From source file:org.cellcore.code.engine.page.extractor.starcity.STCPageDataExtractor.java

protected Card jsonProc(String id, Document doc) {
    HttpClient httpClient = new HttpClient();

    try {//from   w ww. j a  va  2 s  .  c  o m
        String callbackVal = "JQueryS_23ss3sLIJ2211";
        GetMethod getMethod = new GetMethod("http://sales.starcitygames.com/cart_product_ajax.php?callback="
                + callbackVal + "&product=" + id + "&qty=1&mode=login");
        int statusCode = httpClient.executeMethod(getMethod);
        if (statusCode == 200) {
            String resp = getMethod.getResponseBodyAsString().replaceAll(callbackVal, "").replaceAll("\\(", "")
                    .replaceAll("\\)", "");
            getMethod.releaseConnection();
            Map<String, Object> values = GsonUtils.getSerializer().fromJson(resp, Map.class);
            String name = "";
            String price = "-1";
            if ((Boolean) values.get("success")) {
                String feedback = (String) values.get("feedback");
                name = feedback.substring(0, feedback.lastIndexOf("was added"));
                price = feedback.substring(feedback.lastIndexOf("$") + 1, feedback.length() - 1);
            } else {
                String error = (String) values.get("error_message");
                name = error.substring(error.lastIndexOf(" on ") + 3, error.lastIndexOf(","));
            }

            doc.append("<div id=\"custom_card_name_STC\">" + name + "</div>");
            doc.append("<div id=\"custom_card_price_STC\">" + price + "</div>");
        }

    } catch (UnsupportedEncodingException e) {
        logger.error("", e);
    } catch (HttpException e) {
        logger.error("", e);
    } catch (IOException e) {
        logger.error("", e);
    }
    return null;
}