Commit fb1e153f by fukai
parents c609f026 277eac95
package org.sss.presentation.noui.controller;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -12,6 +13,10 @@ import javax.servlet.http.HttpServletResponse;
import log.Log;
import log.LogFactory;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;
import org.apache.commons.io.IOUtils;
import org.sss.common.model.EventType;
import org.sss.common.model.IBaseObject;
......@@ -47,7 +52,30 @@ public class AbstractCommonController {
public Object event(String mappingUrl, String eventType, Map<String, Object> dataMap, HttpServletRequest request, HttpServletResponse response) {
NoUiContext context = null;
Result ret = null;
boolean isMultipart = false;
InputStream fileStream = null;
try {
isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload();
// Parse the request
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
// 普通表单域
if (item.isFormField()) {
String itemName = item.getFieldName();
String itemValue = Streams.asString(item.openStream());
// 给dataMap赋值
dataMap.put(itemName, itemValue);
} else { // 文件域
fileStream = item.openStream();
}
}
}
NoUiRequest noUiRequest = new NoUiRequest(request, mappingUrl, dataMap);
context = NoUiContextManager.createNoUiContext(noUiRequest);
Alias alias = new Alias(mappingUrl);
......@@ -88,16 +116,19 @@ public class AbstractCommonController {
@SuppressWarnings("rawtypes")
IDatafield dataField = (IDatafield) baseObject(context, noUiRequest, alias);
IStream stream = (IStream) dataField.getValue();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] data = new byte[1024];
int bytes = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((bytes = request.getInputStream().read(data)) != -1) {
if (fileStream != null) {
while ((bytes = fileStream.read(data)) != -1) {
bos.write(data, 0, bytes);
}
IOUtils.write(bos.toByteArray(), stream.getOutputStream());
IOUtils.closeQuietly(bos);
}
// dataField.setValue(stream);
dataField.invokeEventRules(context, EventType.ON_STREAM_UPLOAD, null);
IOUtils.closeQuietly(fileStream);
} else if (eventType.equals(ON_STREAM_DOWNLOAD)) {
@SuppressWarnings("rawtypes")
IDatafield dataField = (IDatafield) baseObject(context, noUiRequest, alias);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment