1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.layout.impl;
18
19 import java.util.ArrayList;
20 import java.util.Map;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.jetspeed.ajax.AJAXException;
25 import org.apache.jetspeed.ajax.AjaxAction;
26 import org.apache.jetspeed.ajax.AjaxBuilder;
27 import org.apache.jetspeed.decoration.DecorationValve;
28 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
29 import org.apache.jetspeed.om.page.ContentFragment;
30 import org.apache.jetspeed.om.page.ContentPage;
31 import org.apache.jetspeed.om.page.Fragment;
32 import org.apache.jetspeed.page.PageManager;
33 import org.apache.jetspeed.request.RequestContext;
34
35 /***
36 * Get Portlet Actions retrieves the current set of valid actions for one or more portlet windows
37 *
38 * AJAX Parameters:
39 * id = the fragment id of the portlet for which to retrieve the action list
40 * multiple id parameters are supported
41 * page = (implied in the URL)
42 *
43 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
44 * @version $Id: $
45 */
46 public class GetPortletActionsAction
47 extends BasePortletAction
48 implements AjaxAction, AjaxBuilder, Constants
49 {
50 protected static final Log log = LogFactory.getLog(GetPortletActionsAction.class);
51 protected String action;
52 private DecorationValve decorationValve;
53
54 public GetPortletActionsAction(String template,
55 String errorTemplate,
56 String action,
57 DecorationValve decorationValve)
58 throws AJAXException
59 {
60 this(template, errorTemplate, action, decorationValve, null, null);
61 }
62
63 public GetPortletActionsAction(String template,
64 String errorTemplate,
65 String action,
66 DecorationValve decorationValve,
67 PageManager pageManager,
68 PortletActionSecurityBehavior securityBehavior)
69 throws AJAXException
70 {
71 super(template, errorTemplate, pageManager, securityBehavior);
72 this.action = action;
73 this.decorationValve = decorationValve;
74 }
75
76 public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException
77 {
78 return runAction(requestContext, resultMap, true);
79 }
80
81 public boolean run(RequestContext requestContext, Map resultMap)
82 throws AJAXException
83 {
84 return runAction(requestContext, resultMap, false);
85 }
86
87 public boolean runAction( RequestContext requestContext, Map resultMap, boolean batch )
88 {
89 boolean success = true;
90 String status = "success";
91 try
92 {
93 resultMap.put( ACTION, action );
94
95 ContentPage page = requestContext.getPage();
96
97
98 ArrayList getActionsForFragments = new ArrayList();
99 String[] portletIds = requestContext.getRequest().getParameterValues( PORTLETID );
100 if ( portletIds != null && portletIds.length > 0 )
101 {
102 for ( int i = 0 ; i < portletIds.length ; i++ )
103 {
104 String portletId = portletIds[ i ];
105 ContentFragment fragment = (ContentFragment)page.getFragmentById( portletId );
106 if ( fragment == null )
107 {
108 throw new Exception("fragment not found for specified portlet id: " + portletId);
109 }
110 getActionsForFragments.add( fragment );
111 }
112 getActionsForFragments.add( page.getRootContentFragment() );
113 }
114
115
116 decorationValve.initFragments( requestContext, true, getActionsForFragments );
117
118 if ( getActionsForFragments.size() > 0 )
119 {
120 Fragment rootFragment = (Fragment)getActionsForFragments.remove( getActionsForFragments.size()-1 );
121 resultMap.put( PAGE, rootFragment );
122 }
123
124 resultMap.put( PORTLETS, getActionsForFragments );
125
126 resultMap.put( STATUS, status );
127 }
128 catch (Exception e)
129 {
130
131 log.error( "exception while getting actions for a fragment", e );
132 resultMap.put( REASON, e.toString() );
133
134 success = false;
135 }
136
137 return success;
138 }
139 }