protected Representation processMultipartForm(PipelineConfiguration pipeconfig, Representation entity, Variant variant) {
String id = (String) getRequest().getAttributes().get("id");
XPipeline xpipeline = pipeconfig.pipeline;
XProcRuntime runtime = pipeconfig.runtime;
if (pipeconfig.ran) {
pipeconfig.reset();
xpipeline.reset();
}
String message = "";
HashMap<String,String> nameValuePairs = new HashMap<String,String> ();
HashMap<String,String> nsBindings = new HashMap<String,String> ();
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(100240);
RestletFileUpload upload = new RestletFileUpload(factory);
List<FileItem> items;
try {
items = upload.parseRequest(getRequest());
File file = null;
String filename = null;
for (final Iterator<FileItem> it = items.iterator(); it.hasNext(); ) {
FileItem fi = it.next();
String fieldName = fi.getFieldName();
String name = fi.getName();
if (name == null) {
Matcher matcher = xmlnsRE.matcher(fieldName);
if (matcher.matches()) {
nsBindings.put(matcher.group(1), new String(fi.get(), "utf-8"));
} else {
nameValuePairs.put(fieldName, new String(fi.get(), "utf-8"));
}
} else {
String port = fieldName;
if (pipeconfig.documentCount(port) == 0) {
xpipeline.clearInputs(port);
}
pipeconfig.writeTo(port);
try {
XdmNode doc = null;
MediaType m = new MediaType(fi.getContentType());
if (isXml(m)) {
doc = runtime.parse(new InputSource(fi.getInputStream()));
logger.debug("Posting XML document to " + port + " for " + id);
} else {
ReadablePipe pipe = null;
pipe = new ReadableData(runtime, XProcConstants.c_data, fi.getInputStream(), fi.getContentType());
doc = pipe.read();