Package net.sf.jpluck.plucker.parsing.html

Source Code of net.sf.jpluck.plucker.parsing.html.ImageHandler

package net.sf.jpluck.plucker.parsing.html;

import net.sf.jpluck.plucker.Paragraph;
import net.sf.jpluck.util.URIUtil;

public class ImageHandler extends EmptyTagHandler {
    public void start(HTMLSerializer ser, StyledElement elem) {
        String src = elem.getAttributes().getValue("src");
        try {
            src = URIUtil.fixURI(src);
            String url = ser.resolveLink(src);
            // As a precaution we remove any anchors. (These should not occur in image links in the first place.)
            url = URIUtil.removeAnchor(url);

            Paragraph p = ser.getCurrentParagraph();
            p.addEmbeddedImage(url, elem.getAttributes().getValue("alt"));
            if (ser.isIncludeImages()) {
                ser.addEmbeddedImageURL(url);
            }
        } catch (Exception e) {
            // Invalid URL or null
            if (src != null) {
                ser.addInvalidURL(src);
            }
        }
    }
}
TOP

Related Classes of net.sf.jpluck.plucker.parsing.html.ImageHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.