From seam-commits at lists.jboss.org Fri Oct 24 02:44:38 2008 Content-Type: multipart/mixed; boundary="===============3874275932821299012==" MIME-Version: 1.0 From: seam-commits at lists.jboss.org To: seam-commits at lists.jboss.org Subject: [seam-commits] Seam SVN: r9407 - in trunk: examples/itext/src/org/jboss/seam/example/pdf and 2 other directories. Date: Fri, 24 Oct 2008 02:44:38 -0400 Message-ID: --===============3874275932821299012== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: nickarls Date: 2008-10-24 02:44:38 -0400 (Fri, 24 Oct 2008) New Revision: 9407 Added: trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java trunk/examples/itext/view/fillform.xhtml trunk/examples/itext/view/form.pdf trunk/examples/itext/view/form.xhtml Modified: trunk/doc/Seam_Reference_Guide/en-US/Itext.xml trunk/examples/itext/view/index.xhtml trunk/src/pdf/org/jboss/seam/pdf/ui/FormComponent.java trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java Log: JBSEAM-681 PDF fill-in-forms support Modified: trunk/doc/Seam_Reference_Guide/en-US/Itext.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/doc/Seam_Reference_Guide/en-US/Itext.xml 2008-10-24 06:21:57 UTC = (rev 9406) +++ trunk/doc/Seam_Reference_Guide/en-US/Itext.xml 2008-10-24 06:44:38 UTC = (rev 9407) @@ -2293,7 +2293,124 @@ = +
+ Fill-in-forms + + If you have a complex, pre-generated PDF with named fields, you c= an easily + fill in the values from you application and present it to the use= r. + = + + + + + + + + + + <p:form> + + + + + Description + + Defines a form template to populate + + + Attributes + + + + + + URL — An = URL pointing + to the PDF file to use as a templa= te. If the value + has no protocol part (://), the fi= le is read locally. + + + + + filename —= ; The filename + to use for the generated PDF file. + + + + + exportKey ̵= 2; Place the generated + PDF file in a DocumentData object = under the specified key + in the event context. If set, no r= edirect will occur. + + + + + + + + + = + + + + + + + + + + <p:field> + + + + + Description + + Connects a field name to its value + + + Attributes + + + + + + + name — Th= e name + of the field + + + + + value — T= he value + of the field + + + + + readOnly —= ; Should the field + be read-only? Defaults to true. + + + + + + + + + + + + + + ]]> + = +
+ +
Rendering Swing/AWT components Seam now provides experimental support for rendering Swing c= omponents to into a PDF Added: trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java = (rev 0) +++ trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java 20= 08-10-24 06:44:38 UTC (rev 9407) @@ -0,0 +1,144 @@ +package org.domain.PDF.session; + +import java.util.ArrayList; +import java.util.List; + +import javax.faces.model.SelectItem; + +import org.jboss.seam.ScopeType; +import org.jboss.seam.annotations.Create; +import org.jboss.seam.annotations.Name; +import org.jboss.seam.annotations.Scope; + +(a)Name("fillInForms") +(a)Scope(ScopeType.SESSION) +public class FillInForms { + private String name; + private String address; + private String postalCode; + private String email; + private String[] programming; + private String language; + private String preferred; + private List knowledge; + private List programmingLanguages; + private List languages; + = + = + public List getKnowledge() { + return knowledge; + } + + public void setKnowledge(List knowledge) { + this.knowledge =3D knowledge; + } + + + public List getLanguages() { + return languages; + } + + public void setLanguages(List languages) { + this.languages =3D languages; + } + + public List getProgrammingLanguages() { + return programmingLanguages; + } + + public void setProgrammingLanguages(List programmingLanguages= ) { + this.programmingLanguages =3D programmingLanguages; + } + + @Create + public void init() { + knowledge =3D new ArrayList(); + programmingLanguages =3D new ArrayList(); + programmingLanguages.add(new SelectItem("JAVA", "Java")); + programmingLanguages.add(new SelectItem("C", "C/C++")); + programmingLanguages.add(new SelectItem("CS", "C#")); + programmingLanguages.add(new SelectItem("VB", "VB")); + languages =3D new ArrayList(); + languages.add(new SelectItem("EN", "English")); + languages.add(new SelectItem("FR", "French")); + languages.add(new SelectItem("NL", "Dutch")); + knowledge.add("FR"); + language =3D "FR"; + preferred =3D "FR"; + } + = + public String getName() { + return name; + } + + public void setName(String name) { + this.name =3D name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address =3D address; + } + + public String getPostalCode() { + return postalCode; + } + + public void setPostalCode(String postalCode) { + this.postalCode =3D postalCode; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email =3D email; + } + + public String[] getProgramming() { + return programming; + } + + public void setProgramming(String[] programming) { + this.programming =3D programming; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language =3D language; + } + + public String getPreferred() { + return preferred; + } + + public void setPreferred(String preferred) { + this.preferred =3D preferred; + } + = + public String submit() { + return "/form.xhtml"; + } + = + public boolean isKnowsEnglish() { + boolean knows =3D knowledge.contains("EN"); + System.out.println("Retuning " + knows); + return knows; + } + = + public boolean isKnowsFrench() { + return knowledge.contains("FR"); + } + + public boolean isKnowsDutch() { + return knowledge.contains("NL"); + } + +} Added: trunk/examples/itext/view/fillform.xhtml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/examples/itext/view/fillform.xhtml (rev 0) +++ trunk/examples/itext/view/fillform.xhtml 2008-10-24 06:44:38 UTC (rev 9= 407) @@ -0,0 +1,47 @@ + + + + + + Seam PDF Fill-in-forms + + + = + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + = + = + Added: trunk/examples/itext/view/form.pdf =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/examples/itext/view/form.pdf (rev 0) +++ trunk/examples/itext/view/form.pdf 2008-10-24 06:44:38 UTC (rev 9407) @@ -0,0 +1,126 @@ +%PDF-1.4 +%=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD +10 0 obj<> +endobj +11 0 obj<> +endobj +19 0 obj<>/V/EN/AP<>>>>> +endobj +20 0 obj<>/V/Off/AP<>>>>> +endobj +21 0 obj<>/V/Off/AP<>>>>> +endobj +12 0 obj<> +endobj +22 0 obj<>/T(English)/V/Off/AP<>>>>> +endobj +23 0 obj<>/T(French)/V/Off/AP<>>>>> +endobj +24 0 obj<>/T(Dutch)/V/Off/AP<>>>>> +endobj +13 0 obj<>>>/T= (name)/V()/AP<>/Parent 10 0 R/BS<>/FT/Tx/Rect[298.5 785= 505.7 805]/DA(/Helv 12 Tf 0 g )>> +endobj +14 0 obj<>>>/T= (address)/V()/AP<>/Parent 10 0 R/BS<>/FT/Tx/Rect[298.5 = 763 505.7 783]/DA(/Helv 12 Tf 0 g )>> +endobj +15 0 obj<>>>/T= (postal_code)/V()/AP<>/Parent 10 0 R/BS<>/FT/Tx/Rect[29= 8.5 741 505.7 761]/DA(/Helv 12 Tf 0 g )>> +endobj +16 0 obj<>>>/T= (email)/V()/AP<>/Parent 10 0 R/BS<>/FT/Tx/Rect[298.5 71= 9 505.7 739]/DA(/Helv 12 Tf 0 g )>> +endobj +17 0 obj<>>>/DV(JAVA)/T(programming)/V(JAVA)/AP<>/Opt[[(JAVA)(Java)][(C)(= C/C++)][(CS)(C#)][(VB)(VB)]]/Parent 10 0 R/BS<>/FT/Ch/Rect[297.5 = 668 506.7 718]/DA(/Helv 9 Tf 0 g )>> +endobj +18 0 obj<= >>>/DV(EN)/T(language)/V(EN)/AP<>/Opt[[(EN)(English)][(FR)(French= )][(NL)(Dutch)]]/Parent 10 0 R/BS<>/FT/Ch/Rect[297.5 646 506.7 66= 8]/DA(/Helv 9 Tf 0 g )>> +endobj +25 0 obj <>stream +x=EF=BF=BD=EF=BF=BD=EF=BF=BD]o=EF=BF=BD0=14=EF=BF=BD=EF=BF=BD=EF=BF=BD+=EF= =BF=BD=EF=BF=BDv1=EF=BF=BD=16Z=EF=BF=BD.=EF=BF=BD=EF=BF=BD}$=EF=BF=BDq=EF= =BF=BDK"=15=D9=80=C6=A2=EF=BF=BD=EF=AF=B6=EF=BF=BDh=EF=BF=BD]=0C!=EF=BF=BD<= <=3D}=0F9=DD=A0=EF=BF=BD=02=EF=BF=BD=1C=04=EF=BF=BDPT=08=EF=BF=BD=03e=EF=BF= =BDmZ=EF=BF=BD=05=EF=BF=BD=D8=9B=C2=9B=01=EF=BF=BD=08'=0C=EF=BF=BDH=EF=BF= =BD$=EF=BF=BD=EF=BF=BD=C8=80=EF=BF=BD<=EF=BF=BD@)h=EF=BF=BD=EF=BF=BD=EF=BF= =BD=EF=BF=BD=EF=BF=BD=13=EF=BF=BD=0CQ=EF=BF=BDr=1AS=03=D4=A9=19=EF=BF=BD=EF= =BF=BD=01=EF=BF=BDT"bj=EF=BF=BDZ=EF=BF=BD=EF=BF=BD=13d=EF=BF=BDZ +Q=EF=BF=BDf>>>/MediaBox[0 0 595 842]= /Annots[19 0 R 20 0 R 21 0 R 22 0 R 23 0 R 24 0 R 13 0 R 14 0 R 15 0 R 16 0= R 17 0 R 18 0 R]>> +endobj +4 0 obj<> +endobj +5 0 obj <>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0= ]/Length 22/FormType 1/Filter/FlateDecode>>stream +x=EF=BF=BD+T=08T=EF=BF=BD=0F=EF=BF=BDPp=EF=BF=BDuVp=05b +endstream +endobj +6 0 obj <>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0= ]/Length 22/FormType 1/Filter/FlateDecode>>stream +x=EF=BF=BD+T=08T=EF=BF=BD=0F=EF=BF=BDPp=EF=BF=BDuVp=05b +endstream +endobj +1 0 obj <>/Subtype/Form/BBox[0 0 20 20]/Matrix [1 0 0 1 0 0]/Length 8/FormTyp= e 1/Filter/FlateDecode>>stream +x=EF=BF=BD=03 +endstream +endobj +9 0 obj <>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0= ]/Length 85/FormType 1/Filter/FlateDecode>>stream +x=EF=BF=BD+T=08T=EF=BF=BD=0F=EF=BF=BDPp=EF=BF=BDuV(T0=04B]#=10*JU=08W=EF= =BF=BD=03 +9=EF=BF=BD +=1A=EF=BF=BDy=EF=BF=BD9=EF=BF=BD=EF=BF=BD=19=EF=BF=BD!Y`=EF=BF=BDk=08=EF= =BF=BD=EF=BF=BD@=05W=EF=BF=BD=EF=BF=BD +endstream +endobj +8 0 obj <>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0= ]/Length 121/FormType 1/Filter/FlateDecode>>stream +x=EF=BF=BD=15N=EF=BF=BD +=EF=BF=BD0=14=EF=BF=BD=EF=BF=BD=1C=EF=BF=BD=EF=BF=BDjS=EF=BF=BDa=EF=BF=BD= =EF=BF=BD0=06;=08=0Fv=EF=BF=BD=EF=BF=BD=05q=EF=BF=BD=1Ed=EF=BF=BD=EF=BF=BD= =EF=BF=BD<=08$y!;=06T=EF=BF=BDC=EF=BF=BD=EE=B0=83=EF=BF=BD-=EF=BF=BD;&|=EF= =BF=BD=EF=BF=BD;_=EF=BF=BD=10=C4=8Cd#=EF=BF=BD=EF=BF=BD?=12=EF=BF=BD\=EF=BF= =BD=EF=BF=BD=EF=BF=BD%L=EF=BF=BD=EF=BF=BDcVEkr=EF=BF=BD@=EF=BF=BD(=EF=BF=BD= =EF=BF=BD=EF=BF=BD}Q=3D=EF=BF=BD=EF=BF=BDD=EF=BF=BD=EF=BF=BD=EF=BF=BD3.=EF= =BF=BD=EF=BF=BD=1C=EF=BF=BD=EF=BF=BD(=EF=BF=BD=D1=9B6=0C=EF=BF=BD=EF=BF=BD= =0F=EF=BF=BD=EF=BF=BD=1F=EF=BF=BD +endstream +endobj +7 0 obj <>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0= ]/Length 22/FormType 1/Filter/FlateDecode>>stream +x=EF=BF=BD+T=08T=EF=BF=BD=0F=EF=BF=BDPp=EF=BF=BDuVp=05b +endstream +endobj +3 0 obj <>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0= ]/Length 22/FormType 1/Filter/FlateDecode>>stream +x=EF=BF=BD+T=08T=EF=BF=BD=0F=EF=BF=BDPp=EF=BF=BDuVp=05b +endstream +endobj +2 0 obj <>/Subtype/Form/BBox[0 0 20 20]/Matrix [1 0 0 1 0 0]/Length 26/FormTy= pe 1/Filter/FlateDecode>>stream +x=EF=BF=BD3P0P=EF=BF=BDU02 + +endstream +endobj +26 0 obj<> +endobj +28 0 obj<>>>>> +endobj +29 0 obj<> +endobj +30 0 obj<> +endobj +xref +0 31 +0000000000 65535 f = +0000003730 00000 n = +0000005055 00000 n = +0000004816 00000 n = +0000003165 00000 n = +0000003252 00000 n = +0000003491 00000 n = +0000004577 00000 n = +0000004238 00000 n = +0000003936 00000 n = +0000000015 00000 n = +0000000107 00000 n = +0000000612 00000 n = +0000001154 00000 n = +0000001345 00000 n = +0000001539 00000 n = +0000001737 00000 n = +0000001929 00000 n = +0000002197 00000 n = +0000000197 00000 n = +0000000334 00000 n = +0000000473 00000 n = +0000000686 00000 n = +0000000843 00000 n = +0000000999 00000 n = +0000002453 00000 n = +0000005280 00000 n = +0000002914 00000 n = +0000005332 00000 n = +0000005414 00000 n = +0000005476 00000 n = +trailer +<<6eb921975310bfe3f357= a5cc656b98da>]/Info 30 0 R/Size 31>> +startxref +5610 +%%EOF Added: trunk/examples/itext/view/form.xhtml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/examples/itext/view/form.xhtml (rev 0) +++ trunk/examples/itext/view/form.xhtml 2008-10-24 06:44:38 UTC (rev 9407) @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file Modified: trunk/examples/itext/view/index.xhtml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/examples/itext/view/index.xhtml 2008-10-24 06:21:57 UTC (rev 9406) +++ trunk/examples/itext/view/index.xhtml 2008-10-24 06:44:38 UTC (rev 9407) @@ -45,6 +45,7 @@ []
  • =
  • +
  • = = Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/FormComponent.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/src/pdf/org/jboss/seam/pdf/ui/FormComponent.java 2008-10-24 06:21= :57 UTC (rev 9406) +++ trunk/src/pdf/org/jboss/seam/pdf/ui/FormComponent.java 2008-10-24 06:44= :38 UTC (rev 9407) @@ -6,6 +6,7 @@ public abstract class FormComponent extends UIComponentBase { protected static final String FIELDS_KEY =3D "acrofields"; + protected static final String STAMPER_KEY =3D "acrostamper"; = protected Object valueOf(String name, Object defaultValue) { Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java 2008-10-24 06:21:57 UT= C (rev 9406) +++ trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java 2008-10-24 06:44:38 UT= C (rev 9407) @@ -1,38 +1,95 @@ package org.jboss.seam.pdf.ui; = import java.io.IOException; +import java.util.Iterator; +import java.util.Map; = import javax.faces.FacesException; +import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; = import org.jboss.seam.contexts.Contexts; import org.jboss.seam.core.Interpolator; +import org.jboss.seam.log.Log; +import org.jboss.seam.log.Logging; = import com.lowagie.text.DocumentException; import com.lowagie.text.pdf.AcroFields; +import com.lowagie.text.pdf.PdfStamper; = public class UIField extends FormComponent { public static final String COMPONENT_FAMILY =3D "org.jboss.seam.pdf.UIF= ield"; + private static Log log =3D Logging.getLog(FormComponent.class); = private String name; - private String value; + private Object value; + private Boolean readOnly =3D Boolean.TRUE; = @Override public void encodeBegin(FacesContext facesContext) throws IOException { AcroFields fields =3D (AcroFields) Contexts.getEventContext().get(FI= ELDS_KEY); + String theName =3D getName(); + Object theValue =3D getValue(); + if (theValue =3D=3D null) { + return; + } + Boolean readOnly =3D getReadOnly(); try { - fields.setField(getName(), getValue()); + log.debug("Setting field '#0' to value '#1'", theName, theValue); + boolean success =3D false; + if (theValue instanceof String) { + success =3D fields.setField(theName, (String) theValue); + } else if (theValue instanceof String[]){ + success =3D fields.setField(theName, ((String[])theValue)[0]); + } else { + String message =3D Interpolator.instance().interpolate("Field= #0 expected String or String[] but got #0", getName(), theValue.getClass()= .getName()); + throw new IllegalArgumentException(message); + } + if (!success) + { + warnNotFound(fields, theName, theValue); + } + else + { + if (readOnly.booleanValue()) + { + PdfStamper stamper =3D (PdfStamper) Contexts.getEventContex= t().get(STAMPER_KEY); + stamper.partialFormFlattening(theName); + } + } } catch (DocumentException e) { - String message =3D Interpolator.instance().interpolate("Could not= set field #0 to #1", getName(), getValue()); + String message =3D Interpolator.instance().interpolate("Could not= set field '#0' to '#1'", theName, theValue); throw new FacesException(message, e); } } = + private void warnNotFound(AcroFields fields, String theName, Object the= Value) + { + log.warn("Could not set field '#0' to '#1'", theName, theValue); + Map fieldMap =3D fields.getFields(); + if (!fieldMap.containsKey(theName)) + { + log.warn("Could not find field '#0'. Found fields are", theName); + for (Iterator i =3D fieldMap.keySet().iterator(); i.hasNext();) + { + log.warn(i.next()); + } + return; + } + String[] options =3D fields.getListOptionExport(theName); + String[] values =3D fields.getListOptionDisplay(theName); + log.warn("Valid values for #0 are", theName); + for (int i =3D 0; i < options.length; i++) + { + log.warn("'#0' : '#1'", options[i], values[i]); + } + } + @Override public String getFamily() { @@ -49,14 +106,25 @@ this.name =3D name; } = - public String getValue() + public Object getValue() { - return (String) valueOf("value", value); + return valueOf("value", value); } = - public void setValue(String value) + public void setValue(Object value) { this.value =3D value; } = + public Boolean getReadOnly() + { + return (Boolean) valueOf("readOnly", readOnly); + } + + public void setReadOnly(Boolean readOnly) + { + this.readOnly =3D readOnly; + } + = + } Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java 2008-10-24 06:21:57 UTC= (rev 9406) +++ trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java 2008-10-24 06:44:38 UTC= (rev 9407) @@ -1,10 +1,15 @@ package org.jboss.seam.pdf.ui; = import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; = import javax.faces.FacesException; +import javax.faces.component.UIComponent; +import javax.faces.component.ValueHolder; import javax.faces.context.FacesContext; = import org.jboss.seam.contexts.Contexts; @@ -21,93 +26,125 @@ import com.lowagie.text.pdf.PdfReader; import com.lowagie.text.pdf.PdfStamper; = -public class UIForm extends FormComponent -{ - public static final String COMPONENT_FAMILY =3D "org.jboss.seam.pdf.UIF= orm"; +public class UIForm extends FormComponent { + public static final String COMPONENT_FAMILY =3D "org.jboss.seam.pdf.UI= Form"; = - private Log log =3D Logging.getLog(getClass()); + private Log log =3D Logging.getLog(getClass()); = - private String URL; + private String URL; + private String filename; + private String exportKey; = - PdfReader reader; - PdfStamper stamper; - AcroFields fields; - ByteArrayOutputStream buffer; + PdfReader reader; + PdfStamper stamper; + AcroFields fields; + ByteArrayOutputStream buffer; = - public String getURL() - { - return (String) valueOf("URL", URL); - } + public String getURL() { + return (String) valueOf("URL", URL); + } = - public void setURL(String url) - { - URL =3D url; - } + public void setURL(String url) { + URL =3D url; + } = - @Override - public void encodeBegin(FacesContext facesContext) throws IOException - { - reader =3D new PdfReader(new URL(getURL())); - buffer =3D new ByteArrayOutputStream(); - try - { - stamper =3D new PdfStamper(reader, buffer); - } - catch (DocumentException e) - { - throw new FacesException("Could not create PDF stamper", e); - } - fields =3D stamper.getAcroFields(); - Contexts.getEventContext().set(FIELDS_KEY, fields); - } + @Override + public void encodeBegin(FacesContext facesContext) throws IOException { + if (getURL().indexOf("://") < 0) { + reader =3D new PdfReader(getClass().getClassLoader() + .getResourceAsStream(getURL())); + } else { + reader =3D new PdfReader(new URL(getURL())); + } + log.debug("Loading template #0", getURL()); + buffer =3D new ByteArrayOutputStream(); + try { + stamper =3D new PdfStamper(reader, buffer); + Contexts.getEventContext().set(STAMPER_KEY, stamper); + } catch (DocumentException e) { + throw new FacesException("Could not create PDF stamper", e); + } + fields =3D stamper.getAcroFields(); + Contexts.getEventContext().set(FIELDS_KEY, fields); + } = - @Override - public void encodeEnd(FacesContext facesContext) throws IOException - { - stamper.setFormFlattening(true); - try - { - stamper.close(); - } - catch (DocumentException e) - { - throw new FacesException("Could not flush PDF", e); - } + @Override + public void encodeEnd(FacesContext facesContext) throws IOException { + stamper.setFormFlattening(true); + try { + stamper.close(); + } catch (DocumentException e) { + throw new FacesException("Could not flush PDF", e); + } = - String viewId =3D Pages.getViewId(facesContext); - String baseName =3D baseNameForViewId(viewId); - DocumentStore store =3D DocumentStore.instance(); - DocumentType documentType =3D new DocumentData.DocumentType("pdf", "= application/pdf"); - DocumentData documentData =3D new DocumentData(baseName, documentTyp= e, buffer.toByteArray()); - String id =3D store.newId(); - String url =3D store.preferredUrlForContent(baseName, documentType.g= etExtension(), id); - url =3D Manager.instance().encodeConversationId(url, viewId); - store.saveData(id, documentData); - log.info("Redirecting to #0", url); - facesContext.getExternalContext().redirect(url); - } + if (getExportKey() =3D=3D null) { + UIComponent parent =3D getParent(); + if (parent !=3D null && (parent instanceof ValueHolder)) { + log.debug("Storing PDF data in ValueHolder parent"); + ValueHolder valueHolder =3D (ValueHolder) parent; + valueHolder.setValue(buffer.toByteArray()); + return; + } + } = - public static String baseNameForViewId(String viewId) - { - int pos =3D viewId.lastIndexOf("/"); - if (pos !=3D -1) - { - viewId =3D viewId.substring(pos + 1); - } + String viewId =3D Pages.getViewId(facesContext); + String baseName =3D baseNameForViewId(viewId); = - pos =3D viewId.lastIndexOf("."); - if (pos !=3D -1) - { - viewId =3D viewId.substring(0, pos); - } + DocumentStore store =3D DocumentStore.instance(); + DocumentType documentType =3D new DocumentData.DocumentType("pdf", + "application/pdf"); + DocumentData documentData =3D new DocumentData(baseName, documentT= ype, + buffer.toByteArray()); + documentData.setFilename(getFilename()); = - return viewId; - } + if (getExportKey() !=3D null) { + log.debug("Exporting PDF data to event key #0", getExportKey()= ); + Contexts.getEventContext().set(getExportKey(), documentData); + return; + } = - @Override - public String getFamily() - { - return COMPONENT_FAMILY; - } + String id =3D store.newId(); + String url =3D store.preferredUrlForContent(baseName, documentType + .getExtension(), id); + url =3D Manager.instance().encodeConversationId(url, viewId); + store.saveData(id, documentData); + log.debug("Redirecting to #0 for PDF view", url); + facesContext.getExternalContext().redirect(url); + } = + public static String baseNameForViewId(String viewId) { + int pos =3D viewId.lastIndexOf("/"); + if (pos !=3D -1) { + viewId =3D viewId.substring(pos + 1); + } + + pos =3D viewId.lastIndexOf("."); + if (pos !=3D -1) { + viewId =3D viewId.substring(0, pos); + } + + return viewId; + } + + @Override + public String getFamily() { + return COMPONENT_FAMILY; + } + + public String getFilename() { + return (String) valueOf("filename", filename); + } + + public void setFilename(String filename) { + this.filename =3D filename; + } + + public String getExportKey() { + return (String) valueOf("exportKey", exportKey); + } + + public void setExportKey(String exportKey) { + this.exportKey =3D exportKey; + } + } --===============3874275932821299012==--