Revision 45135
Added by Claudio Atzori about 7 years ago
ResourceTreeController.java | ||
---|---|---|
34 | 34 |
|
35 | 35 |
/** |
36 | 36 |
* test controller. |
37 |
*
|
|
37 |
* |
|
38 | 38 |
* @author marko |
39 |
* |
|
40 | 39 |
*/ |
41 | 40 |
@Controller |
42 | 41 |
public class ResourceTreeController extends AbstractInspectorController { // NOPMD |
43 | 42 |
|
44 | 43 |
/** |
45 | 44 |
* The list view uses this model to represent a collection |
46 |
*
|
|
45 |
* |
|
47 | 46 |
* @author marko |
48 |
* |
|
49 | 47 |
*/ |
50 | 48 |
public class CollectionModel { |
51 | 49 |
|
... | ... | |
72 | 70 |
|
73 | 71 |
/** |
74 | 72 |
* We want to be able to skip useless collections which have only one child collection etc etc. |
75 |
* |
|
76 | 73 |
* <p> |
74 |
* <p> |
|
77 | 75 |
* This method returns us the deepest path containing only one collection at each level |
78 | 76 |
* </p> |
79 |
*
|
|
77 |
* |
|
80 | 78 |
* @return list of collection names to be displayed in one "row" |
81 | 79 |
*/ |
82 | 80 |
public Collection<CollectionModel> getCollectionPath() { |
... | ... | |
96 | 94 |
|
97 | 95 |
/** |
98 | 96 |
* Uri is computed from relative base path. |
99 |
*
|
|
97 |
* |
|
100 | 98 |
* @return |
101 | 99 |
*/ |
102 | 100 |
public String getUrl() { |
... | ... | |
153 | 151 |
|
154 | 152 |
/** |
155 | 153 |
* handles relative paths. |
156 |
*
|
|
154 |
* |
|
157 | 155 |
* @return redirect |
158 | 156 |
*/ |
159 | 157 |
// @RequestMapping("/inspector/") |
... | ... | |
163 | 161 |
|
164 | 162 |
/** |
165 | 163 |
* handles relative paths. |
166 |
*
|
|
164 |
* |
|
167 | 165 |
* @return redirect |
168 | 166 |
*/ |
169 | 167 |
@RequestMapping("/inspector/index.do") |
... | ... | |
173 | 171 |
|
174 | 172 |
/** |
175 | 173 |
* index. |
176 |
* |
|
177 |
* @param model |
|
178 |
* model |
|
179 |
* @param request |
|
180 |
* http request |
|
181 |
* @throws XMLDBException |
|
182 |
* happens |
|
174 |
* |
|
175 |
* @param model model |
|
176 |
* @param request http request |
|
177 |
* @throws XMLDBException happens |
|
183 | 178 |
*/ |
184 | 179 |
@RequestMapping("/inspector/index.do/**/list") |
185 | 180 |
String list(final Model model, final HttpServletRequest request) throws XMLDBException { |
... | ... | |
213 | 208 |
|
214 | 209 |
/** |
215 | 210 |
* return a list of pairs (name, relative url bases) for each path component. |
216 |
* |
|
217 |
* @param path |
|
218 |
* slash separated path |
|
219 |
* @param base |
|
220 |
* prepend this to all paths |
|
211 |
* |
|
212 |
* @param path slash separated path |
|
213 |
* @param base prepend this to all paths |
|
221 | 214 |
* @return list of path components |
222 | 215 |
*/ |
223 | 216 |
private List<Map<String, String>> extractPathComponents(final String path, final String base) { |
... | ... | |
241 | 234 |
|
242 | 235 |
/** |
243 | 236 |
* show a file. |
244 |
* |
|
245 |
* @param model |
|
246 |
* model |
|
247 |
* @param request |
|
248 |
* request |
|
237 |
* |
|
238 |
* @param model model |
|
239 |
* @param request request |
|
249 | 240 |
* @return view name |
250 |
* @throws XMLDBException |
|
251 |
* happens |
|
241 |
* @throws XMLDBException happens |
|
252 | 242 |
*/ |
253 | 243 |
@RequestMapping("/inspector/index.do/**/show") |
254 | 244 |
String show(final Model model, final HttpServletRequest request) throws XMLDBException { |
... | ... | |
303 | 293 |
|
304 | 294 |
/** |
305 | 295 |
* Show raw profile. |
306 |
* |
|
307 |
* @param model |
|
308 |
* mvc model |
|
309 |
* @param request |
|
310 |
* servlet request |
|
311 |
* @return mvc view |
|
312 |
* @throws XMLDBException |
|
313 |
* could happen |
|
296 |
* |
|
297 |
* @param request servlet request |
|
298 |
* @param response servlet response |
|
299 |
* @throws XMLDBException could happen |
|
314 | 300 |
* @throws IOException |
315 | 301 |
*/ |
316 | 302 |
@RequestMapping("/inspector/index.do/**/raw") |
317 |
void raw(final HttpServletRequest request, final HttpServletResponse response) throws XMLDBException, IOException { |
|
303 |
public void raw(final HttpServletRequest request, final HttpServletResponse response) throws XMLDBException, IOException {
|
|
318 | 304 |
|
319 | 305 |
final String path = request.getPathInfo().replace(INDEX_DO, "").replace("/raw", ""); |
320 | 306 |
// log.info("index: " + path); |
... | ... | |
337 | 323 |
|
338 | 324 |
/** |
339 | 325 |
* show a file editor. |
340 |
* |
|
341 |
* @param model |
|
342 |
* model |
|
343 |
* @param request |
|
344 |
* request |
|
326 |
* |
|
327 |
* @param model model |
|
328 |
* @param request request |
|
345 | 329 |
* @return view name |
346 |
* @throws XMLDBException |
|
347 |
* happens |
|
330 |
* @throws XMLDBException happens |
|
348 | 331 |
*/ |
349 | 332 |
@RequestMapping("/inspector/index.do/**/edit") |
350 |
String edit(final Model model, final HttpServletRequest request) throws XMLDBException { |
|
333 |
public String edit(final Model model, final HttpServletRequest request) throws XMLDBException {
|
|
351 | 334 |
|
352 | 335 |
final String path = request.getPathInfo().replace(INDEX_DO, "").replace("/edit", ""); |
353 | 336 |
|
... | ... | |
368 | 351 |
|
369 | 352 |
/** |
370 | 353 |
* update or create a file. |
371 |
* |
|
372 |
* @param model |
|
373 |
* model |
|
374 |
* @param request |
|
375 |
* request |
|
354 |
* |
|
355 |
* @param model model |
|
356 |
* @param request request |
|
376 | 357 |
* @return view name |
377 |
* @throws XMLDBException |
|
378 |
* happens |
|
358 |
* @throws XMLDBException happens |
|
379 | 359 |
*/ |
380 | 360 |
@RequestMapping("/inspector/index.do/**/save") |
381 |
String save(final Model model, final HttpServletRequest request) throws XMLDBException { |
|
361 |
public String save(final Model model, final HttpServletRequest request) throws XMLDBException {
|
|
382 | 362 |
|
383 | 363 |
final String path = request.getPathInfo().replace(INDEX_DO, "").replace("/save", ""); |
384 | 364 |
|
... | ... | |
400 | 380 |
|
401 | 381 |
/** |
402 | 382 |
* delete a file. |
403 |
* |
|
404 |
* @param model |
|
405 |
* model |
|
406 |
* @param request |
|
407 |
* request |
|
383 |
* |
|
384 |
* @param model model |
|
385 |
* @param request request |
|
408 | 386 |
* @return view name |
409 |
* @throws XMLDBException |
|
410 |
* happens |
|
387 |
* @throws XMLDBException happens |
|
411 | 388 |
*/ |
412 | 389 |
@RequestMapping("/inspector/index.do/**/delete") |
413 |
String delete(final Model model, final HttpServletRequest request) throws XMLDBException { |
|
390 |
public String delete(final Model model, final HttpServletRequest request) throws XMLDBException {
|
|
414 | 391 |
|
415 | 392 |
final String path = request.getPathInfo().replace(INDEX_DO, "").replace("/delete", ""); |
416 | 393 |
|
... | ... | |
426 | 403 |
|
427 | 404 |
/** |
428 | 405 |
* delete a collection. |
429 |
* |
|
430 |
* @param model |
|
431 |
* model |
|
432 |
* @param request |
|
433 |
* request |
|
406 |
* |
|
407 |
* @param model model |
|
408 |
* @param request request |
|
434 | 409 |
* @return view name |
435 |
* @throws XMLDBException |
|
436 |
* happens |
|
410 |
* @throws XMLDBException happens |
|
437 | 411 |
*/ |
438 | 412 |
@RequestMapping("/inspector/index.do/**/deleteCollection") |
439 |
String deleteCollection(final Model model, final HttpServletRequest request) throws XMLDBException { |
|
413 |
public String deleteCollection(final Model model, final HttpServletRequest request) throws XMLDBException {
|
|
440 | 414 |
|
441 | 415 |
final String path = request.getPathInfo().replace(INDEX_DO, "").replace("/deleteCollection", ""); |
442 | 416 |
|
... | ... | |
447 | 421 |
|
448 | 422 |
/** |
449 | 423 |
* present a create form for new subcollection |
450 |
* |
|
451 |
* @param model |
|
452 |
* model |
|
453 |
* @param request |
|
454 |
* request |
|
424 |
* |
|
425 |
* @param model model |
|
426 |
* @param request request |
|
455 | 427 |
* @return view name |
456 |
* @throws XMLDBException |
|
457 |
* happens |
|
428 |
* @throws XMLDBException happens |
|
458 | 429 |
*/ |
459 | 430 |
@RequestMapping("/inspector/index.do/**/createsubcoll") |
460 |
String createSubCollection(final Model model, final HttpServletRequest request) throws XMLDBException { |
|
431 |
public String createSubCollection(final Model model, final HttpServletRequest request) throws XMLDBException {
|
|
461 | 432 |
return "inspector/createsubcoll"; |
462 | 433 |
} |
463 | 434 |
|
464 | 435 |
/** |
465 |
* |
|
466 |
* |
|
467 |
* @param model |
|
468 |
* model |
|
469 |
* @param request |
|
470 |
* request |
|
436 |
* @param request request |
|
471 | 437 |
* @return view name |
472 |
* @throws XMLDBException |
|
473 |
* happens |
|
438 |
* @throws XMLDBException happens |
|
474 | 439 |
*/ |
475 | 440 |
@RequestMapping("/inspector/index.do/**/savesubcoll") |
476 |
String saveSubCollection(final Model model, final HttpServletRequest request, @RequestParam("collectionPath") final String collectionPath)
|
|
441 |
public String saveSubCollection(final HttpServletRequest request, @RequestParam("collectionPath") final String collectionPath)
|
|
477 | 442 |
throws XMLDBException { |
478 | 443 |
final String path = request.getPathInfo().replace(INDEX_DO, "").replace("/savesubcoll", ""); |
479 | 444 |
String fullPath = path + "/" + collectionPath; |
480 | 445 |
log.info("Creating subcollection: " + fullPath); |
481 | 446 |
if (!xmlDatabase.collectionExists(fullPath)) { |
482 |
xmlDatabase.createCollection(fullPath, true);
|
|
447 |
xmlDatabase.createCollection(fullPath); |
|
483 | 448 |
} else { |
484 | 449 |
log.info("Subcollection: " + fullPath + " already exists"); |
485 | 450 |
} |
... | ... | |
488 | 453 |
|
489 | 454 |
/** |
490 | 455 |
* present a create form which will redirect to the edit form. |
491 |
* |
|
492 |
* @param model |
|
493 |
* model |
|
494 |
* @param request |
|
495 |
* request |
|
456 |
* |
|
457 |
* @param model model |
|
458 |
* @param request request |
|
496 | 459 |
* @return view name |
497 |
* @throws XMLDBException |
|
498 |
* happens |
|
460 |
* @throws XMLDBException happens |
|
499 | 461 |
*/ |
500 | 462 |
@RequestMapping("/inspector/index.do/**/create") |
501 |
String create(final Model model, final HttpServletRequest request) throws XMLDBException { |
|
463 |
public String create(final Model model, final HttpServletRequest request) throws XMLDBException {
|
|
502 | 464 |
return "inspector/create"; |
503 | 465 |
} |
504 | 466 |
|
505 | 467 |
/** |
506 | 468 |
* sample controller. |
507 |
* |
|
508 |
* @param model |
|
509 |
* model |
|
469 |
* |
|
470 |
* @param model model |
|
510 | 471 |
*/ |
511 | 472 |
@RequestMapping("/inspector/gadget.do") |
512 |
void gadget(final Model model) { |
|
473 |
public void gadget(final Model model) {
|
|
513 | 474 |
log.info("GADGED CALLED"); |
514 | 475 |
|
515 | 476 |
model.addAttribute("items", new String[] { "one", "two", "three" }); |
Also available in: Unified diff
migrated to dnet45