Skip to content

Commit

Permalink
Reduces code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Nov 22, 2016
1 parent e152c15 commit 6280feb
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public UploadedFile[] getFile(String fieldName) {
LOG.error("Cannot write uploaded empty file to disk: {}", storeLocation.getAbsolutePath(), e);
}
}
fileList.add(new JakartaUploadedFile(storeLocation));
fileList.add(new StrutsUploadedFile(storeLocation));
}

return fileList.toArray(new UploadedFile[fileList.size()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,6 @@ public List<LocalizedMessage> getErrors() {
return errors;
}

/**
* Allows interceptor to fetch non-critical messages that can be passed to the action.
*
* @return list of string messages
*/
public List<String> getMesssages() {
return messages;
}

/* (non-Javadoc)
* @see org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFile(java.lang.String)
*/
Expand All @@ -155,7 +146,7 @@ public UploadedFile[] getFile(String fieldName) {

List<UploadedFile> files = new ArrayList<>(infos.size());
for (FileInfo fileInfo : infos) {
files.add(new JakartaUploadedFile(fileInfo.getFile()));
files.add(new StrutsUploadedFile(fileInfo.getFile()));
}

return files.toArray(new UploadedFile[files.size()]);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

import java.io.File;

public class PellUploadedFile implements UploadedFile {
public class StrutsUploadedFile implements UploadedFile {

private File file;

public PellUploadedFile(File file) {
public StrutsUploadedFile(File file) {
this.file = file;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.struts2.TestAction;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest;
import org.apache.struts2.dispatcher.multipart.JakartaUploadedFile;
import org.apache.struts2.dispatcher.multipart.StrutsUploadedFile;
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
import org.apache.struts2.dispatcher.multipart.UploadedFile;
import org.springframework.mock.web.MockHttpServletRequest;
Expand Down Expand Up @@ -198,7 +198,7 @@ public void testAcceptFileWithMaxSize() throws Exception {
URL url = ClassLoaderUtil.getResource("log4j2.xml", FileUploadInterceptorTest.class);
File file = new File(new URI(url.toString()));
assertTrue("log4j2.xml should be in src/test folder", file.exists());
boolean notOk = interceptor.acceptFile(action, new JakartaUploadedFile(file), "filename", "text/html", "inputName", validation);
boolean notOk = interceptor.acceptFile(action, new StrutsUploadedFile(file), "filename", "text/html", "inputName", validation);

assertFalse(notOk);
assertFalse(validation.getFieldErrors().isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public String[] getContentType(String fieldName) {
}

public UploadedFile[] getFile(String fieldName) {
return new UploadedFile[]{ new PellUploadedFile(multi.getFile(fieldName)) };
return new UploadedFile[]{ new StrutsUploadedFile(multi.getFile(fieldName)) };
}

public String[] getFileNames(String fieldName) {
Expand Down

0 comments on commit 6280feb

Please sign in to comment.