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

Norman Richards norman.richards at jboss.com
Wed Jan 24 12:39:40 EST 2007


  User: nrichards
  Date: 07/01/24 12:39:40

  Modified:    src/pdf/org/jboss/seam/pdf   DocumentStore.java
                        DocumentStoreServlet.java
  Log:
  give error page option for missing pdf
  
  Revision  Changes    Path
  1.5       +13 -0     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.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- DocumentStore.java	24 Jan 2007 06:09:54 -0000	1.4
  +++ DocumentStore.java	24 Jan 2007 17:39:40 -0000	1.5
  @@ -18,11 +18,20 @@
   
       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++);
       }
  @@ -31,6 +40,10 @@
           dataStore.put(id, new DocumentData(baseName, type, data));
       }
   
  +    public boolean idIsValid(String id) {
  +        return dataStore.get(id) != null;
  +    }
  +    
       public byte[] dataForId(String id) {
           return dataStore.get(id).getData();
       }
  
  
  
  1.3       +23 -10    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.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- DocumentStoreServlet.java	24 Jan 2007 06:09:54 -0000	1.2
  +++ DocumentStoreServlet.java	24 Jan 2007 17:39:40 -0000	1.3
  @@ -2,6 +2,7 @@
   
   import java.io.IOException;
   
  +import javax.faces.context.FacesContext;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
  @@ -23,8 +24,9 @@
                   "docId",
                   String.class);        
           
  -        
           DocumentStore store = DocumentStore.instance();
  +        
  +        if (store.idIsValid(contentId)) {
           byte[] data = store.dataForId(contentId);          
             
           response.setContentType(store.typeForId(contentId));
  @@ -34,5 +36,16 @@
           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);
  +             }
  +        }
       }    
   }
  
  
  



More information about the jboss-cvs-commits mailing list