-
1. Re: PDF mail attachment with iso-8859-1 encoding is corrupt
mrblacksmith Sep 30, 2009 11:32 PM (in response to mrblacksmith)It seems to me that this is an issue due to the implementation of org.jboss.seam.mail.ui.UIAttachment. It will only render a pdf/excel file if the first line/child in the (pdf/excel) xhtml template contains a pdf/excel tag. If I add a
<?xml version="1.0" encoding="iso-8859-1"?>
line at the top of my pdf template it will fail when added as an attachment, but it will be renderder correct to a pdf when not used as an attachment.
I rewrote it a bit and performed a simple test, and now I can display iso-8859-1 characters (like swedish 'åäö') in the attached pdf.
Here's a patch:
Index: UIAttachment.java =================================================================== --- UIAttachment.java (revision 11528) +++ UIAttachment.java (working copy) @@ -5,12 +5,14 @@ import java.io.InputStream; import java.lang.reflect.Method; import java.net.URL; +import java.util.List; import javax.activation.DataHandler; import javax.activation.DataSource; import javax.activation.FileDataSource; import javax.activation.URLDataSource; import javax.faces.FacesException; +import javax.faces.component.UIComponent; import javax.faces.component.ValueHolder; import javax.faces.context.FacesContext; import javax.faces.convert.Converter; @@ -85,11 +87,11 @@ public void encodeBegin(FacesContext context) throws IOException { if (this.getChildCount() > 0) { - if (Reflections.isInstanceOf(this.getChildren().get(0).getClass(), "org.jboss.seam.pdf.ui.UIDocument") || - Reflections.isInstanceOf(this.getChildren().get(0).getClass(), "org.jboss.seam.excel.ui.UIWorkbook")) + UIComponent uiComponent = findUIComponent(); + if (uiComponent != null) { - Method method = Reflections.getSetterMethod(this.getChildren().get(0).getClass(), "sendRedirect"); - Reflections.invokeAndWrap(method, this.getChildren().get(0), false); + Method method = Reflections.getSetterMethod(uiComponent.getClass(), "sendRedirect"); + Reflections.invokeAndWrap(method, uiComponent, false); JSF.renderChildren(context, this); } else { setValue(encode(context).getBytes()); @@ -101,6 +103,22 @@ } } + private static String PDF_CLASS = "org.jboss.seam.pdf.ui.UIDocument"; + private static String EXCEL_CLASS = "org.jboss.seam.excel.ui.UIWorkbook"; + + private UIComponent findUIComponent() + { + List<UIComponent> children = this.getChildren(); + for (UIComponent uiComponent : children) + { + if (Reflections.isInstanceOf(uiComponent.getClass(), PDF_CLASS) || Reflections.isInstanceOf(uiComponent.getClass(), EXCEL_CLASS)) + { + return uiComponent; + } + } + return null; + } + @Override public void encodeEnd(FacesContext context) throws IOException {
I don't know if this fix has any other implications, is there anyone here who could give their view on the fix?
-
2. Re: PDF mail attachment with iso-8859-1 encoding is corrupt
mrblacksmith Oct 2, 2009 8:30 AM (in response to mrblacksmith)http://www.seamframework.org/Community/Contribute
First, please ask on the Seam Users Forum if your problem is really related to a bug in Seam. If it is related to a bug in Seam, search the JIRA issue database for similar problems. Only if you did not find a reported bug, and other users and developers on the forum confirmed that you found a bug, please report itOK, so what do you say guys, is this a confirmed bug or not? I cannot find any related bug in JIRA and I have a patch - shall I add an issue in JIRA?