1 6 package com.sun.javaee.blueprints.fileupload; 7 8 import java.util.Hashtable ; 9 import java.io.IOException ; 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 25 26 30 public class FileUploadCustomBean { 31 32 private boolean bDebug=false; 33 37 private static ResponseFactory factory = new ResponseFactory(); 38 39 40 41 public FileUploadCustomBean() { 42 } 43 44 public void postProcessingMethod(FacesContext context, Hashtable htUpload, FileUploadStatus status) { 45 if(bDebug) System.out.println("IN Custom Post Processing method"); 46 try { 47 status.enableCustomReturn(); 49 StringBuffer sb=new StringBuffer (); 50 51 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 iox) { 86 System.out.println("FileUploadPhaseListener error writting AJAX response : " + iox); 87 } 88 89 } 90 91 } 92 | Popular Tags |