01: package org.sakaiproject.site.tool.helper.order.rsf;
02:
03: import org.sakaiproject.exception.IdUnusedException;
04: import org.sakaiproject.exception.PermissionException;
05: import org.sakaiproject.site.api.Site;
06: import org.sakaiproject.site.api.SitePage;
07: import org.sakaiproject.site.tool.helper.order.impl.SitePageEditHandler;
08:
09: import uk.org.ponder.messageutil.MessageLocator;
10: import uk.org.ponder.rsf.components.UIBranchContainer;
11: import uk.org.ponder.rsf.components.UIContainer;
12: import uk.org.ponder.rsf.components.UIOutput;
13: import uk.org.ponder.rsf.view.ComponentChecker;
14: import uk.org.ponder.rsf.view.ViewComponentProducer;
15: import uk.org.ponder.rsf.viewstate.ViewParameters;
16: import uk.org.ponder.rsf.viewstate.ViewParamsReporter;
17:
18: /**
19: *
20: * @author Joshua Ryan joshua.ryan@asu.edu
21: *
22: */
23: public class PageDelProducer implements ViewComponentProducer,
24: ViewParamsReporter {
25:
26: public static final String VIEW_ID = "PageDel";
27: public MessageLocator messageLocator;
28: public SitePageEditHandler handler;
29:
30: public String getViewID() {
31: return VIEW_ID;
32: }
33:
34: public void fillComponents(UIContainer arg0, ViewParameters arg1,
35: ComponentChecker arg2) {
36: PageEditViewParameters params = null;
37:
38: String pageId = null;
39:
40: UIBranchContainer mode = null;
41:
42: try {
43: params = (PageEditViewParameters) arg1;
44: pageId = params.pageId;
45:
46: } catch (Exception e) {
47: e.printStackTrace();
48: mode = UIBranchContainer.make(arg0, "mode-failed:");
49: UIOutput.make(mode, "message", e.getLocalizedMessage());
50: return;
51: }
52:
53: if ("nil".equals(pageId)) {
54: mode = UIBranchContainer.make(arg0, "mode-failed:");
55: UIOutput.make(mode, "message", messageLocator
56: .getMessage("error_pageid"));
57: } else {
58: try {
59: Site site = handler.site;
60: SitePage page = site.getPage(pageId);
61: String title = page.getTitle();
62: site.removePage(page);
63: handler.saveSite(site);
64: mode = UIBranchContainer.make(arg0, "mode-pass:");
65: UIOutput.make(mode, "pageId", pageId);
66: UIOutput.make(mode, "message", title + " "
67: + messageLocator.getMessage("success_removed"));
68:
69: } catch (IdUnusedException e) {
70: mode = UIBranchContainer.make(arg0, "mode-failed:");
71: UIOutput.make(mode, "message", e.getLocalizedMessage());
72: e.printStackTrace();
73: } catch (PermissionException e) {
74: mode = UIBranchContainer.make(arg0, "mode-failed:");
75: UIOutput.make(mode, "message", e.getLocalizedMessage());
76: e.printStackTrace();
77: }
78: }
79: }
80:
81: public ViewParameters getViewParameters() {
82: PageEditViewParameters params = new PageEditViewParameters();
83: params.pageId = "nil";
84: return params;
85: }
86: }
|