Java Swing HTML getImgs(final String html)

Here you can find the source of getImgs(final String html)

Description

get Imgs

License

Open Source License

Declaration

public static List<String> getImgs(final String html) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import java.io.Reader;
import java.io.StringReader;

import java.util.LinkedList;
import java.util.List;

import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML.Attribute;
import javax.swing.text.html.HTML.Tag;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;

public class Main {

    public static List<String> getImgs(final String html) throws IOException {
        final List<String> imgs = new LinkedList<String>();
        if (null == html || html.isEmpty()) {
            return imgs;
        }//from w w w  . ja  v a2  s  .  c om
        final Reader r = new StringReader(html);
        ParserDelegator pd = new ParserDelegator();
        pd.parse(r, new HTMLEditorKit.ParserCallback() {
            public void handleSimpleTag(Tag t, MutableAttributeSet a, int pos) {
                if (Tag.IMG.equals(t)) {
                    imgs.add((String) a.getAttribute(Attribute.SRC));
                }
            }
        }, false);
        r.close();
        if (imgs.size() > 0) {
            return imgs;
        } else {
            return null;
        }
    }
}

Related

  1. findElementDown(final String name, final Element parent)
  2. findElementUp(final String name1, final String name2, final Element start)
  3. findLinkElementUp(Element elem)
  4. findLinkUp(Element elem)
  5. getHTMLFromXML(String xml, URL xsl)
  6. getRowIndex(final Element cell)
  7. hasClass(AttributeSet attr, String className)
  8. htmlToPlain(String html)
  9. isUnderline(Element element)