allcolor/YaHP-Converter — Issue #1: Bug on parsing links in CHtmlToPdfFlyingSaucerTransformer 1.3
Author: sanakrom
Created: 2012-01-13 14:12:56+00:00
State: open

Hi,
There is a bug in the "for" instruction code line 705: some links are forgotten by the algorithm. I replace the code and add a "print" media filter :
int previousLength = linknl.getLength();
Element e = (Element)linknl.item(zi);

if ("stylesheet".equals(e.getAttribute("rel")) && "print".equals(e.getAttribute("media")) ) {
String url = normalizeLink(urlForBase, e.getAttribute("href"));
InputStream iin = null;
try {
iin = new URL(url).openStream();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int iNbByteRead = -1;
byte bbuffer[] = new byte[16384];

while ((iNbByteRead = iin.read(bbuffer)) != -1) {
bOut.write(bbuffer, 0, iNbByteRead);
} // end while
String document = new String(bOut.toByteArray(), "utf-8");
CSSStyleSheet sheet = CCSSParser.parse(document, null,
null, url);
if (sheet != null) {
Element style = mydoc.createElement("style");
style.setAttribute("type", "text/css");
style.setTextContent(sheet.toString());
e.getParentNode().insertBefore(style, e);
e.getParentNode().removeChild(e);
}
} // end try
catch (final Throwable ignore) {
} // end catch
finally {
try{iin.close();}catch(Throwable ignore){}
}