1 package org
.argeo
.slc
.web
.mvc
.management
;
5 import javax
.servlet
.http
.HttpServletRequest
;
6 import javax
.servlet
.http
.HttpServletResponse
;
8 import org
.apache
.commons
.fileupload
.FileItem
;
9 import org
.apache
.commons
.fileupload
.FileItemFactory
;
10 import org
.apache
.commons
.fileupload
.disk
.DiskFileItemFactory
;
11 import org
.apache
.commons
.fileupload
.servlet
.ServletFileUpload
;
12 import org
.argeo
.slc
.core
.build
.ResourceDistribution
;
13 import org
.argeo
.slc
.deploy
.DynamicRuntime
;
14 import org
.argeo
.slc
.deploy
.Module
;
15 import org
.argeo
.slc
.web
.mvc
.AbstractServiceController
;
16 import org
.springframework
.core
.io
.ByteArrayResource
;
17 import org
.springframework
.web
.servlet
.ModelAndView
;
19 public class InstallModule
extends AbstractServiceController
{// extends
20 private DynamicRuntime
<?
> dynamicRuntime
;
22 // Create a factory for disk-based file items
23 private FileItemFactory factory
= new DiskFileItemFactory();
25 // Create a new file upload handler
26 private ServletFileUpload upload
= new ServletFileUpload(factory
);
29 @SuppressWarnings(value
= { "unchecked" })
30 protected void handleServiceRequest(HttpServletRequest request
,
31 HttpServletResponse response
, ModelAndView modelAndView
)
34 List
<FileItem
> items
= upload
.parseRequest(request
);
37 for (FileItem item
: items
) {
38 if (!item
.isFormField()) {
44 ByteArrayResource res
= new ByteArrayResource(arr
);
45 Module module
= dynamicRuntime
.installModule(new ResourceDistribution(
48 // TODO: customize whether the module is started or not
49 dynamicRuntime
.startModule(module
);
52 // protected ModelAndView onSubmit(HttpServletRequest request,
53 // HttpServletResponse response, Object command, BindException errors)
55 // FileUploadBean bean = (FileUploadBean) command;
57 // byte[] file = bean.getFile();
58 // if (file == null) {
59 // throw new SlcException("Upload is empty.");
62 // ByteArrayResource res = new ByteArrayResource(file);
63 // dynamicRuntime.installModule(new ResourceDistribution(res));
65 // return super.onSubmit(request, response, command, errors);
68 // protected void initBinder(HttpServletRequest request,
69 // ServletRequestDataBinder binder) throws ServletException {
70 // // to actually be able to convert Multipart instance to byte[]
71 // // we have to register a custom editor
72 // binder.registerCustomEditor(byte[].class,
73 // new ByteArrayMultipartFileEditor());
74 // // now Spring knows how to handle multipart object and convert them
77 public void setDynamicRuntime(DynamicRuntime
<?
> dynamicRuntime
) {
78 this.dynamicRuntime
= dynamicRuntime
;