KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > javaee > blueprints > fileupload > FileUploadCustomBean


1 /*
2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at:
3 * http://developer.sun.com/berkeley_license.html
4 * $Id: FileUploadCustomBean.java,v 1.2 2006/07/31 22:44:34 basler Exp $
5 */

6 package com.sun.javaee.blueprints.fileupload;
7
8 import java.util.Hashtable JavaDoc;
9 import java.io.IOException JavaDoc;
10
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import org.apache.shale.remoting.faces.ResponseFactory;
14
15 import com.sun.javaee.blueprints.components.ui.fileupload.FileUploadStatus;
16
17 /*
18  * FileUploadCustomBean.java
19  *
20  * Created on February 8, 2006, 6:11 AM
21  *
22  * To change this template, choose Tools | Template Manager
23  * and open the template in the editor.
24  */

25
26 /**
27  *
28  * @author basler
29  */

30 public class FileUploadCustomBean {
31     
32     private boolean bDebug=false;
33     /**
34      * <p>Factory for response writers that we can use to construct the
35      * outgoing response.</p>
36      */

37     private static ResponseFactory factory = new ResponseFactory();
38     
39     
40     /** Creates a new instance of FileUploadCustomBean */
41     public FileUploadCustomBean() {
42     }
43     
44     public void postProcessingMethod(FacesContext context, Hashtable JavaDoc htUpload, FileUploadStatus status) {
45         if(bDebug) System.out.println("IN Custom Post Processing method");
46         try {
47             // set custom return enabled so Phaselistener knows not to send default response
48
status.enableCustomReturn();
49             StringBuffer JavaDoc sb=new StringBuffer JavaDoc();
50             
51             // Acquire a response containing these results
52
ResponseWriter writer = factory.getResponseWriter(context, "text/xml");
53             writer.startElement("response", null);
54                 writer.startElement("message", null);
55                 writer.write("***CUSTOM SERVER-SIDE RETURN *** MESSAGE->");
56                 writer.write(status.getMessage());
57                 writer.endElement("message");
58
59                 writer.startElement("status", null);
60                 writer.write(status.getStatus());
61                 writer.endElement("status");
62
63                 writer.startElement("duration", null);
64                 writer.write(String.valueOf(status.getUploadTime()));
65                 writer.endElement("duration");
66
67                 writer.startElement("duration_string", null);
68                 writer.write(status.getUploadTimeString());
69                 writer.endElement("duration_string");
70
71                 writer.startElement("start_date", null);
72                 writer.write(status.getStartUploadDate().toString());
73                 writer.endElement("start_date");
74
75                 writer.startElement("end_date", null);
76                 writer.write(status.getEndUploadDate().toString());
77                 writer.endElement("end_date");
78
79                 writer.startElement("upload_size", null);
80                 writer.write(String.valueOf(status.getTotalUploadSize()));
81                 writer.endElement("upload_size");
82             writer.endElement("response");
83             writer.flush();
84             
85         } catch (IOException JavaDoc iox) {
86             System.out.println("FileUploadPhaseListener error writting AJAX response : " + iox);
87         }
88
89     }
90     
91 }
92
Popular Tags