01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/tool-lib/src/java/org/theospi/portfolio/style/tool/PublishStyleController.java $
03: * $Id:PublishStyleController.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.style.tool;
21:
22: import java.util.Map;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.sakaiproject.metaobj.shared.model.Id;
27: import org.sakaiproject.metaobj.shared.model.PersistenceException;
28: import org.sakaiproject.metaobj.utils.mvc.intf.LoadObjectController;
29: import org.sakaiproject.tool.cover.ToolManager;
30: import org.springframework.validation.Errors;
31: import org.springframework.web.servlet.ModelAndView;
32: import org.theospi.portfolio.style.StyleFunctionConstants;
33: import org.theospi.portfolio.style.model.Style;
34:
35: public class PublishStyleController extends ListStyleController
36: implements LoadObjectController {
37: protected final Log logger = LogFactory.getLog(getClass());
38:
39: public ModelAndView handleRequest(Object requestModel, Map request,
40: Map session, Map application, Errors errors) {
41: //Style style = (Style) requestModel;
42: Id styleId = getIdManager().getId(
43: (String) request.get("style_id"));
44: Style style = getStyleManager().getStyle(styleId);
45:
46: String publishTo = (String) request.get("publishTo");
47: if (publishTo.equals("global")) {
48: style.setGlobalState(Style.STATE_PUBLISHED);
49: style.setSiteId(ToolManager.getCurrentPlacement()
50: .getContext());
51: doSave(style, StyleFunctionConstants.GLOBAL_PUBLISH_STYLE,
52: errors);
53: } else {
54: style.setGlobalState(Style.STATE_WAITING_APPROVAL);
55: doSave(
56: style,
57: StyleFunctionConstants.SUGGEST_GLOBAL_PUBLISH_STYLE,
58: errors);
59: }
60:
61: request.put("newStyleId", style.getId().getValue());
62:
63: return super .handleRequest(requestModel, request, session,
64: application, errors);
65: }
66:
67: protected void doSave(Style style, String function, Errors errors) {
68: checkPermission(function);
69: try {
70: //Don't need to check authz for saving as we should already have perms via the publish
71: getStyleManager().storeStyle(style, false);
72: } catch (PersistenceException e) {
73: errors.rejectValue(e.getField(), e.getErrorCode(), e
74: .getErrorInfo(), e.getDefaultMessage());
75: }
76: }
77:
78: public Object fillBackingObject(Object incomingModel, Map request,
79: Map session, Map application) throws Exception {
80: //Style style = (Style) incomingModel;
81: Id styleId = getIdManager().getId(
82: (String) request.get("style_id"));
83: /*
84: String publishTo = (String)request.get("publishTo");
85: String function = "";
86: if (publishTo.equals("global")) {
87: function = StyleFunctionConstants.GLOBAL_PUBLISH_STYLE;
88: }
89: else if (publishTo.equals("site")){
90: function = StyleFunctionConstants.PUBLISH_STYLE;
91: }
92: else {
93: function = StyleFunctionConstants.SUGGEST_GLOBAL_PUBLISH_STYLE;
94: }
95: getAuthzManager().checkPermission(function, styleId);
96: */
97: return getStyleManager().getStyle(styleId);
98: }
99: }
|