[seam-commits] Seam SVN: r9854 - in trunk: examples/itext/src/org/jboss/seam/example/pdf and 7 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri Jan 2 17:13:54 EST 2009


Author: danielc.roth
Date: 2009-01-02 17:13:54 -0500 (Fri, 02 Jan 2009)
New Revision: 9854

Added:
   trunk/src/main/org/jboss/seam/document/ByteArrayDocumentData.java
Modified:
   trunk/examples/excel/src/org/jboss/seam/excel/test/RenderTest.java
   trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java
   trunk/examples/itext/src/org/jboss/seam/example/pdf/test/DocumentTests.java
   trunk/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java
   trunk/examples/openid/
   trunk/src/excel/org/jboss/seam/excel/exporter/ExcelExporter.java
   trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java
   trunk/src/main/org/jboss/seam/document/DocumentData.java
   trunk/src/main/org/jboss/seam/document/DocumentStorePhaseListener.java
   trunk/src/main/org/jboss/seam/document/DocumentStoreServlet.java
   trunk/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java
   trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java
Log:
Prep for JBSEAM-1350

Modified: trunk/examples/excel/src/org/jboss/seam/excel/test/RenderTest.java
===================================================================
--- trunk/examples/excel/src/org/jboss/seam/excel/test/RenderTest.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/examples/excel/src/org/jboss/seam/excel/test/RenderTest.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -8,6 +8,7 @@
 import jxl.Workbook;
 
 import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.document.ByteArrayDocumentData;
 import org.jboss.seam.document.DocumentData;
 import org.jboss.seam.excel.ExcelTest.Person;
 import org.jboss.seam.faces.Renderer;
@@ -38,7 +39,7 @@
                 Renderer.instance().render("/simple.xhtml");
 
                 DocumentData data = (DocumentData) Contexts.getEventContext().get("testExport");
-                Workbook workbook = Workbook.getWorkbook(new ByteArrayInputStream(data.getData()));
+                Workbook workbook = Workbook.getWorkbook(new ByteArrayInputStream(((ByteArrayDocumentData)data).getData()));
                 Sheet sheet = workbook.getSheet("Developers");
                 
                 assert sheet != null;

Modified: trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java
===================================================================
--- trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/examples/itext/src/org/jboss/seam/example/pdf/FillInForms.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -1,5 +1,6 @@
-package org.domain.PDF.session;
+package org.jboss.seam.example.pdf;
 
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -12,132 +13,156 @@
 
 @Name("fillInForms")
 @Scope(ScopeType.CONVERSATION)
-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 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 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");
-	return knows;
-    }
-    
-    public boolean isKnowsFrench() {
-	return knowledge.contains("FR");
-    }
-    
-    public boolean isKnowsDutch() {
-	return knowledge.contains("NL");
-    }
-    
+   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");
+      return knows;
+   }
+
+   public boolean isKnowsFrench()
+   {
+      return knowledge.contains("FR");
+   }
+
+   public boolean isKnowsDutch()
+   {
+      return knowledge.contains("NL");
+   }
+
 }

Modified: trunk/examples/itext/src/org/jboss/seam/example/pdf/test/DocumentTests.java
===================================================================
--- trunk/examples/itext/src/org/jboss/seam/example/pdf/test/DocumentTests.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/examples/itext/src/org/jboss/seam/example/pdf/test/DocumentTests.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -2,77 +2,81 @@
 
 import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.core.Conversation;
-import org.jboss.seam.mock.SeamTest;
+import org.jboss.seam.document.ByteArrayDocumentData;
 import org.jboss.seam.document.DocumentData;
 import org.jboss.seam.document.DocumentStore;
+import org.jboss.seam.mock.SeamTest;
 import org.jboss.seam.pdf.ui.UIDocument;
 import org.testng.annotations.Test;
 
 /**
- *  This is just a placeholder until I can find a way to actually test the 
- *  UI components.  
+ * This is just a placeholder until I can find a way to actually test the UI
+ * components.
  */
-public class DocumentTests 
-    extends SeamTest
-{   
-    @Test
-    public void documentStore() 
-        throws Exception
-    {
-        String conversationId = new FacesRequest("/whyseam.xhtml") {
+public class DocumentTests extends SeamTest
+{
+   @Test
+   public void documentStore() throws Exception
+   {
+      String conversationId = new FacesRequest("/whyseam.xhtml")
+      {
 
-            
-            @Override
-            protected void invokeApplication() throws Exception {
-                Conversation.instance().begin();
-                
-                DocumentStore store = (DocumentStore) getValue("#{org.jboss.seam.document.documentStore}");
-                String docId = store.newId();
-                             
-                Contexts.getSessionContext().set("docId", docId);
-                
-                DocumentData documentData = new DocumentData("base", UIDocument.PDF, new byte[100]);
-                store.saveData(docId, documentData);
-            }
-            
-            @Override
-            protected void renderResponse() throws Exception {
-                String docId = (String) getValue("#{docId}");
-                assert docId != null;
-                
-                DocumentStore store = (DocumentStore) getValue("#{org.jboss.seam.document.documentStore}");
-                assert store.idIsValid(docId);        
-                
- 
-            }
-        }.run();
-        
-        // different conversation
-        new FacesRequest("/whyseam.xhtml") {
-            @Override
-            protected void renderResponse() throws Exception {
-                String docId = (String) getValue("#{docId}");
-                assert docId != null;
-                
-                DocumentStore store = (DocumentStore) getValue("#{org.jboss.seam.document.documentStore}");
-                assert !store.idIsValid(docId);                
-            }
-        }.run();
-        
-        new FacesRequest("/whyseam.xhtml", conversationId) {
-            @Override
-            protected void renderResponse() throws Exception {
-                String docId = (String) getValue("#{docId}");
-                assert docId != null;
-                
-                DocumentStore store = (DocumentStore) getValue("#{org.jboss.seam.document.documentStore}");
-                assert store.idIsValid(docId);       
-                
-                DocumentData data = store.getDocumentData(docId);
-                assert data.getDocumentType().equals(UIDocument.PDF);
-                assert data.getData().length == 100;
-            }
-        }.run();
-    }
+         @Override
+         protected void invokeApplication() throws Exception
+         {
+            Conversation.instance().begin();
 
+            DocumentStore store = (DocumentStore) getValue("#{org.jboss.seam.document.documentStore}");
+            String docId = store.newId();
+
+            Contexts.getSessionContext().set("docId", docId);
+
+            DocumentData documentData = new ByteArrayDocumentData("base", UIDocument.PDF, new byte[100]);
+            store.saveData(docId, documentData);
+         }
+
+         @Override
+         protected void renderResponse() throws Exception
+         {
+            String docId = (String) getValue("#{docId}");
+            assert docId != null;
+
+            DocumentStore store = (DocumentStore) getValue("#{org.jboss.seam.document.documentStore}");
+            assert store.idIsValid(docId);
+
+         }
+      }.run();
+
+      // different conversation
+      new FacesRequest("/whyseam.xhtml")
+      {
+         @Override
+         protected void renderResponse() throws Exception
+         {
+            String docId = (String) getValue("#{docId}");
+            assert docId != null;
+
+            DocumentStore store = (DocumentStore) getValue("#{org.jboss.seam.document.documentStore}");
+            assert !store.idIsValid(docId);
+         }
+      }.run();
+
+      new FacesRequest("/whyseam.xhtml", conversationId)
+      {
+         @Override
+         protected void renderResponse() throws Exception
+         {
+            String docId = (String) getValue("#{docId}");
+            assert docId != null;
+
+            DocumentStore store = (DocumentStore) getValue("#{org.jboss.seam.document.documentStore}");
+            assert store.idIsValid(docId);
+
+            ByteArrayDocumentData data = (ByteArrayDocumentData)store.getDocumentData(docId);
+            assert data.getDocumentType().equals(UIDocument.PDF);
+            assert data.getData().length == 100;
+         }
+      }.run();
+   }
+
 }

Modified: trunk/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java
===================================================================
--- trunk/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -16,6 +16,7 @@
 
 import org.jboss.seam.mail.ui.UIAttachment;
 import org.jboss.seam.mail.ui.UIMessage;
+import org.jboss.seam.document.ByteArrayDocumentData;
 import org.jboss.seam.document.DocumentData;
 import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.example.mail.Person;
@@ -220,7 +221,7 @@
              UIMessage message = new UIMessage();
              attachment.setParent(message);
              message.setMailSession(MailSession.instance());
-             DocumentData doc = new DocumentData("filename", new DocumentData.DocumentType("pdf", "application/pdf"), new byte[] {});
+             DocumentData doc = new ByteArrayDocumentData("filename", new DocumentData.DocumentType("pdf", "application/pdf"), new byte[] {});
              attachment.setValue(doc);
              attachment.encodeEnd(FacesContext.getCurrentInstance());
              


Property changes on: trunk/examples/openid
___________________________________________________________________
Name: svn:ignore
   + dist
exploded-archives
test-build


Modified: trunk/src/excel/org/jboss/seam/excel/exporter/ExcelExporter.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/exporter/ExcelExporter.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/src/excel/org/jboss/seam/excel/exporter/ExcelExporter.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -18,6 +18,7 @@
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
 import org.jboss.seam.core.Interpolator;
 import org.jboss.seam.core.Manager;
+import org.jboss.seam.document.ByteArrayDocumentData;
 import org.jboss.seam.document.DocumentData;
 import org.jboss.seam.document.DocumentStore;
 import org.jboss.seam.excel.ExcelFactory;
@@ -153,7 +154,7 @@
    {
       String viewId = Pages.getViewId(FacesContext.getCurrentInstance());
       String baseName = UIWorkbook.baseNameForViewId(viewId);
-      DocumentData documentData = new DocumentData(baseName, excelWorkbook.getDocumentType(), excelWorkbook.getBytes());
+      DocumentData documentData = new ByteArrayDocumentData(baseName, excelWorkbook.getDocumentType(), excelWorkbook.getBytes());
       String id = DocumentStore.instance().newId();
       String url = DocumentStore.instance().preferredUrlForContent(baseName, excelWorkbook.getDocumentType().getExtension(), id);
       url = Manager.instance().encodeConversationId(url, viewId);

Modified: trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -9,6 +9,7 @@
 
 import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.core.Manager;
+import org.jboss.seam.document.ByteArrayDocumentData;
 import org.jboss.seam.document.DocumentData;
 import org.jboss.seam.document.DocumentStore;
 import org.jboss.seam.document.DocumentData.DocumentType;
@@ -310,7 +311,7 @@
 
       // Create a new workbook
       excelWorkbook.createWorkbook(this);
-      
+
       List<UILink> stylesheets = getChildrenOfType(getChildren(), UILink.class);
       excelWorkbook.setStylesheets(stylesheets);
    }
@@ -327,14 +328,15 @@
       String viewId = Pages.getViewId(context);
       String baseName = baseNameForViewId(viewId);
 
-      DocumentData documentData = new DocumentData(baseName, type, bytes);
+      DocumentData documentData = new ByteArrayDocumentData(baseName, type, bytes);
       documentData.setFilename(getFilename());
 
-      if (getExportKey() != null) {
+      if (getExportKey() != null)
+      {
          Contexts.getEventContext().set(getExportKey(), documentData);
          return;
       }
-      
+
       if (sendRedirect)
       {
          DocumentStore store = DocumentStore.instance();

Added: trunk/src/main/org/jboss/seam/document/ByteArrayDocumentData.java
===================================================================
--- trunk/src/main/org/jboss/seam/document/ByteArrayDocumentData.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/document/ByteArrayDocumentData.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -0,0 +1,27 @@
+package org.jboss.seam.document;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class ByteArrayDocumentData extends DocumentData
+{
+
+   private byte[] data;
+
+   public ByteArrayDocumentData(String baseName, DocumentType documentType, byte[] data)
+   {
+      super(baseName, documentType);
+   }
+
+   @Override
+   public void writeDataToStream(OutputStream stream) throws IOException
+   {
+      stream.write(data);
+   }
+
+   public byte[] getData()
+   {
+      return data;
+   }
+
+}
\ No newline at end of file

Modified: trunk/src/main/org/jboss/seam/document/DocumentData.java
===================================================================
--- trunk/src/main/org/jboss/seam/document/DocumentData.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/src/main/org/jboss/seam/document/DocumentData.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -1,73 +1,83 @@
 package org.jboss.seam.document;
 
+import java.io.IOException;
+import java.io.OutputStream;
 import java.io.Serializable;
 
-public class DocumentData 
-    implements Serializable
+public abstract class DocumentData implements Serializable
 {
-    byte[] data;
-    DocumentType documentType;
-    String baseName;
+   DocumentType documentType;
+   String baseName;
 
-    String disposition = "inline";
-    String fileName;
-    
-    public DocumentData(String baseName, DocumentType documentType, byte[] data) {
-        super();
-        this.data = data;
-        this.documentType = documentType;
-        this.baseName = baseName;
-    }
+   String disposition = "inline";
+   String fileName;
 
-    public byte[] getData() {
-        return data;
-    }
-    public DocumentType getDocumentType() {
-        return documentType;
-    }
-    public String getBaseName() {
-        return baseName;
-    }
+   public DocumentData(String baseName, DocumentType documentType)
+   {
+      super();
+      this.documentType = documentType;
+      this.baseName = baseName;
+   }
 
-    
-    public void setFilename(String fileName) {
-        this.fileName = fileName;
-    }
-    
-    public String getFileName() {
-        if (fileName == null) {
-            return getBaseName() + "." + getDocumentType().getExtension();
-        } else {
-           return fileName;
-        }
-    }
+   public abstract void writeDataToStream(OutputStream stream) throws IOException;
 
-    public void setDisposition(String disposition) {
-        this.disposition = disposition;
-    }
+   public DocumentType getDocumentType()
+   {
+      return documentType;
+   }
 
-    public String getDisposition() {
-        return disposition;
-    }
+   public String getBaseName()
+   {
+      return baseName;
+   }
 
-    static public class DocumentType 
-        implements Serializable
-    {
-        private String mimeType;
-        private String extension;
+   public void setFilename(String fileName)
+   {
+      this.fileName = fileName;
+   }
 
-        public DocumentType(String extension, String mimeType) {
-            this.extension = extension;
-            this.mimeType = mimeType;
-        }
+   public String getFileName()
+   {
+      if (fileName == null)
+      {
+         return getBaseName() + "." + getDocumentType().getExtension();
+      }
+      else
+      {
+         return fileName;
+      }
+   }
 
-        public String getMimeType() {
-            return mimeType;
-        }
+   public void setDisposition(String disposition)
+   {
+      this.disposition = disposition;
+   }
 
-        public String getExtension(){
-            return extension;
-        }
+   public String getDisposition()
+   {
+      return disposition;
+   }
 
-    }    
+   static public class DocumentType implements Serializable
+   {
+      private String mimeType;
+      private String extension;
+
+      public DocumentType(String extension, String mimeType)
+      {
+         this.extension = extension;
+         this.mimeType = mimeType;
+      }
+
+      public String getMimeType()
+      {
+         return mimeType;
+      }
+
+      public String getExtension()
+      {
+         return extension;
+      }
+
+   }
 }
\ No newline at end of file

Modified: trunk/src/main/org/jboss/seam/document/DocumentStorePhaseListener.java
===================================================================
--- trunk/src/main/org/jboss/seam/document/DocumentStorePhaseListener.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/src/main/org/jboss/seam/document/DocumentStorePhaseListener.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -8,62 +8,61 @@
 import javax.faces.event.PhaseListener;
 import javax.servlet.http.HttpServletResponse;
 
-import org.jboss.seam.log.*;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
 import org.jboss.seam.navigation.Pages;
 import org.jboss.seam.web.Parameters;
 
-
-public class DocumentStorePhaseListener 
-    implements PhaseListener 
+public class DocumentStorePhaseListener implements PhaseListener
 {
-    private static final long serialVersionUID = 7308251684939658978L;
+   private static final long serialVersionUID = 7308251684939658978L;
 
-    private static final LogProvider log = Logging.getLogProvider(DocumentStorePhaseListener.class);
+   private static final LogProvider log = Logging.getLogProvider(DocumentStorePhaseListener.class);
 
-    public PhaseId getPhaseId() 
-    {
-        return PhaseId.RENDER_RESPONSE;
-    }
+   public PhaseId getPhaseId()
+   {
+      return PhaseId.RENDER_RESPONSE;
+   }
 
-    public void afterPhase(PhaseEvent phaseEvent) {
-        // ...
-    }
+   public void afterPhase(PhaseEvent phaseEvent)
+   {
+      // ...
+   }
 
-    public void beforePhase(PhaseEvent phaseEvent) 
-    {
-        String rootId = Pages.getViewId( phaseEvent.getFacesContext() );
-        
-        Parameters params = Parameters.instance();
-        String id = (String) params.convertMultiValueRequestParameter(params.getRequestParameters(), "docId", String.class);              
-        if (rootId.contains(DocumentStore.DOCSTORE_BASE_URL)) {
-            sendContent(phaseEvent.getFacesContext(), id);
-        }
-    }
+   public void beforePhase(PhaseEvent phaseEvent)
+   {
+      String rootId = Pages.getViewId(phaseEvent.getFacesContext());
 
-    public void sendContent(FacesContext context, String contentId) 
-    {
-        try 
-        {            
-            DocumentData documentData = DocumentStore.instance().getDocumentData(contentId);
-            
-            if (documentData != null) {
-                byte[] data = documentData.getData();
+      Parameters params = Parameters.instance();
+      String id = (String) params.convertMultiValueRequestParameter(params.getRequestParameters(), "docId", String.class);
+      if (rootId.contains(DocumentStore.DOCSTORE_BASE_URL))
+      {
+         sendContent(phaseEvent.getFacesContext(), id);
+      }
+   }
 
-                HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
-                response.setContentType( documentData.getDocumentType().getMimeType() );
+   public void sendContent(FacesContext context, String contentId)
+   {
+      try
+      {
+         DocumentData documentData = DocumentStore.instance().getDocumentData(contentId);
 
-                response.setHeader("Content-Disposition", 
-                        documentData.getDisposition() + 
-                        "; filename=\"" + documentData.getFileName() + "\"");
+         if (documentData != null)
+         {
 
-                if (data != null) {
-                    response.getOutputStream().write(data);
-                }
-                context.responseComplete();
-            }
-        } catch (IOException e) {
-            log.error(e);
-        }
-    }
+            HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
+            response.setContentType(documentData.getDocumentType().getMimeType());
 
+            response.setHeader("Content-Disposition", documentData.getDisposition() + "; filename=\"" + documentData.getFileName() + "\"");
+
+            documentData.writeDataToStream(response.getOutputStream());
+            context.responseComplete();
+         }
+      }
+      catch (IOException e)
+      {
+         log.error(e);
+      }
+   }
+
 }

Modified: trunk/src/main/org/jboss/seam/document/DocumentStoreServlet.java
===================================================================
--- trunk/src/main/org/jboss/seam/document/DocumentStoreServlet.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/src/main/org/jboss/seam/document/DocumentStoreServlet.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -10,58 +10,54 @@
 import org.jboss.seam.servlet.ContextualHttpServletRequest;
 import org.jboss.seam.web.Parameters;
 
-public class DocumentStoreServlet 
-    extends HttpServlet 
+public class DocumentStoreServlet extends HttpServlet
 {
-    private static final long serialVersionUID = 5196002741557182072L;
+   private static final long serialVersionUID = 5196002741557182072L;
 
-    @Override
-    protected void doGet(final HttpServletRequest request, final HttpServletResponse response) 
-        throws ServletException, IOException 
-    {
-        new ContextualHttpServletRequest(request)
-        {
-            @Override
-            public void process() 
-                throws ServletException, IOException
-            {
-               doWork(request, response);
-            }
-        }.run();    
-    }    
-    
-    
-    private static void doWork(HttpServletRequest request, HttpServletResponse response) 
-        throws IOException 
-    {
-        Parameters params = Parameters.instance();
-        String contentId = (String) params.convertMultiValueRequestParameter(params.getRequestParameters(), "docId", String.class);        
-                
-        DocumentStore store = DocumentStore.instance();
-        
-        if (store.idIsValid(contentId)) {
-            DocumentData documentData = store.getDocumentData(contentId);
-            
-            byte[] data = documentData.getData();       
+   @Override
+   protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException
+   {
+      new ContextualHttpServletRequest(request)
+      {
+         @Override
+         public void process() throws ServletException, IOException
+         {
+            doWork(request, response);
+         }
+      }.run();
+   }
 
-            response.setContentType(documentData.getDocumentType().getMimeType());            
-            response.setHeader("Content-Disposition", 
-                               documentData.getDisposition() + 
-                               "; filename=\"" + documentData.getFileName() + "\"");
+   private static void doWork(HttpServletRequest request, HttpServletResponse response) throws IOException
+   {
+      Parameters params = Parameters.instance();
+      String contentId = (String) params.convertMultiValueRequestParameter(params.getRequestParameters(), "docId", String.class);
 
-            if (data != null) {
-                response.getOutputStream().write(data);
+      DocumentStore store = DocumentStore.instance();
+
+      if (store.idIsValid(contentId))
+      {
+         DocumentData documentData = store.getDocumentData(contentId);
+
+         response.setContentType(documentData.getDocumentType().getMimeType());
+         response.setHeader("Content-Disposition", documentData.getDisposition() + "; filename=\"" + documentData.getFileName() + "\"");
+
+         documentData.writeDataToStream(response.getOutputStream());
+      }
+      else
+      {
+         String error = store.getErrorPage();
+         if (error != null)
+         {
+            if (error.startsWith("/"))
+            {
+               error = request.getContextPath() + error;
             }
-        } else{
-             String error = store.getErrorPage();             
-             if (error != null) {      
-                 if (error.startsWith("/")) {
-                     error = request.getContextPath() + error;
-                 }
-                 response.sendRedirect(error);
-             } else {
-                 response.sendError(404);
-             }
-        }
-    }
+            response.sendRedirect(error);
+         }
+         else
+         {
+            response.sendError(404);
+         }
+      }
+   }
 }

Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -9,10 +9,11 @@
 import javax.faces.context.FacesContext;
 
 import org.jboss.seam.core.Manager;
-import org.jboss.seam.navigation.Pages;
+import org.jboss.seam.document.ByteArrayDocumentData;
 import org.jboss.seam.document.DocumentData;
 import org.jboss.seam.document.DocumentStore;
 import org.jboss.seam.document.DocumentData.DocumentType;
+import org.jboss.seam.navigation.Pages;
 import org.jboss.seam.pdf.ITextUtils;
 
 import com.lowagie.text.DocWriter;
@@ -275,17 +276,21 @@
 
    protected void processHeaders()
    {
-       UIComponent facet = getFacet("header");
+      UIComponent facet = getFacet("header");
 
-       if (facet == null) {
-           return;
-       }
+      if (facet == null)
+      {
+         return;
+      }
 
-       try {
-           encode(FacesContext.getCurrentInstance(), facet);
-       } catch (Exception e) {
-           throw new RuntimeException(e);
-       }
+      try
+      {
+         encode(FacesContext.getCurrentInstance(), facet);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
    }
 
    protected String baseNameForViewId(String viewId)
@@ -320,7 +325,7 @@
       String viewId = Pages.getViewId(context);
       String baseName = baseNameForViewId(viewId);
 
-      DocumentData documentData = new DocumentData(baseName, documentType, bytes);
+      DocumentData documentData = new ByteArrayDocumentData(baseName, documentType, bytes);
       String dispositionValue = (String) valueBinding(context, "disposition", disposition);
       if (dispositionValue != null)
       {

Modified: trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java	2009-01-01 16:51:57 UTC (rev 9853)
+++ trunk/src/pdf/org/jboss/seam/pdf/ui/UIForm.java	2009-01-02 22:13:54 UTC (rev 9854)
@@ -11,137 +11,160 @@
 
 import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.core.Manager;
+import org.jboss.seam.core.ResourceLoader;
+import org.jboss.seam.document.ByteArrayDocumentData;
 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 org.jboss.seam.core.ResourceLoader;
 
 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";
+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 filename;
-    private String exportKey;
+   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 {
-        log.info("Loading template #0", getURL());
-        if (getURL().indexOf("://") < 0) {
-            reader = new PdfReader(ResourceLoader.instance().getResourceAsStream(getURL()));
-        } else {
-            reader = new PdfReader(new URL(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 encodeBegin(FacesContext facesContext) throws IOException
+   {
+      log.info("Loading template #0", getURL());
+      if (getURL().indexOf("://") < 0)
+      {
+         reader = new PdfReader(ResourceLoader.instance().getResourceAsStream(getURL()));
+      }
+      else
+      {
+         reader = new PdfReader(new URL(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);
+      }
 
-        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;
-            }
-        }
+      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;
+         }
+      }
 
-        String viewId = Pages.getViewId(facesContext);
-        String baseName = baseNameForViewId(viewId);
+      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());
-        documentData.setFilename(getFilename());
+      DocumentStore store = DocumentStore.instance();
+      DocumentType documentType = new DocumentData.DocumentType("pdf", "application/pdf");
+      DocumentData documentData = new ByteArrayDocumentData(baseName, documentType, buffer.toByteArray());
+      documentData.setFilename(getFilename());
 
-        if (getExportKey() != null) {
-            log.debug("Exporting PDF data to event key #0", getExportKey());
-            Contexts.getEventContext().set(getExportKey(), documentData);
-            return;
-        }
+      if (getExportKey() != null)
+      {
+         log.debug("Exporting PDF data to event key #0", getExportKey());
+         Contexts.getEventContext().set(getExportKey(), documentData);
+         return;
+      }
 
-        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);
-    }
+      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);
-        }
+   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);
-        }
+      pos = viewId.lastIndexOf(".");
+      if (pos != -1)
+      {
+         viewId = viewId.substring(0, pos);
+      }
 
-        return viewId;
-    }
+      return viewId;
+   }
 
-    @Override
-    public String getFamily() {
-        return COMPONENT_FAMILY;
-    }
+   @Override
+   public String getFamily()
+   {
+      return COMPONENT_FAMILY;
+   }
 
-    public String getFilename() {
-        return (String) valueOf("filename", filename);
-    }
+   public String getFilename()
+   {
+      return (String) valueOf("filename", filename);
+   }
 
-    public void setFilename(String filename) {
-        this.filename = filename;
-    }
+   public void setFilename(String filename)
+   {
+      this.filename = filename;
+   }
 
-    public String getExportKey() {
-        return (String) valueOf("exportKey", exportKey);
-    }
+   public String getExportKey()
+   {
+      return (String) valueOf("exportKey", exportKey);
+   }
 
-    public void setExportKey(String exportKey) {
-        this.exportKey = exportKey;
-    }
+   public void setExportKey(String exportKey)
+   {
+      this.exportKey = exportKey;
+   }
 
 }




More information about the seam-commits mailing list