1 19 20 package org.efs.openreports.actions.image; 21 22 import java.io.IOException ; 23 import java.util.Map ; 24 25 import javax.servlet.ServletOutputStream ; 26 import javax.servlet.http.HttpServletResponse ; 27 28 import com.opensymphony.webwork.ServletActionContext; 29 import com.opensymphony.xwork.ActionContext; 30 import com.opensymphony.xwork.ActionSupport; 31 32 import org.apache.log4j.Logger; 33 34 53 54 public class ImageLoaderAction extends ActionSupport 55 { 56 protected static Logger log = Logger.getLogger(ImageLoaderAction.class); 57 58 private String imageName; 59 60 public String execute() 61 { 62 Map imagesMap = (Map ) ActionContext.getContext().getSession().get("IMAGES_MAP"); 63 64 if (imagesMap != null) 65 { 66 if (imageName != null) 67 { 68 byte[] imageData = (byte[]) imagesMap.get(imageName); 69 70 HttpServletResponse response = 71 ServletActionContext.getResponse(); 72 73 try 74 { 75 response.setContentLength(imageData.length); 76 ServletOutputStream ouputStream = response.getOutputStream(); 77 ouputStream.write(imageData, 0, imageData.length); 78 ouputStream.flush(); 79 ouputStream.close(); 80 } 81 catch(IOException ioe) 82 { 83 log.warn(ioe.toString()); 84 } 85 } 86 } 87 88 return NONE; 89 } 90 91 public String getImageName() 92 { 93 return imageName; 94 } 95 96 public void setImageName(String imageName) 97 { 98 this.imageName = imageName; 99 } 100 101 } | Popular Tags |