1 15 16 package com.jdon.strutsutil.file; 17 18 import org.apache.struts.action.*; 19 import javax.servlet.http.*; 20 21 import java.io.*; 22 import com.jdon.util.Debug; 23 24 import com.jdon.strutsutil.file.UploadFile; 25 import com.jdon.strutsutil.file.filter.*; 26 27 import com.jdon.util.UtilValidate; 28 29 43 public abstract class ImageShowAction extends Action { 44 public final static String module = ImageShowAction.class.getName(); 45 46 private static final byte[] BLANK = { 47 71, 73, 70, 56, 57, 97, 1, 0, 1, 0, -111, 0, 0, 0, 0, 0, -1, -1, -1, -1, 48 -1, -1, 0, 0, 0, 33, -7, 4, 1, 0, 0, 2, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 49 0, 2, 2, 76, 1, 0, 59}; 50 51 public ActionForward execute(ActionMapping actionMapping, 52 ActionForm actionForm, 53 HttpServletRequest request, 54 HttpServletResponse response) throws 55 Exception { 56 57 String Id = request.getParameter("id"); 58 String tempId = request.getParameter("tempId"); 59 60 String imageId = null; 61 if (!UtilValidate.isEmpty(tempId)) 62 imageId = tempId; 63 else if (!UtilValidate.isEmpty(Id)) 64 imageId = Id; 65 else 66 throw new Exception ("parameter id and tempId all is null"); 67 68 UploadFile uploadFile = null; 69 try { 70 71 ImageFilter imageCacheFilter = new ImageCacheFilter(getImageFilter()); 72 ImageFilter imageFilter = new ImageSessionFilter(imageCacheFilter); 73 74 uploadFile = imageFilter.getUploadFile(request, imageId); 75 if (uploadFile != null) 76 outImage(response, uploadFile.getData()); 77 else 78 outImage(response, BLANK); 79 } catch (Exception ex) { 80 Debug.logError("[JdonFramework]get the image error:" + ex, module); 81 82 } 83 return null; 84 } 85 86 private void outImage(HttpServletResponse response, byte[] data) throws 87 Exception { 88 response.setContentType("images/jpeg"); 89 OutputStream toClient = response.getOutputStream(); 90 try { 91 92 toClient.write(data); 93 94 } catch (Exception ex) { 95 Debug.logError("[JdonFramework]get the image error:" + ex, module); 96 } finally { 97 toClient.close(); 98 } 99 100 } 101 102 107 public abstract ImageFilter getImageFilter(); 108 109 } 110 | Popular Tags |