1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.layout.impl;
1819import java.util.ArrayList;
20import java.util.Map;
2122import org.apache.commons.logging.Log;
23import org.apache.commons.logging.LogFactory;
24import org.apache.jetspeed.ajax.AJAXException;
25import org.apache.jetspeed.ajax.AjaxAction;
26import org.apache.jetspeed.ajax.AjaxBuilder;
27import org.apache.jetspeed.decoration.DecorationValve;
28import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
29import org.apache.jetspeed.om.page.ContentFragment;
30import org.apache.jetspeed.om.page.ContentPage;
31import org.apache.jetspeed.om.page.Fragment;
32import org.apache.jetspeed.page.PageManager;
33import org.apache.jetspeed.request.RequestContext;
3435/***36 * Get Portlet Actions retrieves the current set of valid actions for one or more portlet windows37 *38 * AJAX Parameters: 39 * id = the fragment id of the portlet for which to retrieve the action list40 * multiple id parameters are supported41 * page = (implied in the URL)42 * 43 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>44 * @version $Id: $45 */46publicclassGetPortletActionsAction47extendsBasePortletAction48 implements AjaxAction, AjaxBuilder, Constants49 {
50protectedstaticfinal Log log = LogFactory.getLog(GetPortletActionsAction.class);
51protected String action;
52privateDecorationValve decorationValve;
5354publicGetPortletActionsAction(String template,
55 String errorTemplate,
56 String action,
57DecorationValve decorationValve)
58 throws AJAXException
59 {
60this(template, errorTemplate, action, decorationValve, null, null);
61 }
6263publicGetPortletActionsAction(String template,
64 String errorTemplate,
65 String action,
66DecorationValve decorationValve,
67 PageManager pageManager,
68 PortletActionSecurityBehavior securityBehavior)
69 throws AJAXException
70 {
71super(template, errorTemplate, pageManager, securityBehavior);
72this.action = action;
73this.decorationValve = decorationValve;
74 }
7576publicboolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException
77 {
78return runAction(requestContext, resultMap, true);
79 }
8081publicboolean run(RequestContext requestContext, Map resultMap)
82 throws AJAXException
83 {
84return runAction(requestContext, resultMap, false);
85 }
8687publicboolean runAction( RequestContext requestContext, Map resultMap, boolean batch )
88 {
89boolean success = true;
90 String status = "success";
91try92 {
93 resultMap.put( ACTION, action );
9495 ContentPage page = requestContext.getPage();
9697// Get the necessary parameters off of the request98 ArrayList getActionsForFragments = new ArrayList();
99 String[] portletIds = requestContext.getRequest().getParameterValues( PORTLETID );
100if ( portletIds != null && portletIds.length > 0 )
101 {
102for ( int i = 0 ; i < portletIds.length ; i++ )
103 {
104 String portletId = portletIds[ i ];
105 ContentFragment fragment = (ContentFragment)page.getFragmentById( portletId );
106if ( fragment == null )
107 {
108thrownew Exception("fragment not found for specified portlet id: " + portletId);
109 }
110 getActionsForFragments.add( fragment );
111 }
112 getActionsForFragments.add( page.getRootContentFragment() );
113 }
114115// Run the Decoration valve to get actions116 decorationValve.initFragments( requestContext, true, getActionsForFragments );
117118if ( getActionsForFragments.size() > 0 )
119 {
120 Fragment rootFragment = (Fragment)getActionsForFragments.remove( getActionsForFragments.size()-1 );
121 resultMap.put( PAGE, rootFragment );
122 }
123124 resultMap.put( PORTLETS, getActionsForFragments );
125126 resultMap.put( STATUS, status );
127 }
128catch (Exception e)
129 {
130// Log the exception131 log.error( "exception while getting actions for a fragment", e );
132 resultMap.put( REASON, e.toString() );
133// Return a failure indicator134 success = false;
135 }
136137return success;
138 }
139 }