Seam SVN: r9416 - branches/enterprise/JBPAPP_4_3_FP01/examples/booking/src/org/jboss/seam/example/booking.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-24 07:03:10 -0400 (Fri, 24 Oct 2008)
New Revision: 9416
Modified:
branches/enterprise/JBPAPP_4_3_FP01/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java
Log:
JBPAPP-1320
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java 2008-10-24 10:55:18 UTC (rev 9415)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java 2008-10-24 11:03:10 UTC (rev 9416)
@@ -2,6 +2,7 @@
package org.jboss.seam.example.booking;
import java.util.List;
+import java.util.ArrayList;
import javax.ejb.Remove;
import javax.ejb.Stateful;
@@ -54,7 +55,7 @@
nextPageAvailable = results.size() > pageSize;
if (nextPageAvailable) {
- hotels = results.subList(0,pageSize);
+ hotels = new ArrayList<Hotel>(results.subList(0,pageSize));
} else {
hotels = results;
}
16 years, 1 month
Seam SVN: r9415 - branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-24 06:55:18 -0400 (Fri, 24 Oct 2008)
New Revision: 9415
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework/Query.java
Log:
JBPAPP-1301
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework/Query.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework/Query.java 2008-10-24 10:49:57 UTC (rev 9414)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework/Query.java 2008-10-24 10:55:18 UTC (rev 9415)
@@ -1,6 +1,7 @@
package org.jboss.seam.framework;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -251,7 +252,8 @@
protected boolean isRestrictionParameterSet(Object parameterValue)
{
- return parameterValue!=null && !"".equals(parameterValue);
+ return parameterValue != null && !"".equals(parameterValue) && parameterValue instanceof Collection ? !((Collection) parameterValue).isEmpty() : true;
+
}
/**
16 years, 1 month
Seam SVN: r9414 - in branches/enterprise/JBPAPP_4_3_FP01: examples/ui/view and 3 other directories.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-24 06:49:57 -0400 (Fri, 24 Oct 2008)
New Revision: 9414
Added:
branches/enterprise/JBPAPP_4_3_FP01/examples/ui/src/org/jboss/seam/example/ui/SpanTitle.java
branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/component/UISpan.java
Modified:
branches/enterprise/JBPAPP_4_3_FP01/examples/ui/view/template.xhtml
branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/config/component/span.xml
branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/SpanRendererBase.java
Log:
JBPAPP-1322
Added: branches/enterprise/JBPAPP_4_3_FP01/examples/ui/src/org/jboss/seam/example/ui/SpanTitle.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/ui/src/org/jboss/seam/example/ui/SpanTitle.java (rev 0)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/ui/src/org/jboss/seam/example/ui/SpanTitle.java 2008-10-24 10:49:57 UTC (rev 9414)
@@ -0,0 +1,13 @@
+package org.jboss.seam.example.ui;
+
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Unwrap;
+@Name("spanTitle")
+public class SpanTitle
+{
+ @Unwrap
+ public String unwrap()
+ {
+ return "A Span title";
+ }
+}
\ No newline at end of file
Property changes on: branches/enterprise/JBPAPP_4_3_FP01/examples/ui/src/org/jboss/seam/example/ui/SpanTitle.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/ui/view/template.xhtml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/ui/view/template.xhtml 2008-10-24 08:41:08 UTC (rev 9413)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/ui/view/template.xhtml 2008-10-24 10:49:57 UTC (rev 9414)
@@ -97,12 +97,18 @@
<code>s:graphicImage</code>
<f:param name="personId" value="1" />
</s:link></li>
+
+ <li><s:span title="#{spanTitle}" style="font-weight:bold">
+ <code>s:span</code>
+ </s:span>
+ </li>
</ul>
</s:div>
<s:div styleClass="content">
<h1><code><h:outputText value="#{tagName}" /></code></h1>
<ui:insert name="body" />
<h:messages />
+
</s:div>
</body>
Modified: branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/config/component/span.xml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/config/component/span.xml 2008-10-24 08:41:08 UTC (rev 9413)
+++ branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/config/component/span.xml 2008-10-24 10:49:57 UTC (rev 9414)
@@ -5,7 +5,7 @@
<name>org.jboss.seam.ui.Span</name>
<family>org.jboss.seam.ui.Span</family>
<classname>org.jboss.seam.ui.component.html.HtmlSpan</classname>
- <superclass>org.jboss.seam.ui.component.UIStyle</superclass>
+ <superclass>org.jboss.seam.ui.component.UISpan</superclass>
<description>
<![CDATA[Render a HTML <span>]]>
</description>
@@ -23,5 +23,10 @@
</tag>
&ui_component_attributes;
&html_style_attributes;
+ <property>
+ <name>title</name>
+ <classname>java.lang.String</classname>
+ <description>Span title attribute</description>
+ </property>
</component>
</components>
Added: branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/component/UISpan.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/component/UISpan.java (rev 0)
+++ branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/component/UISpan.java 2008-10-24 10:49:57 UTC (rev 9414)
@@ -0,0 +1,7 @@
+package org.jboss.seam.ui.component;
+
+public abstract class UISpan extends UIStyle
+{
+ public abstract String getTitle();
+ public abstract void setTitle(String title);
+}
Property changes on: branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/component/UISpan.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/SpanRendererBase.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/SpanRendererBase.java 2008-10-24 08:41:08 UTC (rev 9413)
+++ branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/SpanRendererBase.java 2008-10-24 10:49:57 UTC (rev 9414)
@@ -2,8 +2,11 @@
import java.io.IOException;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.jboss.seam.ui.component.UISpan;
import org.jboss.seam.ui.component.UIStyle;
public class SpanRendererBase extends StyleRendererBase
@@ -12,7 +15,7 @@
@Override
protected Class getComponentClass()
{
- return UIStyle.class;
+ return UISpan.class;
}
@Override
@@ -22,6 +25,28 @@
}
@Override
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException
+ {
+ UISpan span = (UISpan) component;
+
+ startElement(writer, span);
+ writer.writeAttribute("id", component.getClientId(context), "id");
+
+ if (span.getStyleClass() != null)
+ {
+ writer.writeAttribute("class", span.getStyleClass(), "styleClass");
+ }
+ if (span.getStyle() != null)
+ {
+ writer.writeAttribute("style", span.getStyle(), "style");
+ }
+ if (span.getTitle() != null)
+ {
+ writer.writeAttribute("title", span.getTitle(), "title");
+ }
+ }
+
+ @Override
public void startElement(ResponseWriter writer, UIStyle style) throws IOException
{
writer.startElement("span", style);
16 years, 1 month
Seam SVN: r9413 - branches/enterprise/JBPAPP_4_3_FP01/src/mail/org/jboss/seam/mail/ui.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-24 04:41:08 -0400 (Fri, 24 Oct 2008)
New Revision: 9413
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/mail/org/jboss/seam/mail/ui/UIMessage.java
Log:
JBPAPP-1323
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/mail/org/jboss/seam/mail/ui/UIMessage.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/mail/org/jboss/seam/mail/ui/UIMessage.java 2008-10-24 08:39:00 UTC (rev 9412)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/mail/org/jboss/seam/mail/ui/UIMessage.java 2008-10-24 08:41:08 UTC (rev 9413)
@@ -84,8 +84,8 @@
@Override
public void encodeBegin(FacesContext context) throws IOException
{
- MailFacesContextImpl.start(getUrlBase()
- + context.getExternalContext().getRequestContextPath() == null ? "" : context.getExternalContext().getRequestContextPath());
+ MailFacesContextImpl.start(getUrlBase() == null ? context.getExternalContext().getRequestContextPath() :
+ (getUrlBase() + context.getExternalContext().getRequestContextPath()));
mimeMessage = null;
try
{
16 years, 1 month
Seam SVN: r9412 - branches/enterprise/JBPAPP_4_3_FP01/examples/ui/view.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-24 04:39:00 -0400 (Fri, 24 Oct 2008)
New Revision: 9412
Modified:
branches/enterprise/JBPAPP_4_3_FP01/examples/ui/view/graphicImage.xhtml
Log:
JBPAPP-1325
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/ui/view/graphicImage.xhtml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/ui/view/graphicImage.xhtml 2008-10-24 08:20:22 UTC (rev 9411)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/ui/view/graphicImage.xhtml 2008-10-24 08:39:00 UTC (rev 9412)
@@ -11,7 +11,7 @@
<p>Outputs an image</p>
<h:panelGrid>
<s:fragment>
- <s:graphicImage value="#{person.picture.data}" rendered="#{person.picture.contentType ne null}" >
+ <s:graphicImage value="#{person.picture.data}">
<s:transformImageSize factor="0.5" />
</s:graphicImage>
<h:outputText value="No image found (upload one)" rendered="#{person.picture.contentType eq null}" />
16 years, 1 month
Seam SVN: r9411 - branches/enterprise/JBPAPP_4_3_FP01/examples/remoting/chatroom/view.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-24 04:20:22 -0400 (Fri, 24 Oct 2008)
New Revision: 9411
Modified:
branches/enterprise/JBPAPP_4_3_FP01/examples/remoting/chatroom/view/chatroom.js
Log:
JBSEAM-2953
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/remoting/chatroom/view/chatroom.js
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/remoting/chatroom/view/chatroom.js 2008-10-24 08:08:36 UTC (rev 9410)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/remoting/chatroom/view/chatroom.js 2008-10-24 08:20:22 UTC (rev 9411)
@@ -11,6 +11,7 @@
}
var username = null;
+var connectedFlag = false;
var chatroom = Seam.Component.getInstance("chatroomAction");
function connect() {
@@ -18,6 +19,7 @@
username = nameCtl.value;
var connectCallback = function(connected, context) {
+ connectedFlag = true;
setInterfaceState(connected);
getObject("username").value = username;
Seam.Remoting.getContext().setConversationId(context.getConversationId());
@@ -36,6 +38,7 @@
}
function disconnect() {
+ connectedFlag = false;
Seam.Remoting.unsubscribe("chatroomTopic");
setInterfaceState(false);
chatroom.disconnect();
@@ -95,6 +98,10 @@
}
function sendMessage() {
+ if (!connectedFlag) {
+ alert("Not connected");
+ return;
+ }
var ctl = getObject("messageText");
chatroom.sendMessage(ctl.value);
ctl.value = "";
16 years, 1 month
Seam SVN: r9410 - branches/enterprise/JBPAPP_4_3_FP01/src/debug/META-INF.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-24 04:08:36 -0400 (Fri, 24 Oct 2008)
New Revision: 9410
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/debug/META-INF/debug.xhtml
Log:
JBPAPP-1315
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/debug/META-INF/debug.xhtml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/debug/META-INF/debug.xhtml 2008-10-24 07:57:09 UTC (rev 9409)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/debug/META-INF/debug.xhtml 2008-10-24 08:08:36 UTC (rev 9410)
@@ -223,7 +223,7 @@
Exception during request processing:
<ui:repeat value="#{org.jboss.seam.debug.contexts.exceptionCauses}" var="exception">
<div>
- Caused by #{exception.class.name} with message: "#{exception.message}"
+ Caused by #{exception.class.name} with message: "#{exception.getMessage()}"
<pre><ui:repeat value="#{exception.stackTrace}" var="stackElement">
#{stackElement}</ui:repeat></pre>
</div>
16 years, 1 month
Seam SVN: r9409 - trunk/examples/seamspace/resources/WEB-INF.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2008-10-24 03:57:09 -0400 (Fri, 24 Oct 2008)
New Revision: 9409
Modified:
trunk/examples/seamspace/resources/WEB-INF/components.xml
Log:
minor
Modified: trunk/examples/seamspace/resources/WEB-INF/components.xml
===================================================================
--- trunk/examples/seamspace/resources/WEB-INF/components.xml 2008-10-24 07:56:29 UTC (rev 9408)
+++ trunk/examples/seamspace/resources/WEB-INF/components.xml 2008-10-24 07:57:09 UTC (rev 9409)
@@ -36,9 +36,9 @@
user-DN-prefix="uid="
user-DN-suffix=",ou=Person,dc=bryzak,dc=com"
role-DN-prefix="cn="
- role-DN-suffix=",ou=Role,dc=bryzak,dc=com"
+ role-DN-suffix=",ou=Roles,dc=bryzak,dc=com"
user-context-DN="ou=Person,dc=bryzak,dc=com"
- role-context-DN="ou=Role,dc=bryzak,dc=com"
+ role-context-DN="ou=Roles,dc=bryzak,dc=com"
user-role-attribute="roles"
role-name-attribute="cn"
user-object-classes="person,uidObject"
16 years, 1 month
Seam SVN: r9408 - trunk/src/main/org/jboss/seam/security/management.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2008-10-24 03:56:29 -0400 (Fri, 24 Oct 2008)
New Revision: 9408
Modified:
trunk/src/main/org/jboss/seam/security/management/LdapIdentityStore.java
Log:
JBSEAM-3552
Modified: trunk/src/main/org/jboss/seam/security/management/LdapIdentityStore.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/management/LdapIdentityStore.java 2008-10-24 06:44:38 UTC (rev 9407)
+++ trunk/src/main/org/jboss/seam/security/management/LdapIdentityStore.java 2008-10-24 07:56:29 UTC (rev 9408)
@@ -597,8 +597,53 @@
{
ctx = initialiseContext();
+ // Delete the role entry itself
String roleDN = String.format("%s=%s,%s", getRoleNameAttribute(), role, getRoleContextDN() );
ctx.destroySubcontext(roleDN);
+
+ // Then delete all user attributes that point to this role
+ int searchScope = SearchControls.SUBTREE_SCOPE;
+ int searchTimeLimit = 10000;
+
+ String[] roleAttr = { getUserRoleAttribute() };
+
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope(searchScope);
+ controls.setReturningAttributes(roleAttr);
+ controls.setTimeLimit(searchTimeLimit);
+
+ StringBuilder roleFilter = new StringBuilder();
+ Object[] filterArgs = new Object[getUserObjectClasses().length + 1];
+ filterArgs[0] = roleDN;
+
+ roleFilter.append("(&(");
+ roleFilter.append(getUserRoleAttribute());
+ roleFilter.append("={0})");
+
+ for (int i = 0; i < getUserObjectClasses().length; i++)
+ {
+ roleFilter.append("(");
+ roleFilter.append(getObjectClassAttribute());
+ roleFilter.append("={");
+ roleFilter.append(i + 1);
+ roleFilter.append("})");
+ filterArgs[i + 1] = getUserObjectClasses()[i];
+ }
+
+ roleFilter.append(")");
+
+ NamingEnumeration answer = ctx.search(getUserContextDN(), roleFilter.toString(), filterArgs, controls);
+ while (answer.hasMore())
+ {
+ SearchResult sr = (SearchResult) answer.next();
+ Attributes attrs = sr.getAttributes();
+ Attribute user = attrs.get( getUserRoleAttribute() );
+ user.remove(roleDN);
+ ctx.modifyAttributes(sr.getNameInNamespace(), new ModificationItem[] {
+ new ModificationItem(DirContext.REPLACE_ATTRIBUTE, user)});
+ }
+ answer.close();
+
return true;
}
catch (NamingException ex)
16 years, 1 month
Seam SVN: r9407 - in trunk: examples/itext/src/org/jboss/seam/example/pdf and 2 other directories.
by seam-commits@lists.jboss.org
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;
+
+@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<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���]o�0���+��v1�Z�.��}$�q�K"ـƢ�ﯶ�h�]!�<<=}9ݠ���PT�e�mZ��؛�'�H�$��Ȁ�<�@)h������Q�rSԩ���T"bj�Z��d�Z
+Q�f<R5D���Ӻ��V㔧H�`
+��Ӕ��#Ɖ }ɏ6ɢ��A�������B3��F[�6�Q��͢
+w��^�
+�oӶA�3��T۵U}�n�S��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
+x�N�
+�0����jS�a��0;v��q�d���<$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
+x�3P0P�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;
+ }
+
}
16 years, 1 month