1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.velocity; |
18 |
|
|
19 |
|
import java.io.IOException; |
20 |
|
import java.io.PrintWriter; |
21 |
|
import java.io.Writer; |
22 |
|
import java.security.Principal; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.HashSet; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Locale; |
27 |
|
import java.util.Set; |
28 |
|
|
29 |
|
import javax.portlet.PortletConfig; |
30 |
|
import javax.portlet.PortletMode; |
31 |
|
import javax.portlet.RenderRequest; |
32 |
|
import javax.portlet.RenderResponse; |
33 |
|
import javax.portlet.WindowState; |
34 |
|
import javax.security.auth.Subject; |
35 |
|
import javax.servlet.http.HttpServletRequest; |
36 |
|
|
37 |
|
import org.apache.commons.configuration.Configuration; |
38 |
|
import org.apache.commons.configuration.PropertiesConfiguration; |
39 |
|
import org.apache.commons.logging.Log; |
40 |
|
import org.apache.commons.logging.LogFactory; |
41 |
|
import org.apache.jetspeed.Jetspeed; |
42 |
|
import org.apache.jetspeed.PortalReservedParameters; |
43 |
|
import org.apache.jetspeed.aggregator.PortletRenderer; |
44 |
|
import org.apache.jetspeed.aggregator.impl.PortletAggregatorFragmentImpl; |
45 |
|
import org.apache.jetspeed.capabilities.CapabilityMap; |
46 |
|
import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent; |
47 |
|
import org.apache.jetspeed.components.portletentity.PortletEntityNotGeneratedException; |
48 |
|
import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException; |
49 |
|
import org.apache.jetspeed.container.state.NavigationalState; |
50 |
|
import org.apache.jetspeed.container.url.BasePortalURL; |
51 |
|
import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow; |
52 |
|
import org.apache.jetspeed.container.window.PortletWindowAccessor; |
53 |
|
import org.apache.jetspeed.locator.LocatorDescriptor; |
54 |
|
import org.apache.jetspeed.locator.TemplateDescriptor; |
55 |
|
import org.apache.jetspeed.locator.TemplateLocator; |
56 |
|
import org.apache.jetspeed.locator.TemplateLocatorException; |
57 |
|
import org.apache.jetspeed.om.page.ContentFragment; |
58 |
|
import org.apache.jetspeed.om.page.ContentFragmentImpl; |
59 |
|
import org.apache.jetspeed.om.page.Fragment; |
60 |
|
import org.apache.jetspeed.om.page.Page; |
61 |
|
import org.apache.jetspeed.request.RequestContext; |
62 |
|
import org.apache.jetspeed.services.title.DynamicTitleService; |
63 |
|
import org.apache.jetspeed.util.ArgUtil; |
64 |
|
import org.apache.jetspeed.util.Path; |
65 |
|
import org.apache.pluto.om.entity.PortletEntity; |
66 |
|
import org.apache.velocity.context.Context; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
public class JetspeedPowerToolImpl implements JetspeedVelocityPowerTool |
89 |
|
{ |
90 |
|
|
91 |
|
private static final String DECORATOR_ID_ATTR = "decoratorId"; |
92 |
|
|
93 |
|
private static final String ACTION_IMAGE_EXTENSION_ATTR = "actionImageExtension"; |
94 |
|
|
95 |
|
protected static final String PORTLET_CONFIG_ATTR = "javax.portlet.config"; |
96 |
|
|
97 |
|
protected static final String RENDER_RESPONSE_ATTR = "javax.portlet.response"; |
98 |
|
|
99 |
|
protected static final String RENDER_REQUEST_ATTR = "javax.portlet.request"; |
100 |
|
|
101 |
|
protected static final String COLUMNS_ATTR = "columns"; |
102 |
|
|
103 |
|
protected static final String COLUMN_SIZES = "columnSizes"; |
104 |
|
|
105 |
|
protected RenderRequest renderRequest; |
106 |
|
|
107 |
|
protected RenderResponse renderResponse; |
108 |
|
|
109 |
|
protected PortletConfig portletConfig; |
110 |
|
|
111 |
|
protected Writer templateWriter; |
112 |
|
|
113 |
0 |
protected static final Log log = LogFactory.getLog(JetspeedPowerToolImpl.class); |
114 |
|
|
115 |
|
protected CapabilityMap capabilityMap; |
116 |
|
|
117 |
|
protected Locale locale; |
118 |
|
|
119 |
|
protected LocatorDescriptor templateLocatorDescriptor; |
120 |
|
|
121 |
|
protected TemplateLocator templateLocator; |
122 |
|
|
123 |
|
protected PortletEntityAccessComponent entityAccess; |
124 |
|
|
125 |
|
protected TemplateLocator decorationLocator; |
126 |
|
|
127 |
|
protected LocatorDescriptor decorationLocatorDescriptor; |
128 |
|
|
129 |
|
protected PortletWindowAccessor windowAccess; |
130 |
|
|
131 |
|
protected RequestContext requestContext; |
132 |
|
|
133 |
|
protected Context velocityContext; |
134 |
|
|
135 |
|
private DynamicTitleService titleService; |
136 |
|
|
137 |
|
private BasePortalURL baseUrlAccess; |
138 |
|
|
139 |
|
private PortletRenderer renderer; |
140 |
|
|
141 |
|
public JetspeedPowerToolImpl(RequestContext requestContext, DynamicTitleService titleService,PortletRenderer renderer) throws Exception |
142 |
0 |
{ |
143 |
0 |
HttpServletRequest request = requestContext.getRequest(); |
144 |
0 |
this.requestContext = requestContext; |
145 |
0 |
this.titleService = titleService; |
146 |
0 |
windowAccess = (PortletWindowAccessor) getComponent(PortletWindowAccessor.class.getName()); |
147 |
0 |
entityAccess = (PortletEntityAccessComponent) getComponent(PortletEntityAccessComponent.class.getName()); |
148 |
|
try |
149 |
|
{ |
150 |
0 |
baseUrlAccess = (BasePortalURL) getComponent("BasePortalURL"); |
151 |
|
} |
152 |
0 |
catch (Exception e) |
153 |
|
{ |
154 |
|
|
155 |
0 |
} |
156 |
|
|
157 |
0 |
renderRequest = (RenderRequest) request.getAttribute(RENDER_REQUEST_ATTR); |
158 |
0 |
renderResponse = (RenderResponse) request.getAttribute(RENDER_RESPONSE_ATTR); |
159 |
0 |
portletConfig = (PortletConfig) request.getAttribute(PORTLET_CONFIG_ATTR); |
160 |
|
|
161 |
|
|
162 |
0 |
templateLocator = (TemplateLocator) getComponent("TemplateLocator"); |
163 |
0 |
decorationLocator = (TemplateLocator) getComponent("DecorationLocator"); |
164 |
|
|
165 |
0 |
capabilityMap = requestContext.getCapabilityMap(); |
166 |
0 |
locale = requestContext.getLocale(); |
167 |
|
|
168 |
0 |
templateLocatorDescriptor = templateLocator.createLocatorDescriptor(null); |
169 |
0 |
templateLocatorDescriptor.setMediaType(capabilityMap.getPreferredMediaType().getName()); |
170 |
0 |
templateLocatorDescriptor.setCountry(locale.getCountry()); |
171 |
0 |
templateLocatorDescriptor.setLanguage(locale.getLanguage()); |
172 |
|
|
173 |
0 |
decorationLocatorDescriptor = decorationLocator.createLocatorDescriptor(null); |
174 |
0 |
decorationLocatorDescriptor.setMediaType(capabilityMap.getPreferredMediaType().getName()); |
175 |
0 |
decorationLocatorDescriptor.setCountry(locale.getCountry()); |
176 |
0 |
decorationLocatorDescriptor.setLanguage(locale.getLanguage()); |
177 |
|
|
178 |
0 |
this.renderer = renderer; |
179 |
0 |
} |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
protected final RequestContext getRequestContext() |
189 |
|
{ |
190 |
0 |
return requestContext; |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
public WindowState getWindowState() throws Exception |
200 |
|
{ |
201 |
|
try |
202 |
|
{ |
203 |
0 |
NavigationalState nav = getRequestContext().getPortalURL().getNavigationalState(); |
204 |
0 |
return nav.getState(windowAccess.getPortletWindow(getCurrentFragment())); |
205 |
|
} |
206 |
0 |
catch (Exception e) |
207 |
|
{ |
208 |
0 |
handleError(e, e.toString(), getCurrentFragment()); |
209 |
0 |
return null; |
210 |
|
} |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
public WindowState getMappedWindowState() throws Exception |
220 |
|
{ |
221 |
|
try |
222 |
|
{ |
223 |
0 |
NavigationalState nav = getRequestContext().getPortalURL().getNavigationalState(); |
224 |
0 |
return nav.getMappedState(windowAccess.getPortletWindow(getCurrentFragment())); |
225 |
|
} |
226 |
0 |
catch (Exception e) |
227 |
|
{ |
228 |
0 |
handleError(e, e.toString(), getCurrentFragment()); |
229 |
0 |
return null; |
230 |
|
} |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
public PortletMode getPortletMode() throws Exception |
240 |
|
{ |
241 |
|
|
242 |
0 |
NavigationalState nav = getRequestContext().getPortalURL().getNavigationalState(); |
243 |
|
try |
244 |
|
{ |
245 |
0 |
return nav.getMode(windowAccess.getPortletWindow(getCurrentFragment())); |
246 |
|
} |
247 |
0 |
catch (FailedToRetrievePortletWindow e) |
248 |
|
{ |
249 |
0 |
handleError(e, e.toString(), getCurrentFragment()); |
250 |
0 |
return null; |
251 |
|
} |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
public PortletMode getMappedPortletMode() throws Exception |
261 |
|
{ |
262 |
|
|
263 |
0 |
NavigationalState nav = getRequestContext().getPortalURL().getNavigationalState(); |
264 |
|
try |
265 |
|
{ |
266 |
0 |
return nav.getMappedMode(windowAccess.getPortletWindow(getCurrentFragment())); |
267 |
|
} |
268 |
0 |
catch (FailedToRetrievePortletWindow e) |
269 |
|
{ |
270 |
0 |
handleError(e, e.toString(), getCurrentFragment()); |
271 |
0 |
return null; |
272 |
|
} |
273 |
|
} |
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
public ContentFragment getCurrentFragment() |
280 |
|
{ |
281 |
0 |
checkState(); |
282 |
0 |
return (ContentFragment) renderRequest.getAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE); |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
public void setCurrentFragment(ContentFragment f) |
290 |
|
{ |
291 |
0 |
checkState(); |
292 |
0 |
setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, f); |
293 |
|
|
294 |
0 |
} |
295 |
|
|
296 |
|
public void setCurrentLayout() |
297 |
|
{ |
298 |
0 |
checkState(); |
299 |
|
|
300 |
0 |
ContentFragment f = (ContentFragment) getRequestContext().getRequest().getAttribute(LAYOUT_ATTR); |
301 |
0 |
setAttribute(LAYOUT_ATTR, f); |
302 |
0 |
} |
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
public ContentFragment getCurrentLayout() |
309 |
|
{ |
310 |
0 |
checkState(); |
311 |
0 |
return (ContentFragment) renderRequest.getAttribute(LAYOUT_ATTR); |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
public Page getPage() |
319 |
|
{ |
320 |
0 |
checkState(); |
321 |
|
|
322 |
|
|
323 |
0 |
return requestContext.getPage(); |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
public List[] getColumns() |
331 |
|
{ |
332 |
0 |
checkState(); |
333 |
0 |
return (List[]) renderRequest.getAttribute(COLUMNS_ATTR); |
334 |
|
} |
335 |
|
|
336 |
|
public List getColumnSizes() |
337 |
|
{ |
338 |
0 |
checkState(); |
339 |
0 |
Object o = renderRequest.getAttribute(COLUMN_SIZES); |
340 |
0 |
if (o == null) |
341 |
0 |
return null; |
342 |
0 |
return (List) renderRequest.getAttribute(COLUMN_SIZES); |
343 |
|
} |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
public PortletEntity getCurrentPortletEntity() throws Exception |
351 |
|
{ |
352 |
|
try |
353 |
|
{ |
354 |
0 |
return windowAccess.getPortletWindow(getCurrentFragment()).getPortletEntity(); |
355 |
|
} |
356 |
0 |
catch (Exception e) |
357 |
|
{ |
358 |
0 |
handleError(e, "JetspeedPowerTool failed to retreive the current PortletEntity. " + e.toString(), |
359 |
|
getCurrentFragment()); |
360 |
0 |
return null; |
361 |
|
} |
362 |
|
} |
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
public PortletEntity getPortletEntity(ContentFragment f) throws Exception |
373 |
|
{ |
374 |
0 |
PortletEntity portletEntity = windowAccess.getPortletWindow(f).getPortletEntity(); |
375 |
|
|
376 |
0 |
if (portletEntity == null) |
377 |
|
{ |
378 |
|
try |
379 |
|
{ |
380 |
0 |
portletEntity = entityAccess.generateEntityFromFragment(f); |
381 |
0 |
entityAccess.storePortletEntity(portletEntity); |
382 |
|
} |
383 |
0 |
catch (PortletEntityNotGeneratedException e) |
384 |
|
{ |
385 |
0 |
String msg = "JetspeedPowerTool failed to retreive a PortletEntity for Fragment " + f.getId() + ". " |
386 |
|
+ e.toString(); |
387 |
0 |
handleError(e, msg, f); |
388 |
|
} |
389 |
0 |
catch (PortletEntityNotStoredException e) |
390 |
|
{ |
391 |
0 |
String msg = "JetspeedPowerTool failed to store a PortletEntity for Fragment " + f.getId() + ". " |
392 |
|
+ e.toString(); |
393 |
0 |
handleError(e, msg, f); |
394 |
0 |
} |
395 |
|
} |
396 |
0 |
return portletEntity; |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
public boolean isHidden(ContentFragment f) |
409 |
|
{ |
410 |
0 |
checkState(); |
411 |
0 |
if (f == null) |
412 |
|
{ |
413 |
0 |
throw new IllegalArgumentException("Fragment cannot be null for isHidden(Fragment)"); |
414 |
|
} |
415 |
0 |
return f.getState() != null && f.getState().equals(HIDDEN); |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
435 |
|
public TemplateDescriptor getTemplate(String path, String templateType) throws TemplateLocatorException |
436 |
|
{ |
437 |
0 |
checkState(); |
438 |
0 |
return getTemplate(path, templateType, templateLocator, templateLocatorDescriptor); |
439 |
|
} |
440 |
|
|
441 |
|
public Configuration getTypeConfiguration(String type, String name, String location) throws Exception |
442 |
|
{ |
443 |
0 |
ArgUtil.assertNotNull(String.class, type, this, "getTypeConfiguration(String type, String name)"); |
444 |
0 |
ArgUtil.assertNotNull(String.class, name, this, "getTypeConfiguration(String type, String name)"); |
445 |
|
try |
446 |
|
{ |
447 |
0 |
TemplateDescriptor locator = null; |
448 |
0 |
if (location.equals("templates")) |
449 |
|
{ |
450 |
0 |
locator = getTemplate(name + "/" + type + ".properties", type); |
451 |
|
} |
452 |
0 |
else if (location.equals("decorations")) |
453 |
|
{ |
454 |
0 |
locator = getDecoration(name + "/decorator.properties", type); |
455 |
|
} |
456 |
|
else |
457 |
|
{ |
458 |
0 |
throw new IllegalArgumentException("Location type " + location |
459 |
|
+ " is not supported by getTypeConfiguration()."); |
460 |
|
} |
461 |
0 |
return new PropertiesConfiguration(locator.getAbsolutePath()); |
462 |
|
} |
463 |
0 |
catch (TemplateLocatorException e) |
464 |
|
{ |
465 |
0 |
log.warn(e.toString(), e); |
466 |
0 |
return null; |
467 |
|
} |
468 |
|
} |
469 |
|
|
470 |
|
public TemplateDescriptor getDecoration(String path, String templateType) throws TemplateLocatorException |
471 |
|
{ |
472 |
0 |
checkState(); |
473 |
0 |
return getTemplate(path, templateType, decorationLocator, decorationLocatorDescriptor); |
474 |
|
} |
475 |
|
|
476 |
|
public String includeTemplate(String template, String templateType) throws IOException |
477 |
|
{ |
478 |
0 |
checkState(); |
479 |
|
try |
480 |
|
{ |
481 |
0 |
TemplateDescriptor useLocator = getTemplate(template, templateType); |
482 |
0 |
return useLocator.getAppRelativePath(); |
483 |
|
} |
484 |
0 |
catch (Exception e) |
485 |
|
{ |
486 |
0 |
PrintWriter directError = new PrintWriter(renderResponse.getWriter()); |
487 |
0 |
directError.write("Error occured process includeTemplate(): " + e.toString() + "\n\n"); |
488 |
0 |
e.printStackTrace(directError); |
489 |
0 |
directError.close(); |
490 |
0 |
return null; |
491 |
|
} |
492 |
|
} |
493 |
|
|
494 |
|
public String includeDecoration(String template, String templateType) throws IOException |
495 |
|
{ |
496 |
0 |
checkState(); |
497 |
|
try |
498 |
|
{ |
499 |
0 |
return getDecoration(template, templateType).getAppRelativePath(); |
500 |
|
} |
501 |
0 |
catch (Exception e) |
502 |
|
{ |
503 |
0 |
PrintWriter directError = new PrintWriter(renderResponse.getWriter()); |
504 |
0 |
directError.write("Error occured process includeDecoration(): " + e.toString() + "\n\n"); |
505 |
0 |
e.printStackTrace(directError); |
506 |
0 |
directError.close(); |
507 |
0 |
return null; |
508 |
|
} |
509 |
|
} |
510 |
|
|
511 |
|
|
512 |
|
|
513 |
|
|
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
public String decorateAndInclude(ContentFragment f) throws Exception |
522 |
|
{ |
523 |
|
|
524 |
|
|
525 |
|
|
526 |
0 |
setCurrentFragment(f); |
527 |
0 |
setCurrentLayout(); |
528 |
|
|
529 |
|
|
530 |
|
try |
531 |
|
{ |
532 |
0 |
return decorateAndIncludePortlet(f); |
533 |
|
} |
534 |
0 |
catch (Exception e) |
535 |
|
{ |
536 |
0 |
renderResponse.getWriter().write(e.toString()); |
537 |
0 |
return null; |
538 |
|
} |
539 |
|
|
540 |
|
} |
541 |
|
|
542 |
|
|
543 |
|
|
544 |
|
|
545 |
|
|
546 |
|
|
547 |
|
|
548 |
|
|
549 |
|
|
550 |
|
|
551 |
|
|
552 |
|
|
553 |
|
|
554 |
|
|
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
|
560 |
|
|
561 |
|
|
562 |
|
|
563 |
|
|
564 |
|
|
565 |
|
|
566 |
|
|
567 |
|
|
568 |
|
|
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
protected String decorateAndIncludePortlet(ContentFragment f) throws Exception |
573 |
|
{ |
574 |
|
|
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
0 |
String fragmentType = f.getType(); |
580 |
0 |
String decorator = f.getDecorator(); |
581 |
0 |
if (decorator == null) |
582 |
|
{ |
583 |
0 |
decorator = getPage().getEffectiveDefaultDecorator(fragmentType); |
584 |
|
} |
585 |
|
|
586 |
|
|
587 |
0 |
TemplateDescriptor propsTemp = getTemplate(decorator + "/" + DECORATOR_TYPE + ".properties", fragmentType, |
588 |
|
decorationLocator, decorationLocatorDescriptor); |
589 |
0 |
if (propsTemp == null) |
590 |
|
{ |
591 |
0 |
fragmentType = GENERIC_TEMPLATE_TYPE; |
592 |
0 |
propsTemp = getTemplate(decorator + "/" + DECORATOR_TYPE + ".properties", fragmentType, decorationLocator, |
593 |
|
decorationLocatorDescriptor); |
594 |
|
} |
595 |
|
|
596 |
|
|
597 |
0 |
Configuration decoConf = new PropertiesConfiguration(propsTemp.getAbsolutePath()); |
598 |
0 |
String ext = decoConf.getString("template.extension"); |
599 |
0 |
String decoratorPath = decorator + "/" + DECORATOR_TYPE + ext; |
600 |
0 |
TemplateDescriptor template = null; |
601 |
|
try |
602 |
|
{ |
603 |
0 |
template = getDecoration(decoratorPath, fragmentType); |
604 |
|
} |
605 |
0 |
catch (TemplateLocatorException e) |
606 |
|
{ |
607 |
0 |
String parent = decoConf.getString("extends"); |
608 |
0 |
if (parent != null) |
609 |
|
{ |
610 |
0 |
template = getDecoration(parent + "/" + DECORATOR_TYPE + ext, fragmentType); |
611 |
|
} |
612 |
0 |
} |
613 |
|
|
614 |
0 |
setAttribute(DECORATOR_ID_ATTR, decoConf.getString("id")); |
615 |
0 |
setAttribute(ACTION_IMAGE_EXTENSION_ATTR, decoConf.getString("action.image.extension", ".gif")); |
616 |
0 |
return template.getAppRelativePath(); |
617 |
|
} |
618 |
|
|
619 |
|
|
620 |
|
|
621 |
|
|
622 |
|
|
623 |
|
|
624 |
|
|
625 |
|
|
626 |
|
|
627 |
|
protected void checkState() |
628 |
|
{ |
629 |
0 |
if (portletConfig == null || renderRequest == class="keyword">null || renderResponse == class="keyword">null) |
630 |
|
{ |
631 |
0 |
throw new IllegalStateException("JetspeedPowerTool has not been properly initialized. " + "" |
632 |
|
+ "The JetspeedPowerTool generally only usuable during the rendering phase of " |
633 |
|
+ "internal portlet applications."); |
634 |
|
} |
635 |
0 |
} |
636 |
|
|
637 |
|
protected TemplateDescriptor getTemplate(String path, String templateType, TemplateLocator locator, |
638 |
|
LocatorDescriptor descriptor) throws TemplateLocatorException |
639 |
|
{ |
640 |
0 |
checkState(); |
641 |
0 |
if (templateType == null) |
642 |
|
{ |
643 |
0 |
templateType = GENERIC_TEMPLATE_TYPE; |
644 |
|
} |
645 |
|
try |
646 |
|
{ |
647 |
|
|
648 |
0 |
descriptor.setName(path); |
649 |
0 |
descriptor.setType(templateType); |
650 |
|
|
651 |
0 |
TemplateDescriptor template = locator.locateTemplate(descriptor); |
652 |
|
|
653 |
0 |
if (template == null) |
654 |
|
{ |
655 |
0 |
Path pathObject = new Path(path); |
656 |
0 |
if (pathObject.length() > 1) |
657 |
|
{ |
658 |
0 |
template = getTemplate(pathObject.getSegment(1).toString(), templateType, locator, descriptor); |
659 |
|
} |
660 |
|
} |
661 |
0 |
return template; |
662 |
|
} |
663 |
0 |
catch (TemplateLocatorException e) |
664 |
|
{ |
665 |
0 |
log.error("Unable to locate template: " + path, e); |
666 |
|
|
667 |
0 |
throw e; |
668 |
|
} |
669 |
|
} |
670 |
|
|
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
|
protected void handleError(Exception e, String msg, ContentFragment fragment) |
680 |
|
{ |
681 |
0 |
log.error(msg, e); |
682 |
|
|
683 |
0 |
Set exceptions = (Set) renderRequest.getAttribute(FRAGMENT_PROCESSING_ERROR_PREFIX + fragment.getId()); |
684 |
0 |
if (exceptions == null) |
685 |
|
{ |
686 |
0 |
exceptions = new HashSet(); |
687 |
0 |
setAttribute(FRAGMENT_PROCESSING_ERROR_PREFIX + fragment.getId(), exceptions); |
688 |
|
} |
689 |
0 |
exceptions.add(e); |
690 |
|
|
691 |
0 |
} |
692 |
|
|
693 |
|
|
694 |
|
|
695 |
|
|
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|
public List getDecoratorActions() |
703 |
|
{ |
704 |
0 |
return getCurrentFragment().getDecoration().getActions(); |
705 |
|
} |
706 |
|
|
707 |
|
|
708 |
|
|
709 |
|
|
710 |
|
|
711 |
|
|
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
|
716 |
|
public List getPageDecoratorActions() throws Exception |
717 |
|
{ |
718 |
0 |
return getCurrentFragment().getDecoration().getActions(); |
719 |
|
} |
720 |
|
|
721 |
|
|
722 |
|
|
723 |
|
|
724 |
|
|
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
|
731 |
|
public String getTitle(PortletEntity entity, ContentFragment f) |
732 |
|
{ |
733 |
0 |
String title = null; |
734 |
|
|
735 |
0 |
if (f != null) |
736 |
|
{ |
737 |
0 |
title = f.getTitle(); |
738 |
|
} |
739 |
|
|
740 |
0 |
if (title == null) |
741 |
|
{ |
742 |
|
try |
743 |
|
{ |
744 |
|
|
745 |
0 |
return titleService.getDynamicTitle(windowAccess.getPortletWindow(f), getRequestContext().getRequest()); |
746 |
|
} |
747 |
0 |
catch (Exception e) |
748 |
|
{ |
749 |
0 |
log.error("Unable to reteive portlet title: " + e.getMessage(), e); |
750 |
0 |
return "Title Error: " + e.getMessage(); |
751 |
|
} |
752 |
|
} |
753 |
|
|
754 |
0 |
return title; |
755 |
|
} |
756 |
|
|
757 |
|
|
758 |
|
|
759 |
|
|
760 |
|
|
761 |
|
|
762 |
|
|
763 |
|
|
764 |
|
|
765 |
|
|
766 |
|
|
767 |
|
public String getTitle(PortletEntity entity) |
768 |
|
{ |
769 |
|
try |
770 |
|
{ |
771 |
0 |
return titleService.getDynamicTitle(windowAccess.getPortletWindow(getCurrentFragment()), |
772 |
|
getRequestContext().getRequest()); |
773 |
|
} |
774 |
0 |
catch (Exception e) |
775 |
|
{ |
776 |
0 |
log.error("Unable to reteive portlet title: " + e.getMessage(), e); |
777 |
0 |
return "Title Error: " + e.getMessage(); |
778 |
|
} |
779 |
|
|
780 |
|
} |
781 |
|
|
782 |
|
public Object getComponent(String name) |
783 |
|
{ |
784 |
0 |
return Jetspeed.getComponentManager().getComponent(name); |
785 |
|
} |
786 |
|
|
787 |
|
public String getAbsoluteUrl(String relativePath) |
788 |
|
{ |
789 |
|
|
790 |
0 |
if (relativePath != null && relativePath.indexOf("://") == -1 && relativePath.indexOf("mailto:") == -1) |
791 |
|
{ |
792 |
0 |
HttpServletRequest request = getRequestContext().getRequest(); |
793 |
0 |
StringBuffer path = new StringBuffer(); |
794 |
0 |
if ( !getRequestContext().getPortalURL().isRelativeOnly() ) |
795 |
|
{ |
796 |
0 |
if (this.baseUrlAccess == null) |
797 |
|
{ |
798 |
0 |
path.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getServerPort()); |
799 |
|
} |
800 |
|
else |
801 |
|
{ |
802 |
0 |
path.append(baseUrlAccess.getServerScheme()).append("://").append(baseUrlAccess.getServerName()).append(":").append(baseUrlAccess.getServerPort()); |
803 |
|
} |
804 |
|
} |
805 |
0 |
return renderResponse.encodeURL(path.append(request.getContextPath()).append(request.getServletPath()).append(relativePath).toString()); |
806 |
|
|
807 |
|
} |
808 |
|
else |
809 |
|
{ |
810 |
0 |
return relativePath; |
811 |
|
} |
812 |
|
} |
813 |
|
|
814 |
|
public Subject getSubject() |
815 |
|
{ |
816 |
0 |
return requestContext.getSubject(); |
817 |
|
} |
818 |
|
|
819 |
|
public boolean getLoggedOn() |
820 |
|
{ |
821 |
0 |
Principal principal = requestContext.getRequest().getUserPrincipal(); |
822 |
0 |
return (principal != null); |
823 |
|
} |
824 |
|
|
825 |
|
public String getBasePath() |
826 |
|
{ |
827 |
0 |
return getRequestContext().getPortalURL().getBasePath(); |
828 |
|
} |
829 |
|
|
830 |
|
public String getPageBasePath() |
831 |
|
{ |
832 |
0 |
return getRequestContext().getPortalURL().getPageBasePath(); |
833 |
|
} |
834 |
|
|
835 |
|
public void setVelocityContext(Context velocityContext) |
836 |
|
{ |
837 |
0 |
this.velocityContext = velocityContext; |
838 |
0 |
} |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
|
843 |
|
|
844 |
|
|
845 |
|
|
846 |
|
|
847 |
|
|
848 |
|
|
849 |
|
|
850 |
|
|
851 |
|
protected void setAttribute(String name, Object object) |
852 |
|
{ |
853 |
0 |
renderRequest.setAttribute(name, object); |
854 |
0 |
if (velocityContext != null) |
855 |
|
{ |
856 |
0 |
velocityContext.put(name, object); |
857 |
|
} |
858 |
0 |
} |
859 |
|
|
860 |
|
public String renderPortletEntity(String entityId, String portletId) |
861 |
|
{ |
862 |
|
|
863 |
0 |
RequestContext context = getRequestContext(); |
864 |
|
|
865 |
0 |
PortletAggregatorFragmentImpl fragment = new PortletAggregatorFragmentImpl( |
866 |
|
entityId); |
867 |
0 |
fragment.setType(Fragment.PORTLET); |
868 |
0 |
fragment.setName(portletId); |
869 |
0 |
ContentFragment contentFragment = new ContentFragmentImpl(fragment, class="keyword">new HashMap(), true); |
870 |
0 |
renderer.renderNow(contentFragment, context); |
871 |
0 |
return contentFragment.getRenderedContent(); |
872 |
|
} |
873 |
|
|
874 |
|
} |