1 19 20 package com.sslexplorer.core; 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 import org.apache.struts.action.Action; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 33 import com.sslexplorer.navigation.actions.FileDownloadAction; 34 import com.sslexplorer.navigation.actions.ShowFileDownloadAction; 35 36 43 44 public class FileDownloadManager implements PageInterceptListener { 45 46 49 public final static String INTERCEPT_ID = "fileDownload"; 50 51 protected List downloads; 53 54 static int id = 0; 56 57 60 public FileDownloadManager() { 61 downloads = new ArrayList (); 62 } 63 64 69 public String getId() { 70 return INTERCEPT_ID; 71 } 72 73 81 public ActionForward checkForForward(Action action, ActionMapping mapping, HttpServletRequest request, 82 HttpServletResponse response) throws PageInterceptException { 83 if (downloads.size() > 0 && !(action instanceof ShowFileDownloadAction) && !(action instanceof FileDownloadAction)) { 84 DownloadContent download = ((DownloadContent) downloads.get(0)); 85 return CoreUtil.addParameterToForward(download.getMessageForward(), "id", String.valueOf(download.getId())); 86 } 87 return null; 88 } 89 90 96 public int addDownload(DownloadContent downloadContent) { 97 id++; 98 downloadContent.setId(id); 99 downloads.add(downloadContent); 100 return id; 101 } 102 103 109 public DownloadContent getDownload(int id) { 110 for (Iterator i = downloads.iterator(); i.hasNext();) { 111 DownloadContent l = (DownloadContent) i.next(); 112 if (l.getId() == id) { 113 return l; 114 } 115 } 116 return null; 117 } 118 119 124 public int size() { 125 return downloads.size(); 126 } 127 128 133 public void removeDownload(int id) { 134 DownloadContent d = getDownload(id); 135 if (d != null) { 136 downloads.remove(d); 137 } 138 139 } 140 141 146 public boolean isRedirect() { 147 return false; 148 } 149 }
| Popular Tags
|