public ActionReportResult get() {
return options();
}
private static ParameterMap createDataBasedOnForm(FormDataMultiPart formData) {
ParameterMap data = new ParameterMap();
try {
Map<String, List<FormDataBodyPart>> m1 = formData.getFields();
Set<String> ss = m1.keySet();
for (String fieldName : ss) {
for (FormDataBodyPart bodyPart : formData.getFields(fieldName)) {
if (bodyPart.getContentDisposition().getFileName() != null) {//we have a file
//save it and mark it as delete on exit.
InputStream fileStream = bodyPart.getValueAs(InputStream.class);
String mimeType = bodyPart.getMediaType().toString();
//Use just the filename without complete path. File creation
//in case of remote deployment failing because fo this.
String fileName = bodyPart.getContentDisposition().getFileName();
if (fileName.contains("/")) {
fileName = Util.getName(fileName, '/');
} else {
if (fileName.contains("\\")) {
fileName = Util.getName(fileName, '\\');
}
}
File f = Util.saveFile(fileName, mimeType, fileStream);
f.deleteOnExit();
//put only the local path of the file in the same field.
data.add(fieldName, f.getAbsolutePath());
} else {
data.add(fieldName, bodyPart.getValue());
}
}
}
} catch (Exception ex) {
Logger.getLogger(TemplateCommandPostResource.class.getName()).log(Level.SEVERE, null, ex);