List items;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
throw new XFormsException(e);
}
Map formFields = new HashMap();
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
String itemName = item.getName();
String fieldName = item.getFieldName();
String id = fieldName.substring(Config.getInstance().
getProperty("chiba.web.dataPrefix").length());
if (logger.isLoggable(Level.FINE)) {
logger.fine("Multipart item name is: " + itemName
+ " and fieldname is: " + fieldName
+ " and id is: " + id);
logger.fine("Is formfield: " + item.isFormField());
logger.fine("Content: " + item.getString());
}
if (item.isFormField()) {
if (removeUploadPrefix == null) {
try {
removeUploadPrefix = Config.getInstance().
getProperty("chiba.web.removeUploadPrefix",
"ru_");
} catch (Exception e) {
removeUploadPrefix = "ru_";
}
}
if (fieldName.startsWith(removeUploadPrefix)) {
id = fieldName.substring(removeUploadPrefix.length());
chibaBean.updateControlValue(id, "", "", null);
continue;
}
// It's a field name, not a file. Do the same
// as processUrlencodedRequest
String values[] = (String[]) formFields.get(fieldName);
String formFieldValue = null;
try {
formFieldValue = item.getString(encoding);
} catch (UnsupportedEncodingException e1) {
throw new XFormsException(e1.getMessage(), e1);
}
if (values == null) {
formFields.put(fieldName, new String[]{formFieldValue});
} else {
String[] tmp = new String[values.length + 1];
System.arraycopy(values, 0, tmp, 0, values.length);
tmp[values.length] = formFieldValue;
formFields.put(fieldName, tmp);
}
} else {
String uniqueFilename = new File("file" + Integer.
toHexString((int) (Math.random() * 10000)),
new File(itemName).getName()).getPath();
File savedFile = new File(uploadRoot, uniqueFilename);
byte[] data = null;
if (item.getSize() > 0)
if (chibaBean.storesExternalData(id)) {
try {
savedFile.getParentFile().mkdir();
item.write(savedFile);
} catch (Exception e) {
throw new XFormsException(e);
}
try {
data = savedFile.toURI().toString().
getBytes(encoding);
} catch (UnsupportedEncodingException e) {
throw new XFormsException(e);
}
} else {
data = item.get();
}