WW-5371 Uses the new upload mechanism in Showcase app

This commit is contained in:
Lukasz Lenart
2023-12-11 07:56:38 +01:00
parent 0bc0217b9d
commit dc4103bcb5
3 changed files with 61 additions and 57 deletions
@@ -21,75 +21,70 @@
package org.apache.struts2.showcase.fileupload;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.action.UploadedFilesAware;
import org.apache.struts2.dispatcher.multipart.UploadedFile;
import java.io.File;
import java.util.List;
/**
* Show case File Upload example's action. <code>FileUploadAction</code>
*/
public class FileUploadAction extends ActionSupport {
public class FileUploadAction extends ActionSupport implements UploadedFilesAware {
private static final long serialVersionUID = 5156288255337069381L;
private static final long serialVersionUID = 5156288255337069381L;
private String contentType;
private File upload;
private String fileName;
private String caption;
private String contentType;
private UploadedFile uploadedFile;
private String fileName;
private String caption;
private String originalName;
public String input() throws Exception {
return SUCCESS;
}
public String input() throws Exception {
return SUCCESS;
}
public String upload() throws Exception {
return SUCCESS;
}
public String upload() throws Exception {
return SUCCESS;
}
// since we are using <s:file name="upload" .../> the file name will be
// obtained through getter/setter of <file-tag-name>FileName
public String getUploadFileName() {
return fileName;
}
public String getContentType() {
return contentType;
}
public void setUploadFileName(String fileName) {
this.fileName = fileName;
}
public String getFileName() {
return fileName;
}
public String getOriginalName() {
return originalName;
}
// since we are using <s:file name="upload" ... /> the content type will be
// obtained through getter/setter of <file-tag-name>ContentType
public String getUploadContentType() {
return contentType;
}
public Object getUploadedFile() {
return uploadedFile.getContent();
}
public void setUploadContentType(String contentType) {
this.contentType = contentType;
}
public String getCaption() {
return caption;
}
public void setCaption(String caption) {
this.caption = caption;
}
// since we are using <s:file name="upload" ... /> the File itself will be
// obtained through getter/setter of <file-tag-name>
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getCaption() {
return caption;
}
public void setCaption(String caption) {
this.caption = caption;
}
public long getUploadSize() {
if (upload != null) {
return upload.length();
} else {
return 0;
}
public long getUploadSize() {
if (uploadedFile != null) {
return uploadedFile.length();
} else {
return 0;
}
}
@Override
public void withUploadedFiles(List<UploadedFile> uploadedFiles) {
this.uploadedFile = uploadedFiles.get(0);
this.fileName = uploadedFile.getName();
this.contentType = uploadedFile.getContentType();
this.originalName = uploadedFile.getOriginalName();
}
}
@@ -19,7 +19,7 @@
*/
-->
<%@ page
language="java"
language="java"
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
@@ -37,9 +37,10 @@
<div class="row">
<div class="col-md-12">
<ul>
<li>ContentType: <s:property value="uploadContentType" /></li>
<li>FileName: <s:property value="uploadFileName" /></li>
<li>File: <s:property value="upload" /></li>
<li>ContentType: <s:property value="contentType" /></li>
<li>FileName: <s:property value="fileName" /></li>
<li>Original FileName: <s:property value="originalName" /></li>
<li>File: <s:property value="uploadedFile" /></li>
<li>Caption:<s:property value="caption" /></li>
</ul>
</div>
@@ -79,6 +79,14 @@ public class StrutsUploadedFile implements UploadedFile {
return originalName;
}
@Override
public String toString() {
return "StrutsUploadedFile{" +
"contentType='" + contentType + '\'' +
", originalName='" + originalName + '\'' +
'}';
}
public static class Builder {
private final File file;
private String contentType;