[seam-commits] Seam SVN: r9407 - in trunk: examples/itext/src/org/jboss/seam/example/pdf and 2 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Oct 24 02:44:38 EDT 2008
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
===================================================================
--- 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 @@
</informaltable>
</section>
+ <section id="itext.fillinforms">
+ <title>Fill-in-forms</title>
+ <para>
+ If you have a complex, pre-generated PDF with named fields, you can easily
+ fill in the values from you application and present it to the user.
+ </para>
+ <informaltable>
+ <tgroup cols="2">
+ <colspec colnum="1" colwidth="1*"/>
+ <colspec colnum="2" colwidth="3*"/>
+
+ <tbody>
+ <row>
+ <entry valign="top">
+ <para>
+ <literal><p:form></literal>
+ </para>
+ </entry>
+ <entry valign="top">
+ <para>
+ <emphasis>Description</emphasis>
+ </para>
+ <para>Defines a form template to populate</para>
+
+ <para>
+ <emphasis>Attributes</emphasis>
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ <literal>URL</literal> — An URL pointing
+ to the PDF file to use as a template. If the value
+ has no protocol part (://), the file is read locally.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>filename</literal> — The filename
+ to use for the generated PDF file.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>exportKey</literal> — Place the generated
+ PDF file in a DocumentData object under the specified key
+ in the event context. If set, no redirect will occur.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+
+ <informaltable>
+ <tgroup cols="2">
+ <colspec colnum="1" colwidth="1*"/>
+ <colspec colnum="2" colwidth="3*"/>
+
+ <tbody>
+ <row>
+ <entry valign="top">
+ <para>
+ <literal><p:field></literal>
+ </para>
+ </entry>
+ <entry valign="top">
+ <para>
+ <emphasis>Description</emphasis>
+ </para>
+ <para>Connects a field name to its value</para>
+
+ <para>
+ <emphasis>Attributes</emphasis>
+ </para>
+
+ <itemizedlist>
+
+ <listitem>
+ <para>
+ <literal>name</literal> — The name
+ of the field
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>value</literal> — The value
+ of the field
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>readOnly</literal> — Should the field
+ be read-only? Defaults to true.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+
+ <programlisting role="XML">
+ <![CDATA[
+ <p:form
+ xmlns:p="http://jboss.com/products/seam/pdf"
+ URL="http://localhost/Concept/form.pdf">
+ <p:field name="person.name" value="Me, myself and I"/>
+ </p:form>
+ ]]>
+ </programlisting>
+ </section>
+
+
<section id="itext.swingcomponents">
<title>Rendering Swing/AWT components</title>
<para>Seam now provides experimental support for rendering Swing components to into a PDF
Added: trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java
===================================================================
--- trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java (rev 0)
+++ trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java 2008-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;
+
+ at Name("fillInForms")
+ at 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<String> knowledge;
+ private List<SelectItem> programmingLanguages;
+ private List<SelectItem> languages;
+
+
+ public List<String> getKnowledge() {
+ return knowledge;
+ }
+
+ public void setKnowledge(List<String> knowledge) {
+ this.knowledge = knowledge;
+ }
+
+
+ public List<SelectItem> getLanguages() {
+ return languages;
+ }
+
+ public void setLanguages(List<SelectItem> languages) {
+ this.languages = languages;
+ }
+
+ public List<SelectItem> getProgrammingLanguages() {
+ return programmingLanguages;
+ }
+
+ public void setProgrammingLanguages(List<SelectItem> programmingLanguages) {
+ this.programmingLanguages = programmingLanguages;
+ }
+
+ @Create
+ public void init() {
+ knowledge = new ArrayList<String>();
+ programmingLanguages = new ArrayList<SelectItem>();
+ 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 = new ArrayList<SelectItem>();
+ languages.add(new SelectItem("EN", "English"));
+ languages.add(new SelectItem("FR", "French"));
+ languages.add(new SelectItem("NL", "Dutch"));
+ knowledge.add("FR");
+ language = "FR";
+ preferred = "FR";
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public void setPostalCode(String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String[] getProgramming() {
+ return programming;
+ }
+
+ public void setProgramming(String[] programming) {
+ this.programming = programming;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ public String getPreferred() {
+ return preferred;
+ }
+
+ public void setPreferred(String preferred) {
+ this.preferred = preferred;
+ }
+
+ public String submit() {
+ return "/form.xhtml";
+ }
+
+ public boolean isKnowsEnglish() {
+ boolean knows = 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
===================================================================
--- trunk/examples/itext/view/fillform.xhtml (rev 0)
+++ trunk/examples/itext/view/fillform.xhtml 2008-10-24 06:44:38 UTC (rev 9407)
@@ -0,0 +1,47 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:s="http://jboss.com/products/seam/taglib"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+ <title>Seam PDF Fill-in-forms</title>
+ <ui:remove><link href="screen.css" rel="stylesheet" type="text/css" /></ui:remove>
+</head>
+<body>
+ <h:form>
+ <h:messages globalOnly="true" styleClass="message" />
+ <h:panelGrid columns="2">
+ <h:outputText value="Your name:" />
+ <h:inputText value="#{fillInForms.name}" />
+ <h:outputText value="Your home address" />
+ <h:inputText value="#{fillInForms.address}" />
+ <h:outputText value="Postal code:" />
+ <h:inputText value="#{fillInForms.postalCode}" />
+ <h:outputText value="Your email address:" />
+ <h:inputText value="#{fillInForms.email}" />
+ <h:outputText value="Programming skills:" />
+ <h:selectManyListbox value="#{fillInForms.programming}">
+ <f:selectItems value="#{fillInForms.programmingLanguages}" />
+ </h:selectManyListbox>
+ <h:outputText value="Mother tongue" />
+ <h:selectOneMenu value="#{fillInForms.language}">
+ <f:selectItems value="#{fillInForms.languages}" />
+ </h:selectOneMenu>
+ <h:outputText value="Preferred language" />
+ <h:selectOneRadio layout="pageDirection" value="#{fillInForms.preferred}">
+ <f:selectItems value="#{fillInForms.languages}" />
+ </h:selectOneRadio>
+ <h:outputText value="Knowledge of" />
+ <h:selectManyCheckbox layout="pageDirection" value="#{fillInForms.knowledge}">
+ <f:selectItems value="#{fillInForms.languages}" />
+ </h:selectManyCheckbox>
+ <h:commandButton value="Submit" action="#{fillInForms.submit}"/>
+ </h:panelGrid>
+ </h:form>
+ </body>
+</html>
+
+
Added: trunk/examples/itext/view/form.pdf
===================================================================
--- 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
+%âãÏÓ
+10 0 obj<</Kids[11 0 R 12 0 R 13 0 R 14 0 R 15 0 R 16 0 R 17 0 R 18 0 R]/T(person)>>
+endobj
+11 0 obj<</Ff 49152/Parent 10 0 R/FT/Btn/Kids[19 0 R 20 0 R 21 0 R]/T(preferred)>>
+endobj
+19 0 obj<</AS/EN/Parent 11 0 R/Type/Annot/Subtype/Widget/Rect[297.5 630 316.52 646]/DR<<>>/V/EN/AP<</N<</EN 2 0 R/Off 1 0 R>>>>>>
+endobj
+20 0 obj<</AS/Off/Parent 11 0 R/Type/Annot/Subtype/Widget/Rect[297.5 614 316.52 630]/DR<<>>/V/Off/AP<</N<</FR 2 0 R/Off 1 0 R>>>>>>
+endobj
+21 0 obj<</AS/Off/Parent 11 0 R/Type/Annot/Subtype/Widget/Rect[297.5 598 316.52 614]/DR<<>>/V/Off/AP<</N<</NL 2 0 R/Off 1 0 R>>>>>>
+endobj
+12 0 obj<</Parent 10 0 R/Kids[22 0 R 23 0 R 24 0 R]/T(knowledge)>>
+endobj
+22 0 obj<</AS/Off/Parent 12 0 R/Type/Annot/Subtype/Widget/Rect[297.5 582 316.52 598]/FT/Btn/DR<<>>/T(English)/V/Off/AP<</N<</Off 1 0 R/On 2 0 R>>>>>>
+endobj
+23 0 obj<</AS/Off/Parent 12 0 R/Type/Annot/Subtype/Widget/Rect[297.5 566 316.52 582]/FT/Btn/DR<<>>/T(French)/V/Off/AP<</N<</Off 1 0 R/On 2 0 R>>>>>>
+endobj
+24 0 obj<</AS/Off/Parent 12 0 R/Type/Annot/Subtype/Widget/Rect[297.5 550 316.52 566]/FT/Btn/DR<<>>/T(Dutch)/V/Off/AP<</N<</Off 1 0 R/On 2 0 R>>>>>>
+endobj
+13 0 obj<</Ff 0/F 4/Type/Annot/Subtype/Widget/DR<</Font<</Helv 4 0 R>>>>/T(name)/V()/AP<</N 3 0 R>>/Parent 10 0 R/BS<</W 1/S/S>>/FT/Tx/Rect[298.5 785 505.7 805]/DA(/Helv 12 Tf 0 g )>>
+endobj
+14 0 obj<</Ff 0/F 4/Type/Annot/Subtype/Widget/DR<</Font<</Helv 4 0 R>>>>/T(address)/V()/AP<</N 5 0 R>>/Parent 10 0 R/BS<</W 1/S/S>>/FT/Tx/Rect[298.5 763 505.7 783]/DA(/Helv 12 Tf 0 g )>>
+endobj
+15 0 obj<</Ff 0/F 4/Type/Annot/Subtype/Widget/DR<</Font<</Helv 4 0 R>>>>/T(postal_code)/V()/AP<</N 6 0 R>>/Parent 10 0 R/BS<</W 1/S/S>>/FT/Tx/Rect[298.5 741 505.7 761]/DA(/Helv 12 Tf 0 g )>>
+endobj
+16 0 obj<</Ff 0/F 4/Type/Annot/Subtype/Widget/DR<</Font<</Helv 4 0 R>>>>/T(email)/V()/AP<</N 7 0 R>>/Parent 10 0 R/BS<</W 1/S/S>>/FT/Tx/Rect[298.5 719 505.7 739]/DA(/Helv 12 Tf 0 g )>>
+endobj
+17 0 obj<</Ff 2097152/F 4/Type/Annot/Subtype/Widget/DR<</Font<</Helv 4 0 R>>>>/DV(JAVA)/T(programming)/V(JAVA)/AP<</N 8 0 R>>/Opt[[(JAVA)(Java)][(C)(C/C++)][(CS)(C#)][(VB)(VB)]]/Parent 10 0 R/BS<</W 1/S/S>>/FT/Ch/Rect[297.5 668 506.7 718]/DA(/Helv 9 Tf 0 g )>>
+endobj
+18 0 obj<</Ff 131072/F 4/Type/Annot/Subtype/Widget/DR<</Font<</Helv 4 0 R>>>>/DV(EN)/T(language)/V(EN)/AP<</N 9 0 R>>/Opt[[(EN)(English)][(FR)(French)][(NL)(Dutch)]]/Parent 10 0 R/BS<</W 1/S/S>>/FT/Ch/Rect[297.5 646 506.7 668]/DA(/Helv 9 Tf 0 g )>>
+endobj
+25 0 obj <</Length 393/Filter/FlateDecode>>stream
+x]o0ïû+Îåv1ÖZË.é}$q³K"ÙÆ¢ñﯶh¥]!<<=}9Ý ç¥æPTÃeömZ Úد'öH$
Èâ<¡@)h¾æóQ§rSÔ©©êT"bjZódøZ
+Q§f<R5DÊòÓº¸Vã§H`
+ÓðÑ#Æ }É6É¢¶ÅAû°³íðíB3§F[Þ6çQÛâ°Í¢
+wøÂ^æ
+ÃoÓ¶A3ßýTÛµÔ°U}½nS¿£s-WRkYÁGi̲sS"ÜPÏöuÛë°a~î¥1Ó²_F=áe·ûÞÆaÂïÂ{¯ö¬j jÂÌi|[fδ0æ÷ê<È¥oaÅ
+endstream
+endobj
+27 0 obj<</Parent 26 0 R/Contents 25 0 R/Type/Page/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</F1 4 0 R>>>>/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<</BaseFont/Helvetica/Type/Font/Encoding/WinAnsiEncoding/Subtype/Type1>>
+endobj
+5 0 obj <</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</Helv 4 0 R>>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0]/Length 22/FormType 1/Filter/FlateDecode>>stream
+x+TTЩPpòuVpb
+endstream
+endobj
+6 0 obj <</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</Helv 4 0 R>>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0]/Length 22/FormType 1/Filter/FlateDecode>>stream
+x+TTЩPpòuVpb
+endstream
+endobj
+1 0 obj <</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]>>/Subtype/Form/BBox[0 0 20 20]/Matrix [1 0 0 1 0 0]/Length 8/FormType 1/Filter/FlateDecode>>stream
+x
+endstream
+endobj
+9 0 obj <</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</Helv 4 0 R>>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0]/Length 85/FormType 1/Filter/FlateDecode>>stream
+x+TTЩPpòuV(T0B]#*JUWÈ
+9
+®yé9Å!Y`¾kÐÈ@W
+endstream
+endobj
+8 0 obj <</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</Helv 4 0 R>>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0]/Length 121/FormType 1/Filter/FlateDecode>>stream
+xNÁ
+0û·ÃjS»a¯0;vö qd¿<$y!;TöCûî°Â-;&|°Á;_§Äd#¼?\¤%LÉåcVEkr¼@¨(¹º}Q=§õDÍÒ3.¯ñ¯¶(Ñ6èµà°ÑÕ
+endstream
+endobj
+7 0 obj <</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</Helv 4 0 R>>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0]/Length 22/FormType 1/Filter/FlateDecode>>stream
+x+TTЩPpòuVpb
+endstream
+endobj
+3 0 obj <</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</Helv 4 0 R>>>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0]/Length 22/FormType 1/Filter/FlateDecode>>stream
+x+TTЩPpòuVpb
+endstream
+endobj
+2 0 obj <</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]>>/Subtype/Form/BBox[0 0 20 20]/Matrix [1 0 0 1 0 0]/Length 26/FormType 1/Filter/FlateDecode>>stream
+x3P0PÈU02
+
+endstream
+endobj
+26 0 obj<</Type/Pages/Count 1/Kids[27 0 R]>>
+endobj
+28 0 obj<</Fields[10 0 R]/DA(/Helv 0 Tf 0 g )/DR<</Font<</Helv 4 0 R>>>>>>
+endobj
+29 0 obj<</Type/Catalog/AcroForm 28 0 R/Pages 26 0 R>>
+endobj
+30 0 obj<</Producer(iText 2.1.2u2 \(by lowagie.com\))/ModDate(D:20080525164253+02'00')/CreationDate(D:20080525164253+02'00')>>
+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
+<</Root 29 0 R/ID [<ae8c73db19e849787be486111b502ecc><6eb921975310bfe3f357a5cc656b98da>]/Info 30 0 R/Size 31>>
+startxref
+5610
+%%EOF
Added: trunk/examples/itext/view/form.xhtml
===================================================================
--- 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 @@
+<p:form
+ xmlns:p="http://jboss.com/products/seam/pdf"
+ URL="form.pdf">
+ <p:field name="person.name" value="#{fillInForms.name}"/>
+ <p:field name="person.address" value="#{fillInForms.address}"/>
+ <p:field name="person.postal_code" value="#{fillInForms.postalCode}"/>
+ <p:field name="person.email" value="#{fillInForms.email}"/>
+ <p:field name="person.programming" value="#{fillInForms.programming}" readOnly="false"/>
+ <p:field name="person.language" value="#{fillInForms.language}" readOnly="false"/>
+ <p:field name="person.preferred" value="#{fillInForms.preferred}" readOnly="false"/>
+ <p:field name="person.knowledge.English" value="#{fillInForms.knowsEnglish ? 'On' : 'Off'}" readOnly="false"/>
+ <p:field name="person.knowledge.French" value="#{fillInForms.knowsFrench ? 'On' : 'Off'}" readOnly="false"/>
+ <p:field name="person.knowledge.Dutch" value="#{fillInForms.knowsDutch ? 'On' : 'Off'}" readOnly="false"/>
+</p:form>
\ No newline at end of file
Modified: trunk/examples/itext/view/index.xhtml
===================================================================
--- 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 @@
[<s:link view="/barcodeimage.xhtml" value="HTML" />]
</li>
<li><s:link view="/swing.xhtml" value="Swing Component" /></li>
+ <li><s:link view="/fillform.xhtml" value="Fill-in-forms" /></li>
<ui:remove>
Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/FormComponent.java
===================================================================
--- 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 = "acrofields";
+ protected static final String STAMPER_KEY = "acrostamper";
protected Object valueOf(String name, Object defaultValue)
{
Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java 2008-10-24 06:21:57 UTC (rev 9406)
+++ trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java 2008-10-24 06:44:38 UTC (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 = "org.jboss.seam.pdf.UIField";
+ private static Log log = Logging.getLog(FormComponent.class);
private String name;
- private String value;
+ private Object value;
+ private Boolean readOnly = Boolean.TRUE;
@Override
public void encodeBegin(FacesContext facesContext) throws IOException
{
AcroFields fields = (AcroFields) Contexts.getEventContext().get(FIELDS_KEY);
+ String theName = getName();
+ Object theValue = getValue();
+ if (theValue == null) {
+ return;
+ }
+ Boolean readOnly = getReadOnly();
try
{
- fields.setField(getName(), getValue());
+ log.debug("Setting field '#0' to value '#1'", theName, theValue);
+ boolean success = false;
+ if (theValue instanceof String) {
+ success = fields.setField(theName, (String) theValue);
+ } else if (theValue instanceof String[]){
+ success = fields.setField(theName, ((String[])theValue)[0]);
+ } else {
+ String message = 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 = (PdfStamper) Contexts.getEventContext().get(STAMPER_KEY);
+ stamper.partialFormFlattening(theName);
+ }
+ }
}
catch (DocumentException e)
{
- String message = Interpolator.instance().interpolate("Could not set field #0 to #1", getName(), getValue());
+ String message = 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 theValue)
+ {
+ log.warn("Could not set field '#0' to '#1'", theName, theValue);
+ Map fieldMap = fields.getFields();
+ if (!fieldMap.containsKey(theName))
+ {
+ log.warn("Could not find field '#0'. Found fields are", theName);
+ for (Iterator i = fieldMap.keySet().iterator(); i.hasNext();)
+ {
+ log.warn(i.next());
+ }
+ return;
+ }
+ String[] options = fields.getListOptionExport(theName);
+ String[] values = fields.getListOptionDisplay(theName);
+ log.warn("Valid values for #0 are", theName);
+ for (int i = 0; i < options.length; i++)
+ {
+ log.warn("'#0' : '#1'", options[i], values[i]);
+ }
+ }
+
@Override
public String getFamily()
{
@@ -49,14 +106,25 @@
this.name = 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 = value;
}
+ public Boolean getReadOnly()
+ {
+ return (Boolean) valueOf("readOnly", readOnly);
+ }
+
+ public void setReadOnly(Boolean readOnly)
+ {
+ this.readOnly = readOnly;
+ }
+
+
}
Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java
===================================================================
--- 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 = "org.jboss.seam.pdf.UIForm";
+public class UIForm extends FormComponent {
+ public static final String COMPONENT_FAMILY = "org.jboss.seam.pdf.UIForm";
- private Log log = Logging.getLog(getClass());
+ private Log log = 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 = url;
- }
+ public void setURL(String url) {
+ URL = url;
+ }
- @Override
- public void encodeBegin(FacesContext facesContext) throws IOException
- {
- reader = new PdfReader(new URL(getURL()));
- buffer = new ByteArrayOutputStream();
- try
- {
- stamper = new PdfStamper(reader, buffer);
- }
- catch (DocumentException e)
- {
- throw new FacesException("Could not create PDF stamper", e);
- }
- fields = stamper.getAcroFields();
- Contexts.getEventContext().set(FIELDS_KEY, fields);
- }
+ @Override
+ public void encodeBegin(FacesContext facesContext) throws IOException {
+ if (getURL().indexOf("://") < 0) {
+ reader = new PdfReader(getClass().getClassLoader()
+ .getResourceAsStream(getURL()));
+ } else {
+ reader = new PdfReader(new URL(getURL()));
+ }
+ log.debug("Loading template #0", getURL());
+ buffer = new ByteArrayOutputStream();
+ try {
+ stamper = new PdfStamper(reader, buffer);
+ Contexts.getEventContext().set(STAMPER_KEY, stamper);
+ } catch (DocumentException e) {
+ throw new FacesException("Could not create PDF stamper", e);
+ }
+ fields = 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 = Pages.getViewId(facesContext);
- String baseName = baseNameForViewId(viewId);
- DocumentStore store = DocumentStore.instance();
- DocumentType documentType = new DocumentData.DocumentType("pdf", "application/pdf");
- DocumentData documentData = new DocumentData(baseName, documentType, buffer.toByteArray());
- String id = store.newId();
- String url = store.preferredUrlForContent(baseName, documentType.getExtension(), id);
- url = Manager.instance().encodeConversationId(url, viewId);
- store.saveData(id, documentData);
- log.info("Redirecting to #0", url);
- facesContext.getExternalContext().redirect(url);
- }
+ if (getExportKey() == null) {
+ UIComponent parent = getParent();
+ if (parent != null && (parent instanceof ValueHolder)) {
+ log.debug("Storing PDF data in ValueHolder parent");
+ ValueHolder valueHolder = (ValueHolder) parent;
+ valueHolder.setValue(buffer.toByteArray());
+ return;
+ }
+ }
- public static String baseNameForViewId(String viewId)
- {
- int pos = viewId.lastIndexOf("/");
- if (pos != -1)
- {
- viewId = viewId.substring(pos + 1);
- }
+ String viewId = Pages.getViewId(facesContext);
+ String baseName = baseNameForViewId(viewId);
- pos = viewId.lastIndexOf(".");
- if (pos != -1)
- {
- viewId = viewId.substring(0, pos);
- }
+ DocumentStore store = DocumentStore.instance();
+ DocumentType documentType = new DocumentData.DocumentType("pdf",
+ "application/pdf");
+ DocumentData documentData = new DocumentData(baseName, documentType,
+ buffer.toByteArray());
+ documentData.setFilename(getFilename());
- return viewId;
- }
+ if (getExportKey() != 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 = store.newId();
+ String url = store.preferredUrlForContent(baseName, documentType
+ .getExtension(), id);
+ url = 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 = viewId.lastIndexOf("/");
+ if (pos != -1) {
+ viewId = viewId.substring(pos + 1);
+ }
+
+ pos = viewId.lastIndexOf(".");
+ if (pos != -1) {
+ viewId = 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 = filename;
+ }
+
+ public String getExportKey() {
+ return (String) valueOf("exportKey", exportKey);
+ }
+
+ public void setExportKey(String exportKey) {
+ this.exportKey = exportKey;
+ }
+
}
More information about the seam-commits
mailing list