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 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
public class GetPortletActionsAction |
47 |
|
extends BasePortletAction |
48 |
|
implements AjaxAction, AjaxBuilder, Constants |
49 |
|
{ |
50 |
0 |
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 |
0 |
this(template, errorTemplate, action, decorationValve, null, class="keyword">null); |
61 |
0 |
} |
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 |
0 |
super(template, errorTemplate, pageManager, securityBehavior); |
72 |
0 |
this.action = action; |
73 |
0 |
this.decorationValve = decorationValve; |
74 |
0 |
} |
75 |
|
|
76 |
|
public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException |
77 |
|
{ |
78 |
0 |
return runAction(requestContext, resultMap, true); |
79 |
|
} |
80 |
|
|
81 |
|
public boolean run(RequestContext requestContext, Map resultMap) |
82 |
|
throws AJAXException |
83 |
|
{ |
84 |
0 |
return runAction(requestContext, resultMap, false); |
85 |
|
} |
86 |
|
|
87 |
|
public boolean runAction( RequestContext requestContext, Map resultMap, class="keyword">boolean batch ) |
88 |
|
{ |
89 |
0 |
boolean success = true; |
90 |
0 |
String status = "success"; |
91 |
|
try |
92 |
|
{ |
93 |
0 |
resultMap.put( ACTION, action ); |
94 |
|
|
95 |
0 |
ContentPage page = requestContext.getPage(); |
96 |
|
|
97 |
|
|
98 |
0 |
ArrayList getActionsForFragments = new ArrayList(); |
99 |
0 |
String[] portletIds = requestContext.getRequest().getParameterValues( PORTLETID ); |
100 |
0 |
if ( portletIds != null && portletIds.length > 0 ) |
101 |
|
{ |
102 |
0 |
for ( int i = 0 ; i < portletIds.length ; i++ ) |
103 |
|
{ |
104 |
0 |
String portletId = portletIds[ i ]; |
105 |
0 |
ContentFragment fragment = (ContentFragment)page.getFragmentById( portletId ); |
106 |
0 |
if ( fragment == null ) |
107 |
|
{ |
108 |
0 |
throw new Exception("fragment not found for specified portlet id: " + portletId); |
109 |
|
} |
110 |
0 |
getActionsForFragments.add( fragment ); |
111 |
|
} |
112 |
0 |
getActionsForFragments.add( page.getRootContentFragment() ); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
0 |
decorationValve.initFragments( requestContext, true, getActionsForFragments ); |
117 |
|
|
118 |
0 |
if ( getActionsForFragments.size() > 0 ) |
119 |
|
{ |
120 |
0 |
Fragment rootFragment = (Fragment)getActionsForFragments.remove( getActionsForFragments.size()-1 ); |
121 |
0 |
resultMap.put( PAGE, rootFragment ); |
122 |
|
} |
123 |
|
|
124 |
0 |
resultMap.put( PORTLETS, getActionsForFragments ); |
125 |
|
|
126 |
0 |
resultMap.put( STATUS, status ); |
127 |
|
} |
128 |
0 |
catch (Exception e) |
129 |
|
{ |
130 |
|
|
131 |
0 |
log.error( "exception while getting actions for a fragment", e ); |
132 |
0 |
resultMap.put( REASON, e.toString() ); |
133 |
|
|
134 |
0 |
success = false; |
135 |
0 |
} |
136 |
|
|
137 |
0 |
return success; |
138 |
|
} |
139 |
|
} |