001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.decoration;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.Locale;
024: import java.util.MissingResourceException;
025: import java.util.ResourceBundle;
026:
027: import javax.portlet.PortletMode;
028: import javax.portlet.WindowState;
029:
030: import org.apache.jetspeed.JetspeedActions;
031: import org.apache.jetspeed.container.url.PortalURL;
032: import org.apache.jetspeed.om.common.portlet.PortletApplication;
033: import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
034: import org.apache.jetspeed.om.page.ContentFragment;
035: import org.apache.jetspeed.request.RequestContext;
036: import org.apache.jetspeed.security.SecurityAccessController;
037: import org.apache.pluto.om.window.PortletWindow;
038:
039: public abstract class AbstractDecoratorActionsFactory implements
040: DecoratorActionsFactory {
041: private static ThreadLocal actionResourcesMap = new ThreadLocal();
042: private boolean editMaximizesOption = false;
043: private boolean configMaximizesOption = false;
044: private boolean editDefaultsMaximizesOption = false;
045:
046: /**
047: * When Edit is clicked, also maximize the window state
048: *
049: * @param editMaxOption
050: */
051: public AbstractDecoratorActionsFactory() {
052: }
053:
054: public List getDecoratorActions(RequestContext rc,
055: PortletApplication pa, PortletWindow pw, PortletMode pm,
056: WindowState ws, Decoration decoration,
057: List actionTemplates, PortletDefinitionComposite portlet,
058: ContentFragment fragment,
059: SecurityAccessController accessController) {
060: DecoratorAction action;
061: boolean checkConstraints = false;
062: ArrayList actions = new ArrayList();
063:
064: Iterator iter = actionTemplates.iterator();
065: while (iter.hasNext()) {
066: checkConstraints = false;
067: DecoratorActionTemplate template = (DecoratorActionTemplate) iter
068: .next();
069: //checking the constraints only on EDIT and HELP Action, as VIEW will taken care with portlet view.
070: if (template.getAction().equals(JetspeedActions.EDIT)
071: || template.getAction()
072: .equals(JetspeedActions.HELP))
073: checkConstraints = true;
074: if (checkConstraints
075: && checkSecurityConstraint(portlet, fragment,
076: accessController, template.getAction())) {
077: action = createAction(rc, pw, decoration, template);
078: if (action != null) {
079: actions.add(action);
080: }
081: } else if (!checkConstraints) {
082: action = createAction(rc, pw, decoration, template);
083: if (action != null) {
084: actions.add(action);
085: }
086: }
087: }
088: return actions;
089: }
090:
091: public List getDecoratorActions(RequestContext rc,
092: PortletApplication pa, PortletWindow pw, PortletMode pm,
093: WindowState ws, Decoration decoration, List actionTemplates) {
094: DecoratorAction action;
095: ArrayList actions = new ArrayList();
096: Iterator iter = actionTemplates.iterator();
097: while (iter.hasNext()) {
098: action = createAction(rc, pw, decoration,
099: (DecoratorActionTemplate) iter.next());
100: if (action != null) {
101: actions.add(action);
102: }
103: }
104: return actions;
105: }
106:
107: protected DecoratorAction createAction(RequestContext rc,
108: PortletWindow pw, Decoration decoration,
109: DecoratorActionTemplate template) {
110: String actionName = template.getAction();
111:
112: PortalURL portalURL = rc.getPortalURL();
113: Boolean isAjaxRequest = (Boolean) rc
114: .getAttribute(DecorationValve.IS_AJAX_DECORATION_REQUEST);
115:
116: WindowState ws;
117: PortletMode pm;
118: if (editMaximizesOption || configMaximizesOption
119: || editDefaultsMaximizesOption) {
120: if (editMaximizesOption
121: && template.getAction()
122: .equals(JetspeedActions.EDIT)) {
123: ws = WindowState.MAXIMIZED;
124: pm = template.getCustomMode();
125: } else if (configMaximizesOption
126: && template.getAction().equals(
127: JetspeedActions.CONFIG)) {
128: ws = WindowState.MAXIMIZED;
129: pm = template.getCustomMode();
130: } else if (editDefaultsMaximizesOption
131: && template.getAction().equals(
132: JetspeedActions.EDIT_DEFAULTS)) {
133: ws = WindowState.MAXIMIZED;
134: pm = template.getCustomMode();
135: } else if (template.getAction()
136: .equals(JetspeedActions.VIEW)) {
137: ws = WindowState.NORMAL;
138: pm = template.getCustomMode();
139: } else if (template.getAction().equals(
140: JetspeedActions.NORMAL)) {
141: pm = PortletMode.VIEW;
142: ws = template.getCustomState();
143: } else {
144: ws = template.getCustomState();
145: pm = template.getCustomMode();
146: }
147: } else {
148: ws = template.getCustomState();
149: pm = template.getCustomMode();
150: }
151: /////////////////////////////////////
152:
153: String actionURL = rc.getResponse().encodeURL(
154: (isAjaxRequest == null) ? portalURL.createPortletURL(
155: pw, pm, ws, portalURL.isSecure()).toString()
156: : portalURL.createNavigationalEncoding(pw, pm,
157: ws));
158:
159: String linkURL = decoration.getResource("images/" + actionName
160: + ".gif");
161:
162: boolean customAction = (template.getMode() != null && !template
163: .getMode().equals(template.getCustomMode()))
164: || (template.getState() != null && !template.getState()
165: .equals(template.getCustomState()));
166:
167: HashMap resourcesMap = (HashMap) actionResourcesMap.get();
168: ResourceBundle bundle = DecoratorAction.getResourceBundle(rc
169: .getLocale());
170: String localizedName = null;
171:
172: if (resourcesMap == null) {
173: resourcesMap = new HashMap();
174: actionResourcesMap.set(resourcesMap);
175: resourcesMap.put(DecoratorAction.RESOURCE_BUNDLE, bundle);
176: localizedName = DecoratorAction.getResourceString(bundle,
177: actionName, actionName);
178: resourcesMap.put(actionName, localizedName);
179: } else {
180: localizedName = (String) resourcesMap.get(actionName);
181: if (localizedName == null) {
182: localizedName = DecoratorAction.getResourceString(
183: bundle, actionName, actionName);
184: resourcesMap.put(actionName, localizedName);
185: }
186: }
187: return new DecoratorAction(actionName, localizedName,
188: localizedName, linkURL, actionURL, customAction,
189: template.getActionType());
190: }
191:
192: //added for checkin the constraints on actions
193: protected boolean checkSecurityConstraint(
194: PortletDefinitionComposite portlet,
195: ContentFragment fragment,
196: SecurityAccessController accessController, String action) {
197: if (fragment.getType().equals(ContentFragment.PORTLET)) {
198: if (accessController != null) {
199: return accessController.checkPortletAccess(portlet,
200: JetspeedActions.getContainerActionMask(action));
201: }
202: }
203: return true;
204: }
205:
206: public void setMaximizeOnEdit(boolean maxOnEdit) {
207: this .editMaximizesOption = maxOnEdit;
208: }
209:
210: public boolean getMaximizeOnEdit() {
211: return this .editMaximizesOption;
212: }
213:
214: public void setMaximizeOnConfig(boolean maxOnConfig) {
215: this .configMaximizesOption = maxOnConfig;
216: }
217:
218: public boolean getMaximizeOnConfig() {
219: return this .configMaximizesOption;
220: }
221:
222: public void setMaximizeOnEditDefaults(boolean maxOnEditDefaults) {
223: this .editDefaultsMaximizesOption = maxOnEditDefaults;
224: }
225:
226: public boolean getMaximizeOnEditDefaults() {
227: return this.editDefaultsMaximizesOption;
228: }
229: }
|