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

Norman Richards norman.richards at jboss.com
Sat Jan 20 02:41:23 EST 2007


  User: nrichards
  Date: 07/01/20 02:41:23

  Modified:    src/pdf/org/jboss/seam/pdf     DocumentStore.java
                        DocumentStorePhaseListener.java
  Added:       src/pdf/org/jboss/seam/pdf     DocumentStoreServlet.java
                        package-info.java
  Log:
  SEAM-677: preliminary support for proper file extensions
  
  Revision  Changes    Path
  1.3       +43 -6     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.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- DocumentStore.java	18 Jan 2007 02:29:03 -0000	1.2
  +++ DocumentStore.java	20 Jan 2007 07:41:23 -0000	1.3
  @@ -8,6 +8,7 @@
   
   @Name("documentStore")
   @Scope(ScopeType.SESSION)
  + at Install(precedence=Install.BUILT_IN)
   public class DocumentStore 
       implements Serializable
   {    
  @@ -16,12 +17,17 @@
       Map<String,DocumentData> dataStore = new HashMap<String,DocumentData>();   
   
       long nextId = 1;
  +    boolean useExtensions = false;
  +    
  +    public void setUseExtensions(boolean useExtensions) {
  +        this.useExtensions = useExtensions;
  +    }
       
       public String newId() {
           return String.valueOf(nextId++);
       }
   
  -    public void saveData(String id, String type, byte[] data) {
  +    public void saveData(String id, DocType type, byte[] data) {
           dataStore.put(id, new DocumentData(type,data));
       }
   
  @@ -30,7 +36,7 @@
       }
       
       public String typeForId(String id) {
  -        return dataStore.get(id).getMimeType();
  +        return dataStore.get(id).getDocType().getMimeType();
       }
   
       public static DocumentStore instance()
  @@ -40,20 +46,51 @@
       
       static class DocumentData {
           byte[] data;
  -        String mimeType;
  +        DocType docType;
           
  -        public DocumentData(String mimeType,byte[] data) {
  +        public DocumentData(DocType docType,byte[] data) {
               super();
               this.data = data;
  -            this.mimeType = mimeType;
  +            this.docType = docType;
           }
           public byte[] getData() {
               return data;
           }
  +        public DocType getDocType() {
  +            return docType;
  +        }      
  +    }
  +
  +    public String preferredUrlForContent(DocType docType, String id) {
  +        String extension = "seam";
  +
  +        if (useExtensions) {
  +            extension = docType.getExtension();
  +        } 
  +        
  +        return "seam-doc." + extension + "?docId="+id;
  +    }
  +    
  +    
  +    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.2       +2 -3      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.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- DocumentStorePhaseListener.java	15 Jan 2007 19:36:41 -0000	1.1
  +++ DocumentStorePhaseListener.java	20 Jan 2007 07:41:23 -0000	1.2
  @@ -20,7 +20,7 @@
   
   
       public void afterPhase(PhaseEvent phaseEvent) {
  -        //String rootId = phaseEvent.getFacesContext().getViewRoot().getViewId();
  +        // ...
       }
   
   
  @@ -31,7 +31,6 @@
           Parameters.convertMultiValueRequestParameter(Parameters.getRequestParameters(),
                                                        "docId",
                                                        String.class);
  -        
           if (rootId.startsWith("/seam-doc")) {            
               sendContent(phaseEvent.getFacesContext(), id);
           }
  
  
  
  1.1      date: 2007/01/20 07:41:23;  author: nrichards;  state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/DocumentStoreServlet.java
  
  Index: DocumentStoreServlet.java
  ===================================================================
  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.util.Parameters;
  
  public class DocumentStoreServlet 
      extends HttpServlet 
  {
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) 
          throws ServletException, 
                 IOException 
      {
          String contentId = (String)
          Parameters.convertMultiValueRequestParameter(Parameters.getRequestParameters(),
                  "docId",
                  String.class);        
          
          
          DocumentStore store = DocumentStore.instance();
          byte[] data = store.dataForId(contentId);          
            
          response.setContentType(store.typeForId(contentId));
          if (data != null) {
              response.getOutputStream().write(data);
          }
      }    
  }
  
  
  
  1.1      date: 2007/01/20 07:41:23;  author: nrichards;  state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/package-info.java
  
  Index: package-info.java
  ===================================================================
  @Namespace("http://jboss.com/products/seam/pdf")
  package org.jboss.seam.pdf;
  
  import org.jboss.seam.annotations.Namespace;
  
  



More information about the jboss-cvs-commits mailing list