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