[seam-commits] Seam SVN: r8589 - in trunk/src: excel/org/jboss/seam/excel and 10 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Aug 5 15:05:20 EDT 2008


Author: norman.richards at jboss.com
Date: 2008-08-05 15:05:20 -0400 (Tue, 05 Aug 2008)
New Revision: 8589

Added:
   trunk/src/main/org/jboss/seam/document/
   trunk/src/main/org/jboss/seam/document/DocumentData.java
   trunk/src/main/org/jboss/seam/document/DocumentStore.java
   trunk/src/main/org/jboss/seam/document/DocumentStorePhaseListener.java
   trunk/src/main/org/jboss/seam/document/DocumentStoreServlet.java
Removed:
   trunk/src/excel/org/jboss/seam/excel/DocumentData.java
   trunk/src/excel/org/jboss/seam/excel/DocumentStore.java
   trunk/src/excel/org/jboss/seam/excel/DocumentStorePhaseListener.java
   trunk/src/excel/org/jboss/seam/excel/DocumentStoreServlet.java
   trunk/src/pdf/org/jboss/seam/pdf/DocumentData.java
   trunk/src/pdf/org/jboss/seam/pdf/DocumentStore.java
   trunk/src/pdf/org/jboss/seam/pdf/DocumentStorePhaseListener.java
   trunk/src/pdf/org/jboss/seam/pdf/DocumentStoreServlet.java
Modified:
   trunk/src/excel/META-INF/faces-config.xml
   trunk/src/excel/org/jboss/seam/excel/ExcelWorkbook.java
   trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java
   trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java
   trunk/src/excel/org/jboss/seam/excel/jxl/exporter/ExcelExporter.java
   trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java
   trunk/src/main/META-INF/faces-config.xml
   trunk/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java
   trunk/src/test/excel/unit/org/jboss/seam/test/excel/unit/JXLExcelWorkbookTest.java
Log:
JBSEAM-3220

Modified: trunk/src/excel/META-INF/faces-config.xml
===================================================================
--- trunk/src/excel/META-INF/faces-config.xml	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/META-INF/faces-config.xml	2008-08-05 19:05:20 UTC (rev 8589)
@@ -116,9 +116,4 @@
 		<component-type>org.jboss.seam.excel.ui.UIExcelExport</component-type>
 		<component-class>org.jboss.seam.excel.ui.UIExcelExport</component-class>
 	</component>
-
-    <lifecycle>
-        <phase-listener>org.jboss.seam.excel.DocumentStorePhaseListener</phase-listener>
-    </lifecycle>
-
 </faces-config>

Deleted: trunk/src/excel/org/jboss/seam/excel/DocumentData.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/DocumentData.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/org/jboss/seam/excel/DocumentData.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -1,76 +0,0 @@
-package org.jboss.seam.excel;
-
-import java.io.Serializable;
-
-public class DocumentData implements Serializable
-{
-   private static final long serialVersionUID = -7473346073592279335L;
-   byte[] data;
-   DocumentType documentType;
-   String baseName;
-
-   String disposition = "inline";
-
-   public DocumentData(String baseName, DocumentType documentType, byte[] data)
-   {
-      super();
-      this.data = data;
-      this.documentType = documentType;
-      this.baseName = baseName;
-   }
-
-   public byte[] getData()
-   {
-      return data;
-   }
-
-   public DocumentType getDocumentType()
-   {
-      return documentType;
-   }
-
-   public String getBaseName()
-   {
-      return baseName;
-   }
-
-   public String getFileName()
-   {
-      return getBaseName() + "." + getDocumentType().getExtension();
-   }
-
-   public void setDisposition(String disposition)
-   {
-      this.disposition = disposition;
-   }
-
-   public String getDisposition()
-   {
-      return disposition;
-   }
-
-   static public class DocumentType implements Serializable
-   {
-      private static final long serialVersionUID = 1L;
-
-      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

Deleted: trunk/src/excel/org/jboss/seam/excel/DocumentStore.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/DocumentStore.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/org/jboss/seam/excel/DocumentStore.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -1,92 +0,0 @@
-package org.jboss.seam.excel;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.faces.application.ViewHandler;
-import javax.faces.context.FacesContext;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.ui.util.Faces;
-
- at Name("org.jboss.seam.excel.documentStore")
- at Scope(ScopeType.CONVERSATION)
- at Install(precedence = Install.BUILT_IN)
-public class DocumentStore implements Serializable
-{
-   private static final long serialVersionUID = -357154201942127711L;
-
-   public final static String EXCEL_DOC = "/seam-excel";
-
-   Map<String, DocumentData> dataStore = new HashMap<String, DocumentData>();
-
-   long nextId = 1;
-   boolean useExtensions = false;
-   String errorPage = null;
-
-   public void setUseExtensions(boolean useExtensions)
-   {
-      this.useExtensions = useExtensions;
-   }
-
-   public void setErrorPage(String errorPage)
-   {
-      this.errorPage = errorPage;
-   }
-
-   public String getErrorPage()
-   {
-      return errorPage;
-   }
-
-   public String newId()
-   {
-      return String.valueOf(nextId++);
-   }
-
-   public void saveData(String id, DocumentData documentData)
-   {
-      dataStore.put(id, documentData);
-   }
-
-   public boolean idIsValid(String id)
-   {
-      return dataStore.get(id) != null;
-   }
-
-   public DocumentData getDocumentData(String id)
-   {
-      return dataStore.get(id);
-   }
-
-   public static DocumentStore instance()
-   {
-      return (DocumentStore) Component.getInstance(DocumentStore.class);
-   }
-
-   public String preferredUrlForContent(String baseName, String extension, String contentId)
-   {
-      return baseUrlForContent(baseName, extension) + "?docId=" + contentId;
-   }
-
-   protected String baseUrlForContent(String baseName, String extension)
-   {
-      if (useExtensions)
-      {
-         return baseName + "." + extension;
-      }
-      else
-      {
-         FacesContext context = FacesContext.getCurrentInstance();
-         ViewHandler handler = context.getApplication().getViewHandler();
-         String url = handler.getActionURL(context, EXCEL_DOC + Faces.getDefaultSuffix(context));
-         return context.getExternalContext().encodeActionURL(url);
-      }
-   }
-
-}

Deleted: trunk/src/excel/org/jboss/seam/excel/DocumentStorePhaseListener.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/DocumentStorePhaseListener.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/org/jboss/seam/excel/DocumentStorePhaseListener.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -1,65 +0,0 @@
-package org.jboss.seam.excel;
-
-import java.io.IOException;
-
-import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.seam.navigation.Pages;
-import org.jboss.seam.web.Parameters;
-
-public class DocumentStorePhaseListener implements PhaseListener
-{
-   private static final long serialVersionUID = 7308251684939658978L;
-
-   public PhaseId getPhaseId()
-   {
-      return PhaseId.RENDER_RESPONSE;
-   }
-
-   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.EXCEL_DOC))
-      {
-         sendContent(phaseEvent.getFacesContext(), id);
-      }
-   }
-
-   public void sendContent(FacesContext context, String contentId)
-   {
-      try
-      {
-         DocumentData documentData = DocumentStore.instance().getDocumentData(contentId);
-
-         byte[] data = documentData.getData();
-
-         HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
-         response.setContentType(documentData.getDocumentType().getMimeType());
-
-         response.setHeader("Content-Disposition", documentData.getDisposition() + "; filename=\"" + documentData.getFileName() + "\"");
-
-         if (data != null)
-         {
-            response.getOutputStream().write(data);
-         }
-         context.responseComplete();
-      }
-      catch (IOException e)
-      {
-         e.printStackTrace();
-      }
-   }
-
-}

Deleted: trunk/src/excel/org/jboss/seam/excel/DocumentStoreServlet.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/DocumentStoreServlet.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/org/jboss/seam/excel/DocumentStoreServlet.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -1,68 +0,0 @@
-package org.jboss.seam.excel;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.seam.servlet.ContextualHttpServletRequest;
-import org.jboss.seam.web.Parameters;
-
-public class DocumentStoreServlet extends HttpServlet
-{
-   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();
-
-         response.setContentType(documentData.getDocumentType().getMimeType());
-         response.setHeader("Content-Disposition", documentData.getDisposition() + "; filename=\"" + documentData.getFileName() + "\"");
-
-         if (data != null)
-         {
-            response.getOutputStream().write(data);
-         }
-      }
-      else
-      {
-         String error = store.getErrorPage();
-         if (error != null)
-         {
-            if (error.startsWith("/"))
-            {
-               error = request.getContextPath() + error;
-            }
-            response.sendRedirect(error);
-         }
-         else
-         {
-            response.sendError(404);
-         }
-      }
-   }
-}

Modified: trunk/src/excel/org/jboss/seam/excel/ExcelWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ExcelWorkbook.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/org/jboss/seam/excel/ExcelWorkbook.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -1,6 +1,6 @@
 package org.jboss.seam.excel;
 
-import org.jboss.seam.excel.DocumentData.DocumentType;
+import org.jboss.seam.document.DocumentData.DocumentType;
 import org.jboss.seam.excel.ui.UIColumn;
 import org.jboss.seam.excel.ui.UIWorkbook;
 import org.jboss.seam.excel.ui.UIWorksheet;

Modified: trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -10,12 +10,12 @@
 import org.jboss.seam.annotations.Scope;
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
 import org.jboss.seam.excel.Command;
-import org.jboss.seam.excel.DocumentData;
+import org.jboss.seam.document.DocumentData;
 import org.jboss.seam.excel.ExcelWorkbook;
 import org.jboss.seam.excel.ExcelWorkbookException;
 import org.jboss.seam.excel.Template;
 import org.jboss.seam.excel.WorksheetItem;
-import org.jboss.seam.excel.DocumentData.DocumentType;
+import org.jboss.seam.document.DocumentData.DocumentType;
 import org.jboss.seam.excel.ui.UICell;
 import org.jboss.seam.excel.ui.UIColumn;
 import org.jboss.seam.excel.ui.UIImage;

Modified: trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -26,12 +26,12 @@
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
 import org.jboss.seam.core.Interpolator;
 import org.jboss.seam.excel.Command;
-import org.jboss.seam.excel.DocumentData;
+import org.jboss.seam.document.DocumentData;
 import org.jboss.seam.excel.ExcelWorkbook;
 import org.jboss.seam.excel.ExcelWorkbookException;
 import org.jboss.seam.excel.Template;
 import org.jboss.seam.excel.WorksheetItem;
-import org.jboss.seam.excel.DocumentData.DocumentType;
+import org.jboss.seam.document.DocumentData.DocumentType;
 import org.jboss.seam.excel.jxl.JXLTemplates.CellInfo;
 import org.jboss.seam.excel.ui.UICell;
 import org.jboss.seam.excel.ui.UIColumn;

Modified: trunk/src/excel/org/jboss/seam/excel/jxl/exporter/ExcelExporter.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/jxl/exporter/ExcelExporter.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/org/jboss/seam/excel/jxl/exporter/ExcelExporter.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -17,8 +17,8 @@
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
 import org.jboss.seam.core.Interpolator;
 import org.jboss.seam.core.Manager;
-import org.jboss.seam.excel.DocumentData;
-import org.jboss.seam.excel.DocumentStore;
+import org.jboss.seam.document.DocumentData;
+import org.jboss.seam.document.DocumentStore;
 import org.jboss.seam.excel.ExcelFactory;
 import org.jboss.seam.excel.ExcelWorkbook;
 import org.jboss.seam.excel.ExcelWorkbookException;

Modified: trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -8,12 +8,12 @@
 import javax.faces.context.FacesContext;
 
 import org.jboss.seam.core.Manager;
-import org.jboss.seam.excel.DocumentData;
-import org.jboss.seam.excel.DocumentStore;
+import org.jboss.seam.document.DocumentData;
+import org.jboss.seam.document.DocumentStore;
 import org.jboss.seam.excel.ExcelFactory;
 import org.jboss.seam.excel.ExcelWorkbook;
 import org.jboss.seam.excel.Template;
-import org.jboss.seam.excel.DocumentData.DocumentType;
+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;

Modified: trunk/src/main/META-INF/faces-config.xml
===================================================================
--- trunk/src/main/META-INF/faces-config.xml	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/main/META-INF/faces-config.xml	2008-08-05 19:05:20 UTC (rev 8589)
@@ -19,5 +19,8 @@
    <lifecycle>
       <phase-listener>org.jboss.seam.jsf.SeamPhaseListener</phase-listener>
    </lifecycle>
-    
+
+   <lifecycle>
+       <phase-listener>org.jboss.seam.document.DocumentStorePhaseListener</phase-listener>
+   </lifecycle>    
 </faces-config>

Added: trunk/src/main/org/jboss/seam/document/DocumentData.java
===================================================================
--- trunk/src/main/org/jboss/seam/document/DocumentData.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/document/DocumentData.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -0,0 +1,73 @@
+package org.jboss.seam.document;
+
+import java.io.Serializable;
+
+public class DocumentData 
+    implements Serializable
+{
+    byte[] data;
+    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;
+    }
+
+    public byte[] getData() {
+        return data;
+    }
+    public DocumentType getDocumentType() {
+        return documentType;
+    }
+    public String getBaseName() {
+        return baseName;
+    }
+
+    
+    public void setFilename(String fileName) {
+        this.fileName = fileName;
+    }
+    
+    public String getFileName() {
+        if (fileName == null) {
+            return getBaseName() + "." + getDocumentType().getExtension();
+        } else {
+           return fileName;
+        }
+    }
+
+    public void setDisposition(String disposition) {
+        this.disposition = disposition;
+    }
+
+    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

Added: trunk/src/main/org/jboss/seam/document/DocumentStore.java
===================================================================
--- trunk/src/main/org/jboss/seam/document/DocumentStore.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/document/DocumentStore.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -0,0 +1,100 @@
+package org.jboss.seam.document;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContext;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+
+ at Name("org.jboss.seam.document.documentStore")
+ at Scope(ScopeType.CONVERSATION)
+ at Install(precedence=Install.BUILT_IN)
+public class DocumentStore 
+    implements Serializable
+{    
+    public static final String DOCSTORE_BASE_URL = "/seam-docstore";
+
+    private static final long serialVersionUID = -357154201942127711L;
+
+    Map<String,DocumentData> dataStore = new HashMap<String,DocumentData>();   
+
+    long nextId = 1;
+    
+ 
+    boolean useExtensions = false;
+    String errorPage = null;
+    
+    public void setUseExtensions(boolean useExtensions) 
+    {
+        this.useExtensions = useExtensions;
+    }
+    
+    public void setErrorPage(String errorPage) 
+    {
+        this.errorPage = errorPage;
+    }
+    
+    public String getErrorPage() 
+    {
+        return errorPage;
+    }
+    
+    public String newId() 
+    {
+        return String.valueOf(nextId++);
+    }
+
+    public void saveData(String id, DocumentData documentData) 
+    {
+        dataStore.put(id, documentData);
+    }
+
+    public boolean idIsValid(String id) 
+    {
+        return dataStore.get(id) != null;
+    }
+    
+    public DocumentData getDocumentData(String id) 
+    {
+        return dataStore.get(id);
+    }
+    
+    public static DocumentStore instance()
+    {
+        return (DocumentStore) Component.getInstance(DocumentStore.class);
+    }
+  
+
+    public String preferredUrlForContent(String baseName, String extension, String contentId) 
+    {                
+        return baseUrlForContent(baseName, extension) + "?docId=" + contentId;
+    }
+
+    protected String baseUrlForContent(String baseName, String extension) {
+        if (useExtensions) {
+            return baseName + "." + extension;
+        } else { 
+            FacesContext context = FacesContext.getCurrentInstance();
+            ViewHandler handler = context.getApplication().getViewHandler();
+            String url = handler.getActionURL(context, 
+                    DOCSTORE_BASE_URL + getDefaultSuffix(context));
+            return context.getExternalContext().encodeActionURL(url);
+        }
+    }
+    
+    public static String getDefaultSuffix(FacesContext context) 
+        throws FacesException 
+    {
+        String viewSuffix = context.getExternalContext().getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME);
+        return (viewSuffix != null) ? viewSuffix : ViewHandler.DEFAULT_SUFFIX;
+    }
+}
+   

Added: trunk/src/main/org/jboss/seam/document/DocumentStorePhaseListener.java
===================================================================
--- trunk/src/main/org/jboss/seam/document/DocumentStorePhaseListener.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/document/DocumentStorePhaseListener.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -0,0 +1,66 @@
+package org.jboss.seam.document;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.seam.navigation.Pages;
+import org.jboss.seam.web.Parameters;
+
+
+public class DocumentStorePhaseListener 
+    implements PhaseListener 
+{
+    private static final long serialVersionUID = 7308251684939658978L;
+
+    public PhaseId getPhaseId() 
+    {
+        return PhaseId.RENDER_RESPONSE;
+    }
+
+    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 sendContent(FacesContext context, String contentId) 
+    {
+        try 
+        {            
+            DocumentData documentData = DocumentStore.instance().getDocumentData(contentId);
+            
+            if (documentData != null) {
+                byte[] data = documentData.getData();
+
+                HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
+                response.setContentType( documentData.getDocumentType().getMimeType() );
+
+                response.setHeader("Content-Disposition", 
+                        documentData.getDisposition() + 
+                        "; filename=\"" + documentData.getFileName() + "\"");
+
+                if (data != null) {
+                    response.getOutputStream().write(data);
+                }
+                context.responseComplete();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+}

Added: trunk/src/main/org/jboss/seam/document/DocumentStoreServlet.java
===================================================================
--- trunk/src/main/org/jboss/seam/document/DocumentStoreServlet.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/document/DocumentStoreServlet.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -0,0 +1,67 @@
+package org.jboss.seam.document;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.seam.servlet.ContextualHttpServletRequest;
+import org.jboss.seam.web.Parameters;
+
+public class DocumentStoreServlet 
+    extends HttpServlet 
+{
+    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();       
+
+            response.setContentType(documentData.getDocumentType().getMimeType());            
+            response.setHeader("Content-Disposition", 
+                               documentData.getDisposition() + 
+                               "; filename=\"" + documentData.getFileName() + "\"");
+
+            if (data != null) {
+                response.getOutputStream().write(data);
+            }
+        } else{
+             String error = store.getErrorPage();             
+             if (error != null) {      
+                 if (error.startsWith("/")) {
+                     error = request.getContextPath() + error;
+                 }
+                 response.sendRedirect(error);
+             } else {
+                 response.sendError(404);
+             }
+        }
+    }
+}

Deleted: trunk/src/pdf/org/jboss/seam/pdf/DocumentData.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/DocumentData.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/pdf/org/jboss/seam/pdf/DocumentData.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -1,74 +0,0 @@
-package org.jboss.seam.pdf;
-
-import java.io.Serializable;
-
-public class DocumentData 
-    implements Serializable
-{
-    byte[] data;
-    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;
-    }
-
-
-    public byte[] getData() {
-        return data;
-    }
-    public DocumentType getDocumentType() {
-        return documentType;
-    }
-    public String getBaseName() {
-        return baseName;
-    }
-
-    
-    public void setFilename(String fileName) {
-        this.fileName = fileName;
-    }
-    
-    public String getFileName() {
-        if (fileName == null) {
-            return getBaseName() + "." + getDocumentType().getExtension();
-        } else {
-           return fileName;
-        }
-    }
-
-    public void setDisposition(String disposition) {
-        this.disposition = disposition;
-    }
-
-    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

Deleted: trunk/src/pdf/org/jboss/seam/pdf/DocumentStore.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/DocumentStore.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/pdf/org/jboss/seam/pdf/DocumentStore.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -1,94 +0,0 @@
-package org.jboss.seam.pdf;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.faces.application.ViewHandler;
-import javax.faces.context.FacesContext;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.ui.util.Faces;
-
- at Name("org.jboss.seam.pdf.documentStore")
- at Scope(ScopeType.CONVERSATION)
- at Install(precedence=Install.BUILT_IN)
-public class DocumentStore implements Serializable
-{    
-    private static final long serialVersionUID = -357154201942127711L;
-
-    Map<String,DocumentData> dataStore = new HashMap<String,DocumentData>();   
-
-    long nextId = 1;
-    boolean useExtensions = false;
-    String errorPage = null;
-    
-    public void setUseExtensions(boolean useExtensions) 
-    {
-        this.useExtensions = useExtensions;
-    }
-    
-    public void setErrorPage(String errorPage) 
-    {
-        this.errorPage = errorPage;
-    }
-    
-    public String getErrorPage() 
-    {
-        return errorPage;
-    }
-    
-    public String newId() 
-    {
-        return String.valueOf(nextId++);
-    }
-
-    public void saveData(String id, DocumentData documentData) 
-    {
-        dataStore.put(id, documentData);
-    }
-
-    public boolean idIsValid(String id) 
-    {
-        return dataStore.get(id) != null;
-    }
-    
-    public DocumentData getDocumentData(String id) 
-    {
-        return dataStore.get(id);
-    }
-    
-    public static DocumentStore instance()
-    {
-        return (DocumentStore) Component.getInstance(DocumentStore.class);
-    }
-  
-
-    public String preferredUrlForContent(String baseName, String extension, String contentId) 
-    {                
-        return baseUrlForContent(baseName, extension) + "?docId=" + contentId;
-    }
-
-    protected String baseUrlForContent(String baseName, String extension) {
-        if (useExtensions) {
-            return baseName + "." + extension;
-        } else { 
-            FacesContext context = FacesContext.getCurrentInstance();
-            ViewHandler handler = context.getApplication().getViewHandler();
-            String url = handler.getActionURL(context, "/seam-doc" + Faces.getDefaultSuffix(context));
-            return context.getExternalContext().encodeActionURL(url);
-        }
-    }
-    
-//    @Deprecated
-//    public String preferredUrlForContent(String baseName, DocType docType, String contentId) 
-//    {
-//        return preferredUrlForContent(baseName, docType.getExtension(), contentId);
-//    }
-    
-}
-   

Deleted: trunk/src/pdf/org/jboss/seam/pdf/DocumentStorePhaseListener.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/DocumentStorePhaseListener.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/pdf/org/jboss/seam/pdf/DocumentStorePhaseListener.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -1,67 +0,0 @@
-package org.jboss.seam.pdf;
-
-import java.io.IOException;
-
-import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.seam.navigation.Pages;
-import org.jboss.seam.web.Parameters;
-
-
-public class DocumentStorePhaseListener 
-    implements PhaseListener 
-{
-    private static final long serialVersionUID = 7308251684939658978L;
-
-    public PhaseId getPhaseId() 
-    {
-        return PhaseId.RENDER_RESPONSE;
-    }
-
-    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("/seam-doc") ) 
-        {
-            sendContent(phaseEvent.getFacesContext(), id);
-        }
-    }
-
-    public void sendContent(FacesContext context, String contentId) 
-    {
-        try 
-        {            
-            DocumentData documentData = DocumentStore.instance().getDocumentData(contentId);
-            
-            byte[] data = documentData.getData();
-
-            HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
-            response.setContentType( documentData.getDocumentType().getMimeType() );
-            
-            response.setHeader("Content-Disposition", 
-                                documentData.getDisposition() + 
-                                "; filename=\"" + documentData.getFileName() + "\"");
-            
-            if (data != null) 
-            {
-                response.getOutputStream().write(data);
-            }
-            context.responseComplete();
-        } 
-        catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-}

Deleted: trunk/src/pdf/org/jboss/seam/pdf/DocumentStoreServlet.java
===================================================================
--- trunk/src/pdf/org/jboss/seam/pdf/DocumentStoreServlet.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/pdf/org/jboss/seam/pdf/DocumentStoreServlet.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -1,67 +0,0 @@
-package org.jboss.seam.pdf;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.seam.servlet.ContextualHttpServletRequest;
-import org.jboss.seam.web.Parameters;
-
-public class DocumentStoreServlet 
-    extends HttpServlet 
-{
-    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();       
-
-            response.setContentType(documentData.getDocumentType().getMimeType());            
-            response.setHeader("Content-Disposition", 
-                               documentData.getDisposition() + 
-                               "; filename=\"" + documentData.getFileName() + "\"");
-
-            if (data != null) {
-                response.getOutputStream().write(data);
-            }
-        } else{
-             String error = store.getErrorPage();             
-             if (error != null) {      
-                 if (error.startsWith("/")) {
-                     error = request.getContextPath() + error;
-                 }
-                 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	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -10,10 +10,10 @@
 
 import org.jboss.seam.core.Manager;
 import org.jboss.seam.navigation.Pages;
-import org.jboss.seam.pdf.DocumentData;
-import org.jboss.seam.pdf.DocumentStore;
+import org.jboss.seam.document.DocumentData;
+import org.jboss.seam.document.DocumentStore;
+import org.jboss.seam.document.DocumentData.DocumentType;
 import org.jboss.seam.pdf.ITextUtils;
-import org.jboss.seam.pdf.DocumentData.DocumentType;
 
 import com.lowagie.text.DocWriter;
 import com.lowagie.text.Document;

Modified: trunk/src/test/excel/unit/org/jboss/seam/test/excel/unit/JXLExcelWorkbookTest.java
===================================================================
--- trunk/src/test/excel/unit/org/jboss/seam/test/excel/unit/JXLExcelWorkbookTest.java	2008-08-05 18:40:02 UTC (rev 8588)
+++ trunk/src/test/excel/unit/org/jboss/seam/test/excel/unit/JXLExcelWorkbookTest.java	2008-08-05 19:05:20 UTC (rev 8589)
@@ -9,7 +9,7 @@
 import jxl.format.BorderLineStyle;
 import jxl.format.Colour;
 
-import org.jboss.seam.excel.DocumentData;
+import org.jboss.seam.document.DocumentData;
 import org.jboss.seam.excel.ExcelWorkbook;
 import org.jboss.seam.excel.ExcelWorkbookException;
 import org.jboss.seam.excel.jxl.JXLExcelWorkbook;




More information about the seam-commits mailing list