[jboss-cvs] jboss-seam/src/pdf/org/jboss/seam/pdf ...

Norman Richards norman.richards at jboss.com
Sun Feb 4 14:10:34 EST 2007


  User: nrichards
  Date: 07/02/04 14:10:34

  Modified:    src/pdf/org/jboss/seam/pdf     DocumentStore.java
                        DocumentStorePhaseListener.java
                        DocumentStoreServlet.java
  Added:       src/pdf/org/jboss/seam/pdf     DocumentData.java
  Log:
  refactor to expose DocumentData
  
  Revision  Changes    Path
  1.6       +9 -58     jboss-seam/src/pdf/org/jboss/seam/pdf/DocumentStore.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DocumentStore.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/DocumentStore.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- DocumentStore.java	24 Jan 2007 17:39:40 -0000	1.5
  +++ DocumentStore.java	4 Feb 2007 19:10:34 -0000	1.6
  @@ -5,6 +5,7 @@
   
   import org.jboss.seam.*;
   import org.jboss.seam.annotations.*;
  +import org.jboss.seam.pdf.DocumentData.DocType;
   
   @Name("documentStore")
   @Scope(ScopeType.CONVERSATION)
  @@ -36,24 +37,16 @@
           return String.valueOf(nextId++);
       }
   
  -    public void saveData(String id, String baseName, DocType type, byte[] data) {
  -        dataStore.put(id, new DocumentData(baseName, type, data));
  +    public void saveData(String id, DocumentData documentData) {
  +        dataStore.put(id, documentData);
       }
   
       public boolean idIsValid(String id) {
           return dataStore.get(id) != null;
       }
       
  -    public byte[] dataForId(String id) {
  -        return dataStore.get(id).getData();
  -    }
  -    
  -    public String typeForId(String id) {
  -        return dataStore.get(id).getDocType().getMimeType();
  -    }
  -   
  -    public String fileNameForId(String id) {
  -        return dataStore.get(id).getBaseName() + "." + dataStore.get(id).getDocType().getExtension();
  +    public DocumentData getDocumentData(String id) { 
  +        return dataStore.get(id);
       }
   
       public static DocumentStore instance()
  @@ -61,58 +54,16 @@
           return (DocumentStore) Component.getInstance(DocumentStore.class, true);
       }
       
  -    static class DocumentData {
  -        byte[] data;
  -        DocType docType;
  -        String baseName;
  -        
  -        public DocumentData(String baseName, DocType docType, byte[] data) {
  -            super();
  -            this.data = data;
  -            this.docType = docType;
  -            this.baseName = baseName;
  -        }
  -        public byte[] getData() {
  -            return data;
  -        }
  -        public DocType getDocType() {
  -            return docType;
  -        }
  -        public String getBaseName() {
  -            return baseName;
  -        }
  -    }
   
  -    public String preferredUrlForContent(String baseName, DocType docType, String id) {
  +    public String preferredUrlForContent(String baseName, DocType docType, String contentId) {
           String baseUrl = "seam-doc.seam";
           
           if (useExtensions) {
               baseUrl = baseName + "." + docType.getExtension();
           } 
           
  -        return baseUrl + "?docId=" + id;
  +        return baseUrl + "?docId=" + contentId;
       }
       
  -    
  -    public enum DocType { 
  -        PDF("pdf", "application/pdf"), 
  -        RTF("rtf", "text/rtf"),
  -        HTML("html", "text/html");
  -        
  -        private String mimeType;
  -        private String extension;
  -
  -        DocType(String extension, String mimeType) {
  -            this.extension = extension;
  -            this.mimeType = mimeType;
  -        }
  -        
  -        public String getMimeType() {
  -            return mimeType;
  -        }
  -        
  -        public String getExtension(){
  -            return extension;
  -        }
  -    }
   }
  +   
  
  
  
  1.5       +9 -6      jboss-seam/src/pdf/org/jboss/seam/pdf/DocumentStorePhaseListener.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DocumentStorePhaseListener.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/DocumentStorePhaseListener.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- DocumentStorePhaseListener.java	24 Jan 2007 06:09:54 -0000	1.4
  +++ DocumentStorePhaseListener.java	4 Feb 2007 19:10:34 -0000	1.5
  @@ -14,6 +14,8 @@
   public class DocumentStorePhaseListener 
       implements PhaseListener 
   {
  +    private static final long serialVersionUID = 7308251684939658978L;
  +
       public PhaseId getPhaseId() {
           return PhaseId.RENDER_RESPONSE;
       }
  @@ -38,14 +40,15 @@
   
       public void sendContent(FacesContext context, String contentId) {
           try {
  -            DocumentStore store = DocumentStore.instance();
  -            byte[] data = store.dataForId(contentId);
  +            DocumentData documentData = DocumentStore.instance().getDocumentData(contentId);
  +            
  +            byte[] data = documentData.getData();
   
               HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
  -            response.setContentType(store.typeForId(contentId));
  +            response.setContentType(documentData.getDocType().getMimeType());
   
               response.setHeader("Content-Disposition", 
  -                               "inline; filename=\"" + store.fileNameForId(contentId) + "\"");
  +                               "inline; filename=\"" + documentData.getFileName() + "\"");
               
               if (data != null) {
                   response.getOutputStream().write(data);
  
  
  
  1.5       +5 -3      jboss-seam/src/pdf/org/jboss/seam/pdf/DocumentStoreServlet.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DocumentStoreServlet.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/DocumentStoreServlet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- DocumentStoreServlet.java	24 Jan 2007 21:55:44 -0000	1.4
  +++ DocumentStoreServlet.java	4 Feb 2007 19:10:34 -0000	1.5
  @@ -25,11 +25,13 @@
           DocumentStore store = DocumentStore.instance();
           
           if (store.idIsValid(contentId)) {
  -            byte[] data = store.dataForId(contentId);          
  +            DocumentData documentData = store.getDocumentData(contentId);
   
  -            response.setContentType(store.typeForId(contentId));
  +            byte[] data = documentData.getData();       
  +
  +            response.setContentType(documentData.getDocType().getMimeType());
               response.setHeader("Content-Disposition", 
  -                    "inline; filename=\"" + store.fileNameForId(contentId) + "\"");
  +                    "inline; filename=\"" + documentData.getFileName() + "\"");
   
               if (data != null) {
                   response.getOutputStream().write(data);
  
  
  
  1.1      date: 2007/02/04 19:10:34;  author: nrichards;  state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/DocumentData.java
  
  Index: DocumentData.java
  ===================================================================
  package org.jboss.seam.pdf;
  
  public class DocumentData {
      byte[] data;
      DocType docType;
      String baseName;
      
      public DocumentData(String baseName, DocType docType, byte[] data) {
          super();
          this.data = data;
          this.docType = docType;
          this.baseName = baseName;
      }
      public byte[] getData() {
          return data;
      }
      public DocType getDocType() {
          return docType;
      }
      public String getBaseName() {
          return baseName;
      }
          
      public String getFileName() {
          return getBaseName() + "." + getDocType().getExtension();
      }
      
      public enum DocType { 
          PDF("pdf", "application/pdf"), 
          RTF("rtf", "text/rtf"),
          HTML("html", "text/html");
          
          private String mimeType;
          private String extension;
  
          DocType(String extension, String mimeType) {
              this.extension = extension;
              this.mimeType = mimeType;
          }
          
          public String getMimeType() {
              return mimeType;
          }
          
          public String getExtension(){
              return extension;
          }
      }
  }
  
  



More information about the jboss-cvs-commits mailing list