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);
}
}
}
}