[seam-commits] Seam SVN: r8840 - trunk/src/pdf/org/jboss/seam/pdf/ui.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Aug 28 07:49:18 EDT 2008


Author: jbalunas at redhat.com
Date: 2008-08-28 07:49:18 -0400 (Thu, 28 Aug 2008)
New Revision: 8840

Modified:
   trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java
   trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java
Log:
JBSEAM-3342 thanks for the patch Scott.

Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java	2008-08-28 11:08:42 UTC (rev 8839)
+++ trunk/src/pdf/org/jboss/seam/pdf/ui/UIField.java	2008-08-28 11:49:18 UTC (rev 8840)
@@ -1,61 +1,61 @@
-package org.jboss.seam.pdf.ui;
-
-import java.io.IOException;
-
-import javax.faces.context.FacesContext;
-
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.Interpolator;
-
-import com.lowagie.text.DocumentException;
-import com.lowagie.text.pdf.AcroFields;
-
-public class UIField extends FormComponent
-{
-   public static final String COMPONENT_FAMILY = "org.jboss.seam.pdf.UIField";
-   
-   private String name;
-   private String value;
-   
-   @Override
-   public void encodeBegin(FacesContext facesContext) throws IOException
-   {
-      AcroFields fields = (AcroFields) Contexts.getEventContext().get(FIELDS_KEY);
-      try
-      {
-         fields.setField(getName(), getValue());
-      }
-      catch (DocumentException e)
-      {
-         String message = Interpolator.instance().interpolate("Could not set field #0 to #1", getName(), getValue());
-         throw new IOException(message, e);
-      }
-   }
-
-   @Override
-   public String getFamily()
-   {
-      return COMPONENT_FAMILY;
-   }
-
-   public String getName()
-   {
-      return (String) valueOf("name", name);
-   }
-
-   public void setName(String name)
-   {
-      this.name = name;
-   }
-
-   public String getValue()
-   {
-      return (String) valueOf("value", value);
-   }
-
-   public void setValue(String value)
-   {
-      this.value = value;
-   }
-
-}
+package org.jboss.seam.pdf.ui;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Interpolator;
+
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.pdf.AcroFields;
+
+public class UIField extends FormComponent
+{
+   public static final String COMPONENT_FAMILY = "org.jboss.seam.pdf.UIField";
+   
+   private String name;
+   private String value;
+   
+   @Override
+   public void encodeBegin(FacesContext facesContext) throws IOException
+   {
+      AcroFields fields = (AcroFields) Contexts.getEventContext().get(FIELDS_KEY);
+      try
+      {
+         fields.setField(getName(), getValue());
+      }
+      catch (DocumentException e)
+      {
+         String message = Interpolator.instance().interpolate("Could not set field #0 to #1", getName(), getValue());
+         throw new IOException(message);
+      }
+   }
+
+   @Override
+   public String getFamily()
+   {
+      return COMPONENT_FAMILY;
+   }
+
+   public String getName()
+   {
+      return (String) valueOf("name", name);
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   public String getValue()
+   {
+      return (String) valueOf("value", value);
+   }
+
+   public void setValue(String value)
+   {
+      this.value = value;
+   }
+
+}

Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java	2008-08-28 11:08:42 UTC (rev 8839)
+++ trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java	2008-08-28 11:49:18 UTC (rev 8840)
@@ -1,114 +1,114 @@
-package org.jboss.seam.pdf.ui;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.net.URL;
-
-import javax.faces.context.FacesContext;
-
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.core.Manager;
-import org.jboss.seam.document.DocumentData;
-import org.jboss.seam.document.DocumentStore;
-import org.jboss.seam.document.DocumentData.DocumentType;
-import org.jboss.seam.log.Log;
-import org.jboss.seam.log.Logging;
-import org.jboss.seam.navigation.Pages;
-
-import com.lowagie.text.DocumentException;
-import com.lowagie.text.pdf.AcroFields;
-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";
-   private static final String CONTENT_TYPE = "application/pdf";
-  
-   private Log log = Logging.getLog(getClass());
-   
-   private String URL;
-   
-   PdfReader reader;
-   PdfStamper stamper;
-   AcroFields fields;
-   ByteArrayOutputStream buffer;
-   
-   public String getURL()
-   {
-      return (String) valueOf("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 IOException("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 IOException("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);
-   }
-
-
-   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;
-   }
-
-}
+package org.jboss.seam.pdf.ui;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.URL;
+
+import javax.faces.context.FacesContext;
+
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.document.DocumentData;
+import org.jboss.seam.document.DocumentStore;
+import org.jboss.seam.document.DocumentData.DocumentType;
+import org.jboss.seam.log.Log;
+import org.jboss.seam.log.Logging;
+import org.jboss.seam.navigation.Pages;
+
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.pdf.AcroFields;
+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";
+   private static final String CONTENT_TYPE = "application/pdf";
+  
+   private Log log = Logging.getLog(getClass());
+   
+   private String URL;
+   
+   PdfReader reader;
+   PdfStamper stamper;
+   AcroFields fields;
+   ByteArrayOutputStream buffer;
+   
+   public String getURL()
+   {
+      return (String) valueOf("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 IOException("Could not create PDF stamper");
+      }
+      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 IOException("Could not flush PDF");
+      }
+      
+      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);
+   }
+
+
+   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;
+   }
+
+}




More information about the seam-commits mailing list