|
1 |
| package photospace.web.spring; |
|
2 |
| |
|
3 |
| import java.io.*; |
|
4 |
| import java.util.*; |
|
5 |
| import javax.servlet.http.*; |
|
6 |
| import org.springframework.context.support.*; |
|
7 |
| import org.springframework.web.bind.*; |
|
8 |
| import org.springframework.web.servlet.*; |
|
9 |
| import org.springframework.web.servlet.mvc.multiaction.*; |
|
10 |
| import org.springframework.web.servlet.view.*; |
|
11 |
| import photospace.graphics.*; |
|
12 |
| import photospace.meta.*; |
|
13 |
| import photospace.search.*; |
|
14 |
| import photospace.vfs.*; |
|
15 |
| import photospace.web.*; |
|
16 |
| |
|
17 |
| public class AdminController |
|
18 |
| extends MultiActionController |
|
19 |
| { |
|
20 |
| |
|
21 |
| private Browser browser; |
|
22 |
| private Persister persister; |
|
23 |
| private Indexer indexer; |
|
24 |
| private ImageCache imageCache; |
|
25 |
| private DefaultController controller; |
|
26 |
| |
|
27 |
| private boolean syncing = false; |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
0
| public ModelAndView login(HttpServletRequest request, HttpServletResponse response)
|
|
33 |
| throws Exception |
|
34 |
| { |
|
35 |
0
| return controller.history(request, response);
|
|
36 |
| } |
|
37 |
| |
|
38 |
0
| public ModelAndView delete(HttpServletRequest request, HttpServletResponse response)
|
|
39 |
| throws Exception |
|
40 |
| { |
|
41 |
0
| Meta meta = persister.getMeta(RequestUtils.getRequiredStringParameter(request, "path"));
|
|
42 |
0
| if (meta instanceof FolderMeta)
|
|
43 |
| { |
|
44 |
0
| FolderMeta folder = browser.browse(meta.getPath(), 1);
|
|
45 |
0
| if (folder.getFiles().length != 0)
|
|
46 |
| { |
|
47 |
0
| return controller.error(request, response,
|
|
48 |
| messages().getMessage("error.delete.not-empty", |
|
49 |
| new Object[] { folder.getLabel(), |
|
50 |
| new Integer(folder.getFiles().length) })); |
|
51 |
| } |
|
52 |
| } |
|
53 |
0
| try
|
|
54 |
| { |
|
55 |
0
| persister.remove(meta);
|
|
56 |
| } |
|
57 |
| catch (IOException e) |
|
58 |
| { |
|
59 |
0
| return controller.error(request, response,
|
|
60 |
| messages().getMessage("error.delete.failed", new Object[] { meta.getLabel() })); |
|
61 |
| } |
|
62 |
| |
|
63 |
0
| History history = controller.getHistory(request.getSession());
|
|
64 |
0
| history.goTo(history.getEnd() - 1);
|
|
65 |
| |
|
66 |
0
| return controller.message(request, response,
|
|
67 |
| messages().getMessage("message.delete.success", |
|
68 |
| new Object[] { meta.getLabel() })); |
|
69 |
| } |
|
70 |
| |
|
71 |
0
| public ModelAndView reindex(HttpServletRequest request, HttpServletResponse response)
|
|
72 |
| throws Exception |
|
73 |
| { |
|
74 |
0
| Date start = new Date();
|
|
75 |
0
| int docCount = indexer.index(Arrays.asList(new Meta[] { browser.browse("/", -1) }), true);
|
|
76 |
0
| long duration = new Date().getTime() - start.getTime();
|
|
77 |
0
| request.getSession().setAttribute("message", messages().getMessage("message.index.success", new Object[] { new Integer(docCount),
|
|
78 |
| new Long(duration)})); |
|
79 |
0
| return new ModelAndView(new RedirectView("/doc/index-status.jsp", true));
|
|
80 |
| } |
|
81 |
| |
|
82 |
0
| public ModelAndView cacheImages(HttpServletRequest request, HttpServletResponse response)
|
|
83 |
| throws Exception |
|
84 |
| { |
|
85 |
0
| if (syncing)
|
|
86 |
| { |
|
87 |
0
| request.getSession().setAttribute("error", messages().getMessage("error.cacheImages.inProgress"));
|
|
88 |
0
| return controller.history(request, response);
|
|
89 |
| } |
|
90 |
| |
|
91 |
0
| try
|
|
92 |
| { |
|
93 |
0
| Date start = new Date();
|
|
94 |
0
| int count = imageCache.sync();
|
|
95 |
0
| long duration = new Date().getTime() - start.getTime();
|
|
96 |
0
| request.getSession().setAttribute("message", messages().getMessage("message.cacheImages.success", new Object[] { new Integer(count), new Long(duration)}));
|
|
97 |
| |
|
98 |
0
| return controller.history(request, response);
|
|
99 |
| } |
|
100 |
| finally |
|
101 |
| { |
|
102 |
0
| syncing = false;
|
|
103 |
| } |
|
104 |
| } |
|
105 |
| |
|
106 |
0
| public void setBrowser(Browser browser)
|
|
107 |
| { |
|
108 |
0
| this.browser = browser;
|
|
109 |
| } |
|
110 |
| |
|
111 |
0
| public void setPersister(Persister persister)
|
|
112 |
| { |
|
113 |
0
| this.persister = persister;
|
|
114 |
| } |
|
115 |
| |
|
116 |
0
| public void setIndexer(Indexer indexer)
|
|
117 |
| { |
|
118 |
0
| this.indexer = indexer;
|
|
119 |
| } |
|
120 |
| |
|
121 |
0
| private MessageSourceAccessor messages()
|
|
122 |
| { |
|
123 |
0
| return getMessageSourceAccessor();
|
|
124 |
| } |
|
125 |
| |
|
126 |
0
| public void setController(DefaultController controller)
|
|
127 |
| { |
|
128 |
0
| this.controller = controller;
|
|
129 |
| } |
|
130 |
| |
|
131 |
0
| public void setImageCache(ImageCache imageCache)
|
|
132 |
| { |
|
133 |
0
| this.imageCache = imageCache;
|
|
134 |
| } |
|
135 |
| |
|
136 |
| } |