001: package org.sakaiproject.site.tool.helper.order.rsf;
002:
003: import org.sakaiproject.exception.IdUnusedException;
004: import org.sakaiproject.exception.PermissionException;
005: import org.sakaiproject.site.api.Site;
006: import org.sakaiproject.site.api.SitePage;
007: import org.sakaiproject.site.api.ToolConfiguration;
008: import org.sakaiproject.site.tool.helper.order.impl.SitePageEditHandler;
009:
010: import uk.org.ponder.messageutil.MessageLocator;
011: import uk.org.ponder.rsf.components.UIBranchContainer;
012: import uk.org.ponder.rsf.components.UIContainer;
013: import uk.org.ponder.rsf.components.UIOutput;
014: import uk.org.ponder.rsf.view.ComponentChecker;
015: import uk.org.ponder.rsf.view.ViewComponentProducer;
016: import uk.org.ponder.rsf.viewstate.ViewParameters;
017: import uk.org.ponder.rsf.viewstate.ViewParamsReporter;
018:
019: /**
020: *
021: * @author Joshua Ryan joshua.ryan@asu.edu
022: *
023: */
024: public class PageEditProducer implements ViewComponentProducer,
025: ViewParamsReporter {
026:
027: public SitePageEditHandler handler;
028: public static final String VIEW_ID = "PageEdit";
029: public MessageLocator messageLocator;
030:
031: public String getViewID() {
032: return VIEW_ID;
033: }
034:
035: public void fillComponents(UIContainer arg0, ViewParameters arg1,
036: ComponentChecker arg2) {
037: PageEditViewParameters params = null;
038:
039: String pageId = null;
040: String newTitle = null;
041: String visible = null;
042: String newConfig = null;
043:
044: UIBranchContainer mode = null;
045:
046: try {
047: params = (PageEditViewParameters) arg1;
048: pageId = params.pageId;
049: newTitle = params.newTitle;
050: visible = params.visible;
051: newConfig = params.newConfig;
052: } catch (Exception e) {
053: e.printStackTrace();
054: mode = UIBranchContainer.make(arg0, "mode-failed:");
055: UIOutput.make(mode, "message", e.getLocalizedMessage());
056: return;
057: }
058:
059: if (!"nil".equals(pageId)) {
060: if (!"nil".equals(newTitle)) {
061: if (newTitle != null && !"".equals(newTitle)) {
062: try {
063: Site site = handler.site;
064: SitePage page = site.getPage(pageId);
065: String oldTitle = page.getTitle();
066: page.setTitle(newTitle);
067:
068: // TODO: Find a way to call each tool to ask what fields they need configured
069: // and what methods to use to validate the input..
070: if (page.getTools().size() == 1
071: && !"nil".equals(newConfig)) {
072: ToolConfiguration tool = (ToolConfiguration) page
073: .getTools().get(0);
074: if ("sakai.iframe".equals(tool.getToolId())) {
075: tool.getPlacementConfig().setProperty(
076: "source", newConfig);
077:
078: }
079: }
080:
081: handler.saveSite(site);
082: mode = UIBranchContainer.make(arg0,
083: "mode-pass:");
084: UIOutput.make(mode, "page-title", newTitle);
085: UIOutput.make(mode, "message", oldTitle
086: + " "
087: + messageLocator
088: .getMessage("success_changed")
089: + " " + newTitle);
090:
091: } catch (IdUnusedException e) {
092: mode = UIBranchContainer.make(arg0,
093: "mode-failed:");
094: UIOutput.make(mode, "message", e
095: .getLocalizedMessage());
096: e.printStackTrace();
097: } catch (PermissionException e) {
098: mode = UIBranchContainer.make(arg0,
099: "mode-failed:");
100: UIOutput.make(mode, "message", e
101: .getLocalizedMessage());
102: e.printStackTrace();
103: }
104: } else {
105: mode = UIBranchContainer.make(arg0, "mode-failed:");
106: UIOutput.make(mode, "message", messageLocator
107: .getMessage("error_title_null"));
108: }
109: }
110:
111: if ("true".equals(visible) || "false".equals(visible)) {
112: try {
113: if ("true".equals(visible)) {
114: handler.showPage(pageId);
115: } else {
116: handler.hidePage(pageId);
117: }
118: Site site = handler.site;
119: SitePage page = site.getPage(pageId);
120: String oldTitle = page.getTitle();
121:
122: mode = UIBranchContainer.make(arg0, "mode-pass:");
123: UIOutput.make(mode, "page-title", oldTitle);
124: if ("true".equals(visible)) {
125: UIOutput.make(mode, "message", oldTitle
126: + " "
127: + messageLocator
128: .getMessage("success_visible"));
129: } else {
130: UIOutput.make(mode, "message", oldTitle
131: + " "
132: + messageLocator
133: .getMessage("success_hidden"));
134: }
135: } catch (IdUnusedException e) {
136: mode = UIBranchContainer.make(arg0, "mode-failed:");
137: UIOutput.make(mode, "message", e
138: .getLocalizedMessage());
139: e.printStackTrace();
140: } catch (PermissionException e) {
141: mode = UIBranchContainer.make(arg0, "mode-failed:");
142: UIOutput.make(mode, "message", e
143: .getLocalizedMessage());
144: e.printStackTrace();
145: }
146: }
147: } else {
148: UIOutput.make(mode, "message", messageLocator
149: .getMessage("error_pageid"));
150: }
151: }
152:
153: public ViewParameters getViewParameters() {
154: PageEditViewParameters params = new PageEditViewParameters();
155:
156: //Bet you can't guess what my first language was? ;-)
157: params.pageId = "nil";
158: params.newTitle = "nil";
159: params.newConfig = "nil";
160: return params;
161: }
162:
163: }
|