Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#913 Implement convenience method form multipart forms
(cherry picked from commit c6d77ea)
- Loading branch information
Showing
5 changed files
with
117 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
activeweb/src/main/java/org/javalite/activeweb/MultipartForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.javalite.activeweb; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class MultipartForm { | ||
|
||
private List<FormItem> formItems = new ArrayList<>(); | ||
private List<FileItem> fileItems = new ArrayList<>(); | ||
|
||
void addFormItem(FormItem formItem){ | ||
formItems.add(formItem); | ||
} | ||
|
||
void addFileItem(FileItem fileItem){ | ||
fileItems.add(fileItem); | ||
} | ||
|
||
/** | ||
* @return all file items | ||
*/ | ||
public List<FileItem> getFileItems() { | ||
return fileItems; | ||
} | ||
|
||
/** | ||
* @return all form items | ||
*/ | ||
public List<FormItem> getFormItems() { | ||
return formItems; | ||
} | ||
|
||
/** | ||
* | ||
* @param name name of a form input that is not a file | ||
* @return value of a named input from a form | ||
*/ | ||
public String param(String name){ | ||
for (FormItem formItem : formItems) { | ||
if(formItem.getFieldName().equals(name)){ | ||
return formItem.getStreamAsString(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @return all form items that are not files. | ||
*/ | ||
public Map<String,String> params(){ | ||
Map<String,String> map = new HashMap<>(); | ||
for (FormItem formItem : formItems) { | ||
map.put(formItem.getFieldName(), formItem.getStreamAsString()); | ||
} | ||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters