KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > imagedb > web > ImageController


1 package org.springframework.samples.imagedb.web;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import javax.servlet.http.HttpServletResponse JavaDoc;
5
6 import org.springframework.samples.imagedb.ImageDatabase;
7 import org.springframework.web.multipart.MultipartFile;
8 import org.springframework.web.multipart.MultipartHttpServletRequest;
9 import org.springframework.web.servlet.ModelAndView;
10 import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
11
12 /**
13  * MultiActionController for the image list/upload UI.
14  *
15  * @author Juergen Hoeller
16  * @since 07.01.2004
17  */

18 public class ImageController extends MultiActionController {
19
20     private ImageDatabase imageDatabase;
21
22     public void setImageDatabase(ImageDatabase imageDatabase) {
23         this.imageDatabase = imageDatabase;
24     }
25
26     public ModelAndView showImageList(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
27         return new ModelAndView("imageList", "images", this.imageDatabase.getImages());
28     }
29
30     public ModelAndView streamImageContent(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
31         this.imageDatabase.streamImage(request.getParameter("name"), response.getOutputStream());
32         return null;
33     }
34
35     public ModelAndView processImageUpload(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
36         String JavaDoc name = request.getParameter("name");
37         String JavaDoc description = request.getParameter("description");
38         MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
39         MultipartFile multipartFile = multipartRequest.getFile("image");
40         this.imageDatabase.storeImage(name, multipartFile.getInputStream(), (int) multipartFile.getSize(), description);
41         return new ModelAndView("redirect:imageList");
42     }
43
44     public ModelAndView clearDatabase(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
45         this.imageDatabase.clearDatabase();
46         return new ModelAndView("redirect:imageList");
47     }
48
49 }
50
Popular Tags