Example usage for org.jsoup.nodes Element after

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

Introduction

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

Prototype

@Override
public Element after(Node node) 

Source Link

Document

Insert the specified node into the DOM after this node (as a following sibling).

Usage

From source file:com.geecko.QuickLyric.lyrics.LyricWiki.java

public static Lyrics fromURL(String url, String artist, String song) {
    if (url.endsWith("action=edit")) {
        return new Lyrics(NO_RESULT);
    }/*from  w  ww. j  a  v  a  2 s.  c  om*/
    String text;
    try {
        //url = URLDecoder.decode(url, "utf-8");
        Document lyricsPage = Jsoup.connect(url).get();
        Element lyricbox = lyricsPage.select("div.lyricBox").get(0);
        lyricbox.after(lyricbox.childNode(0));
        String lyricsHtml = lyricbox.html();
        text = lyricsHtml.substring(0, lyricsHtml.indexOf("<!--")).replaceAll("<.*?>", "").replaceAll("\n",
                "<br />");
        if (text.contains("&#"))
            text = Parser.unescapeEntities(text, true);
    } catch (IndexOutOfBoundsException | IOException e) {
        e.printStackTrace();
        return new Lyrics(ERROR);
    }

    if (artist == null)
        artist = url.substring(24).replace("Gracenote:", "").split(":", 2)[0].replace('_', ' ');
    if (song == null)
        song = url.substring(24).replace("Gracenote:", "").split(":", 2)[1].replace('_', ' ');

    try {
        artist = URLDecoder.decode(artist, "UTF-8");
        song = URLDecoder.decode(song, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    if (text.contains(
            "Unfortunately, we are not licensed to display the full lyrics for this song at the moment.")
            || text.equals("Instrumental <br />")) {
        Lyrics result = new Lyrics(NEGATIVE_RESULT);
        result.setArtist(artist);
        result.setTitle(song);
        return result;
    } else if (text.equals("") || text.length() < 3)
        return new Lyrics(NO_RESULT);
    else {
        Lyrics lyrics = new Lyrics(POSITIVE_RESULT);
        lyrics.setArtist(artist);
        lyrics.setTitle(song);
        lyrics.setText(text);
        lyrics.setSource("LyricsWiki");
        lyrics.setURL(url);
        return lyrics;
    }
}

From source file:com.iorga.iraj.servlet.AgglomeratorServlet.java

private long searchAndAppendAfter(final ServletConfig config, final Element agglomerateElement,
        final String scriptSrc, final String pathPrefix, final String pathSuffix, final String urlAttribute,
        long lastModified) throws MalformedURLException, IOException, URISyntaxException {
    if (mode == Mode.DEVELOPMENT) {
        // add a watch for that directory
        final Path path = Paths.get(config.getServletContext().getRealPath(scriptSrc));
        path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE);
    }/* w w  w  .j a v a2s .  c o m*/
    final Set<String> childrenPaths = config.getServletContext().getResourcePaths(scriptSrc);
    for (final String path : childrenPaths) {
        if (path.endsWith(pathSuffix)) {
            // add that JS
            final StringBuilder targetScript = new StringBuilder("<");
            targetScript.append(agglomerateElement.tagName());
            // copy all the origin attributes
            for (final Attribute attribute : agglomerateElement.attributes()) {
                final String key = attribute.getKey();
                if (!ATTRIBUTE_NAME.equalsIgnoreCase(key) && !urlAttribute.equalsIgnoreCase(key)
                        && !URL_ATTRIBUTE_ATTRIBUTE_NAME.equalsIgnoreCase(key)) {
                    targetScript.append(" ").append(attribute.html());
                }
            }
            // specify the src path
            final String childUrl = StringUtils.removeStart(path, pathPrefix);
            targetScript.append(" ").append(new Attribute(urlAttribute, childUrl).html()).append(" />");
            agglomerateElement.after(targetScript.toString());
            lastModified = Math.max(
                    config.getServletContext().getResource(childUrl).openConnection().getLastModified(),
                    lastModified);
        } else if (path.endsWith("/")) {
            // it's a directory, recurse search & append
            lastModified = Math.max(searchAndAppendAfter(config, agglomerateElement, path, pathPrefix,
                    pathSuffix, urlAttribute, lastModified), lastModified);
        }
    }
    return lastModified;
}

From source file:moose.com.ac.ArticleViewActivity.java

private void filterImg(String str) {
    Document mDocument = Jsoup.parse(str);

    Elements imgs = mDocument.select("img");
    for (int imgIndex = 0; imgIndex < imgs.size(); imgIndex++) {
        Element img = imgs.get(imgIndex);
        String src = img.attr("src").trim();
        if (TextUtils.isEmpty(src))
            continue;
        Uri parsedUri = Uri.parse(src);/*w ww  . java2 s  .c  om*/
        if ("file".equals(parsedUri.getScheme()))
            continue;
        if (parsedUri.getPath() == null)
            continue;
        if (!"http".equals(parsedUri.getScheme())) {
            parsedUri = parsedUri.buildUpon().scheme("http").authority("www.acfun.tv").build();
        }
        // url may have encoded path
        parsedUri = parsedUri.buildUpon().path(parsedUri.getPath()).build();
        src = parsedUri.toString();
        Log.i(TAG, "image src:" + src);
        img.attr("org", src);
        if (CommonUtil.getMode() == 1 && !CommonUtil.isWifiConnected(mContext)) {//
            Log.i(TAG, "[?]");
            img.after("<div style=\"width: 100%;text-align: center;\"><br><p>[]</p></div>");
        } else {
            Log.i(TAG, "[?]");
            StringBuilder builder = new StringBuilder();
            builder.append("<div style='text-align: center;'><br>")
                    .append("<img src='file:///android_asset/loading.gif'").append("name = '").append(src)
                    .append("'\n;onclick = window.JsBridge.showImage('").append(src).append("')")
                    .append(" alt=' '/>\n").append("</div>");
            img.after(builder.toString());
            Log.i(TAG, "image:table:-" + builder.toString());
        }
        /*if (CommonUtil.getMode() == 1 && !CommonUtil.isWifiConnected(mContext)) {
        img.after("<p >[]</p>");
        } else if (!src.contains(Config.AC_EMOTION)) {
        StringBuilder builder = new StringBuilder();
        builder.append("<div style=\"width: 100%;text-align: center;\"><br><img src=\"")
                .append(src)
                .append("\" width=: 100%;height:auto\"")
                .append(" alt=\" \"/>\n")
                .append("</div>");
        Log.i(TAG, "index image:" + builder.toString());
        img.after(builder.toString());
        } else {
        img.after("<img src=\"" + src + "\" alt=\" \"/>\n");
        }*/

        img.remove();
        //img.removeAttr("style");
        HtmlBody = mDocument.toString();
        Log.i(TAG, "??html:" + HtmlBody);
    }
}

From source file:org.keionline.keionline.ArticleView.java

private String getContent(String url) throws IOException {
    Document doc = Jsoup.connect(url).userAgent("Mozilla").get();
    Element data = doc.getElementsByClass("node").first();// get the third content div,
    Elements select = data.select("img");
    // Change the links to absolute!! so that images work
    for (Element e : select) {
        e.attr("src", e.absUrl("src"));
    }//from   w w w .  j a va2s .  c o m
    select = data.select("a");
    for (Element e : select) {
        e.attr("href", e.absUrl("href"));
    }
    Element info = data.getElementsByClass("submitted").first();
    info.after("<hr>");
    String cont = data.toString();
    cont = CSS + cont + "</body>";
    content = cont;
    return cont;
}