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.Iterator; |
20 |
|
import java.util.List; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import org.apache.commons.logging.Log; |
24 |
|
import org.apache.commons.logging.LogFactory; |
25 |
|
import org.apache.jetspeed.ajax.AJAXException; |
26 |
|
import org.apache.jetspeed.ajax.AjaxAction; |
27 |
|
import org.apache.jetspeed.ajax.AjaxBuilder; |
28 |
|
import org.apache.jetspeed.layout.PortletActionSecurityBehavior; |
29 |
|
import org.apache.jetspeed.om.page.Fragment; |
30 |
|
import org.apache.jetspeed.om.page.Page; |
31 |
|
import org.apache.jetspeed.page.PageManager; |
32 |
|
import org.apache.jetspeed.request.RequestContext; |
33 |
|
import org.apache.jetspeed.security.UserManager; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
public abstract class BaseUserAction |
44 |
|
implements AjaxAction, AjaxBuilder, Constants |
45 |
|
{ |
46 |
0 |
protected Log log = LogFactory.getLog(BaseUserAction.class); |
47 |
0 |
protected String template = null; |
48 |
0 |
protected UserManager userManager = null; |
49 |
0 |
protected String errorTemplate = null; |
50 |
|
protected RolesSecurityBehavior securityBehavior; |
51 |
|
|
52 |
|
public BaseUserAction(String template, |
53 |
|
String errorTemplate, |
54 |
|
RolesSecurityBehavior securityBehavior) |
55 |
0 |
{ |
56 |
0 |
this.template = template; |
57 |
0 |
this.errorTemplate = errorTemplate; |
58 |
0 |
this.securityBehavior = securityBehavior; |
59 |
0 |
} |
60 |
|
|
61 |
|
public BaseUserAction(String template, |
62 |
|
String errorTemplate, |
63 |
|
UserManager userManager) |
64 |
0 |
{ |
65 |
0 |
this.template = template; |
66 |
0 |
this.errorTemplate = errorTemplate; |
67 |
0 |
this.userManager = userManager; |
68 |
0 |
this.securityBehavior = null; |
69 |
0 |
} |
70 |
|
|
71 |
|
public BaseUserAction(String template, |
72 |
|
String errorTemplate, |
73 |
|
UserManager userManager, |
74 |
|
RolesSecurityBehavior securityBehavior) |
75 |
|
{ |
76 |
0 |
this(template, errorTemplate, securityBehavior); |
77 |
0 |
this.userManager = userManager; |
78 |
0 |
} |
79 |
|
|
80 |
|
public boolean buildContext(RequestContext requestContext, Map responseContext) |
81 |
|
{ |
82 |
0 |
return true; |
83 |
|
} |
84 |
|
|
85 |
|
public boolean buildErrorContext(RequestContext requestContext, |
86 |
|
Map responseContext) |
87 |
|
{ |
88 |
0 |
responseContext.put(STATUS, "failure"); |
89 |
|
|
90 |
|
|
91 |
0 |
if (responseContext.get(ACTION) == null) |
92 |
|
{ |
93 |
0 |
responseContext.put(ACTION, "unknown"); |
94 |
|
} |
95 |
|
|
96 |
0 |
if (responseContext.get(PORTLETID) == null) |
97 |
|
{ |
98 |
0 |
responseContext.put(PORTLETID, "unknown"); |
99 |
|
} |
100 |
|
|
101 |
0 |
return true; |
102 |
|
} |
103 |
|
|
104 |
|
public String getErrorTemplate() |
105 |
|
{ |
106 |
0 |
return errorTemplate; |
107 |
|
} |
108 |
|
|
109 |
|
public String getTemplate() |
110 |
|
{ |
111 |
0 |
return template; |
112 |
|
} |
113 |
|
|
114 |
|
public boolean checkAccess(RequestContext context, String action) |
115 |
|
{ |
116 |
0 |
boolean access = true; |
117 |
0 |
if (null != securityBehavior) |
118 |
|
{ |
119 |
0 |
access = securityBehavior.checkAccess(context, action); |
120 |
|
} |
121 |
0 |
return access; |
122 |
|
} |
123 |
|
|
124 |
|
public boolean createNewPageOnEdit(RequestContext context) |
125 |
|
{ |
126 |
0 |
if (securityBehavior == null) |
127 |
0 |
return false; |
128 |
|
|
129 |
0 |
return securityBehavior.createNewPageOnEdit(context); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
public Fragment getFragmentIdFromLocation(int row, class="keyword">int column, Page page) |
134 |
|
{ |
135 |
0 |
Fragment root = page.getRootFragment(); |
136 |
0 |
Iterator fragments = root.getFragments().iterator(); |
137 |
0 |
while (fragments.hasNext()) |
138 |
|
{ |
139 |
0 |
Fragment fragment = (Fragment)fragments.next(); |
140 |
0 |
if (fragment.getLayoutColumn() == column && |
141 |
|
fragment.getLayoutRow() == row) |
142 |
|
{ |
143 |
0 |
return fragment; |
144 |
|
} |
145 |
0 |
} |
146 |
0 |
return null; |
147 |
|
} |
148 |
|
|
149 |
|
public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException |
150 |
|
{ |
151 |
0 |
return run(requestContext, resultMap); |
152 |
|
} |
153 |
|
|
154 |
|
public String getActionParameter(RequestContext requestContext, String name) |
155 |
|
{ |
156 |
0 |
String parameter = requestContext.getRequestParameter(name); |
157 |
0 |
if (parameter == null) |
158 |
|
{ |
159 |
0 |
Object o = requestContext.getAttribute(name); |
160 |
0 |
if (o != null) |
161 |
|
{ |
162 |
0 |
if (o instanceof String) |
163 |
0 |
return (String)o; |
164 |
|
} |
165 |
|
} |
166 |
0 |
return parameter; |
167 |
|
} |
168 |
|
|
169 |
|
public Fragment getParentFragmentById(String id, Fragment root) |
170 |
|
{ |
171 |
0 |
if ( id == null ) |
172 |
|
{ |
173 |
0 |
return null; |
174 |
|
} |
175 |
0 |
return searchForParentFragmentById( id, root ); |
176 |
|
} |
177 |
|
|
178 |
|
protected Fragment searchForParentFragmentById( String id, Fragment parent ) |
179 |
|
{ |
180 |
|
|
181 |
0 |
Fragment matchedParent = null; |
182 |
0 |
if( parent != null ) |
183 |
|
{ |
184 |
|
|
185 |
0 |
List children = parent.getFragments(); |
186 |
0 |
for( int i = 0, cSize = children.size() ; i < cSize ; i++) |
187 |
|
{ |
188 |
0 |
Fragment childFrag = (Fragment)children.get( i ); |
189 |
0 |
if ( childFrag != null ) |
190 |
|
{ |
191 |
0 |
if ( id.equals( childFrag.getId() ) ) |
192 |
|
{ |
193 |
0 |
matchedParent = parent; |
194 |
0 |
break; |
195 |
|
} |
196 |
|
else |
197 |
|
{ |
198 |
0 |
matchedParent = searchForParentFragmentById( id, childFrag ); |
199 |
0 |
if ( matchedParent != null ) |
200 |
|
{ |
201 |
0 |
break; |
202 |
|
} |
203 |
|
} |
204 |
|
} |
205 |
|
} |
206 |
|
} |
207 |
0 |
return matchedParent; |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
public boolean isTrue(String parameter) |
219 |
|
{ |
220 |
0 |
boolean isTrue = false; |
221 |
0 |
if(parameter != null) |
222 |
|
{ |
223 |
0 |
if(parameter.equalsIgnoreCase("true")) |
224 |
|
{ |
225 |
0 |
isTrue = true; |
226 |
|
} |
227 |
|
} |
228 |
0 |
return isTrue; |
229 |
|
} |
230 |
|
|
231 |
|
} |