package
cn.luxh.struts2.action;
import
java.io.File;
import
java.text.SimpleDateFormat;
import
java.util.Date;
import
cn.luxh.utils.ZipFileUtil;
import
com.opensymphony.xwork2.ActionSupport;
/**
* 處理多個(gè)附件下載
* @author Luxh
*/
public
class
MultiFileDownloadAction
extends
ActionSupport {
private
static
final
long
serialVersionUID = 2743077909387361587L;
private
String attachmentPath;
private
String fileName;
/**
* 下載多個(gè)附件
* 實(shí)現(xiàn):將多個(gè)附近壓縮成zip包,然后再下載zip包
*/
public
String downloadMultiFile() {
String formatDate =
new
SimpleDateFormat(
"yyyyMMddHHmmssSSS"
).format(
new
Date());
fileName =
"D:/test/"
+ formatDate +
".zip"
;
if
(attachmentPath !=
null
&& !
""
.equals(attachmentPath)) {
String[] attachmentPathArray = attachmentPath.split(
","
);
if
(attachmentPathArray !=
null
&& attachmentPathArray.length >
0
) {
File[] files =
new
File[attachmentPathArray.length];
for
(
int
i=
0
;i<attachmentPathArray.length;i++) {
if
(attachmentPathArray[i] !=
null
) {
File file =
new
File(attachmentPathArray[i].trim());
if
(file.exists()) {
files[i] = file;
}
}
}
ZipFileUtil.compressFiles2Zip(files,fileName);
}
}
return
SUCCESS;
}
public
String getAttachmentPath() {
return
attachmentPath;
}
public
void
setAttachmentPath(String attachmentPath) {
this
.attachmentPath = attachmentPath;
}
public
String getFileName() {
return
fileName;
}
public
void
setFileName(String fileName) {
this
.fileName = fileName;
}
}