mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
Reduces code duplication
This commit is contained in:
+1
-1
@@ -240,7 +240,7 @@ public class JakartaMultiPartRequest implements MultiPartRequest {
|
||||
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()]);
|
||||
|
||||
+1
-10
@@ -135,15 +135,6 @@ public class JakartaStreamMultiPartRequest implements MultiPartRequest {
|
||||
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)
|
||||
*/
|
||||
@@ -155,7 +146,7 @@ public class JakartaStreamMultiPartRequest implements MultiPartRequest {
|
||||
|
||||
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()]);
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.struts2.dispatcher.multipart;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class JakartaUploadedFile implements UploadedFile {
|
||||
|
||||
private File file;
|
||||
|
||||
public JakartaUploadedFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long length() {
|
||||
return file.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFile() {
|
||||
return file.isFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete() {
|
||||
return file.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAbsolutePath() {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getContent() {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -21,11 +21,11 @@ package org.apache.struts2.dispatcher.multipart;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.apache.struts2.StrutsInternalTestCase;
|
||||
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;
|
||||
@@ -198,7 +198,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
|
||||
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());
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ public class PellMultiPartRequest implements MultiPartRequest {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user