1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.portlets.layout; |
18 |
|
|
19 |
|
import java.io.IOException; |
20 |
|
import java.util.HashMap; |
21 |
|
import java.util.Locale; |
22 |
|
import java.util.Map; |
23 |
|
import java.util.StringTokenizer; |
24 |
|
|
25 |
|
import javax.portlet.ActionRequest; |
26 |
|
import javax.portlet.ActionResponse; |
27 |
|
import javax.portlet.PortletConfig; |
28 |
|
import javax.portlet.PortletException; |
29 |
|
import javax.portlet.PortletPreferences; |
30 |
|
import javax.portlet.RenderRequest; |
31 |
|
import javax.portlet.RenderResponse; |
32 |
|
|
33 |
|
import org.apache.commons.configuration.Configuration; |
34 |
|
import org.apache.commons.configuration.ConfigurationException; |
35 |
|
import org.apache.commons.configuration.PropertiesConfiguration; |
36 |
|
import org.apache.commons.logging.Log; |
37 |
|
import org.apache.commons.logging.LogFactory; |
38 |
|
import org.apache.jetspeed.CommonPortletServices; |
39 |
|
import org.apache.jetspeed.JetspeedActions; |
40 |
|
import org.apache.jetspeed.PortalReservedParameters; |
41 |
|
import org.apache.jetspeed.capabilities.CapabilityMap; |
42 |
|
import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent; |
43 |
|
import org.apache.jetspeed.components.portletregistry.PortletRegistry; |
44 |
|
import org.apache.jetspeed.container.window.PortletWindowAccessor; |
45 |
|
import org.apache.jetspeed.layout.JetspeedPowerTool; |
46 |
|
import org.apache.jetspeed.locator.LocatorDescriptor; |
47 |
|
import org.apache.jetspeed.locator.TemplateDescriptor; |
48 |
|
import org.apache.jetspeed.locator.TemplateLocator; |
49 |
|
import org.apache.jetspeed.locator.TemplateLocatorException; |
50 |
|
import org.apache.jetspeed.om.page.Fragment; |
51 |
|
import org.apache.jetspeed.om.page.Page; |
52 |
|
import org.apache.jetspeed.page.PageManager; |
53 |
|
import org.apache.jetspeed.request.RequestContext; |
54 |
|
import org.apache.jetspeed.velocity.JetspeedPowerToolFactory; |
55 |
|
import org.apache.pluto.om.window.PortletWindow; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
0 |
public class LayoutPortlet extends org.apache.portals.bridges.common.GenericServletPortlet |
60 |
|
{ |
61 |
|
public static final String GENERIC_TEMPLATE_TYPE = "generic"; |
62 |
|
|
63 |
|
public static final String FRAGMENT_PROCESSING_ERROR_PREFIX = "fragment.processing.error."; |
64 |
|
|
65 |
|
public static final String FRAGMENT_ATTR = "fragment"; |
66 |
|
|
67 |
|
public static final String LAYOUT_ATTR = "layout"; |
68 |
|
|
69 |
|
public static final String HIDDEN = "hidden"; |
70 |
|
|
71 |
|
public static final String LAYOUT_TEMPLATE_TYPE = "layout"; |
72 |
|
|
73 |
|
public static final String DECORATOR_TYPE = "decorator"; |
74 |
|
|
75 |
|
public static final String PARAM_SOLO_PAGE = "SoloPage"; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
0 |
protected final static Log log = LogFactory.getLog(LayoutPortlet.class); |
80 |
|
|
81 |
|
protected PortletRegistry registry; |
82 |
|
protected PageManager pageManager; |
83 |
|
protected JetspeedPowerToolFactory jptFactory; |
84 |
|
protected TemplateLocator templateLocator; |
85 |
|
protected PortletEntityAccessComponent entityAccess; |
86 |
|
protected PortletWindowAccessor windowAccess; |
87 |
|
protected TemplateLocator decorationLocator; |
88 |
|
|
89 |
|
|
90 |
0 |
private Map layoutTemplateProperties = new HashMap(); |
91 |
|
public static final String DEFAULT_TEMPLATE_EXT = ".vm"; |
92 |
|
public static final String TEMPLATE_EXTENSION_KEY = "template.extension"; |
93 |
|
public static final String DEFAULT_TEMPLATE_TYPE = "velocity"; |
94 |
|
public static final String TEMPLATE_TYPE_KEY = "template.type"; |
95 |
|
|
96 |
|
|
97 |
|
public void init( PortletConfig config ) throws PortletException |
98 |
|
{ |
99 |
0 |
super.init(config); |
100 |
|
|
101 |
0 |
registry = (PortletRegistry)getPortletContext().getAttribute(CommonPortletServices.CPS_REGISTRY_COMPONENT); |
102 |
0 |
if (null == registry) |
103 |
|
{ |
104 |
0 |
throw new PortletException("Failed to find the Portlet Registry on portlet initialization"); |
105 |
|
} |
106 |
0 |
pageManager = (PageManager)getPortletContext().getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT); |
107 |
0 |
if (null == pageManager) |
108 |
|
{ |
109 |
0 |
throw new PortletException("Failed to find the Page Manager on portlet initialization"); |
110 |
|
} |
111 |
0 |
jptFactory = (JetspeedPowerToolFactory)getPortletContext().getAttribute(CommonPortletServices.CPS_JETSPEED_POWERTOOL_FACTORY); |
112 |
0 |
if (null == jptFactory) |
113 |
|
{ |
114 |
0 |
throw new PortletException("Failed to find the JPT Factory on portlet initialization"); |
115 |
|
} |
116 |
|
|
117 |
0 |
entityAccess = (PortletEntityAccessComponent) getPortletContext().getAttribute(CommonPortletServices.CPS_ENTITY_ACCESS_COMPONENT); |
118 |
0 |
if (null == entityAccess) |
119 |
|
{ |
120 |
0 |
throw new PortletException("Failed to find the Entity Access on portlet initialization"); |
121 |
|
} |
122 |
|
|
123 |
0 |
windowAccess = (PortletWindowAccessor) getPortletContext().getAttribute(CommonPortletServices.CPS_WINDOW_ACCESS_COMPONENT); |
124 |
0 |
if (null == windowAccess) |
125 |
|
{ |
126 |
0 |
throw new PortletException("Failed to find the Window Access on portlet initialization"); |
127 |
|
} |
128 |
|
|
129 |
0 |
templateLocator = (TemplateLocator) getPortletContext().getAttribute("TemplateLocator"); |
130 |
0 |
decorationLocator = (TemplateLocator) getPortletContext().getAttribute("DecorationLocator"); |
131 |
0 |
} |
132 |
|
|
133 |
|
public void doHelp( RenderRequest request, RenderResponse response ) throws PortletException, IOException |
134 |
|
{ |
135 |
0 |
response.setContentType("text/html"); |
136 |
0 |
JetspeedPowerTool jpt = getJetspeedPowerTool(request); |
137 |
|
|
138 |
0 |
String absHelpPage = ""; |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
try |
144 |
|
{ |
145 |
0 |
String helpPage = (String)request.getPortletSession().getAttribute(PortalReservedParameters.PAGE_LAYOUT_HELP); |
146 |
0 |
if (helpPage == null) |
147 |
|
{ |
148 |
0 |
PortletPreferences prefs = request.getPreferences(); |
149 |
0 |
helpPage = prefs.getValue(PARAM_HELP_PAGE, null); |
150 |
0 |
if (helpPage == null) |
151 |
|
{ |
152 |
0 |
helpPage = this.getInitParameter(PARAM_HELP_PAGE); |
153 |
0 |
if (helpPage == null) |
154 |
0 |
helpPage = "columns"; |
155 |
|
} |
156 |
0 |
request.getPortletSession().setAttribute(PortalReservedParameters.PAGE_LAYOUT_HELP, helpPage); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
0 |
Configuration props = getConfiguration(request, helpPage); |
161 |
0 |
String ext = (String) props.getString(TEMPLATE_EXTENSION_KEY); |
162 |
0 |
absHelpPage = jpt.getTemplate(helpPage + "/" + JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE + "-help" + ext, |
163 |
|
JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE).getAppRelativePath(); |
164 |
0 |
log.debug("Path to help page for LayoutPortlet " + absHelpPage); |
165 |
0 |
request.setAttribute(PARAM_VIEW_PAGE, absHelpPage); |
166 |
|
} |
167 |
0 |
catch (TemplateLocatorException e) |
168 |
|
{ |
169 |
0 |
throw new PortletException("Unable to locate view page " + absHelpPage, e); |
170 |
0 |
} |
171 |
0 |
super.doView(request, response); |
172 |
|
|
173 |
0 |
} |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
public void doView( RenderRequest request, RenderResponse response ) throws PortletException, IOException |
179 |
|
{ |
180 |
0 |
response.setContentType("text/html"); |
181 |
0 |
RequestContext context = getRequestContext(request); |
182 |
0 |
PortletWindow window = context.getPortalURL().getNavigationalState().getMaximizedWindow(); |
183 |
0 |
boolean maximized = (window != null); |
184 |
0 |
boolean solo = false; |
185 |
|
|
186 |
0 |
if (maximized) |
187 |
|
{ |
188 |
0 |
request.setAttribute("layout", getMaximizedLayout(request)); |
189 |
0 |
solo = JetspeedActions.SOLO_STATE.equals(context.getPortalURL().getNavigationalState().getMappedState(window)); |
190 |
0 |
if ( solo ) |
191 |
|
{ |
192 |
0 |
maximized = false; |
193 |
|
} |
194 |
|
} |
195 |
|
else |
196 |
|
{ |
197 |
0 |
request.setAttribute("layout", getFragment(request, false)); |
198 |
|
} |
199 |
0 |
String viewPage = null; |
200 |
0 |
String absViewPage = null; |
201 |
|
try |
202 |
|
{ |
203 |
0 |
JetspeedPowerTool jpt = getJetspeedPowerTool(request); |
204 |
0 |
if (maximized) |
205 |
|
{ |
206 |
0 |
viewPage = (String)request.getPortletSession().getAttribute(PortalReservedParameters.PAGE_LAYOUT_MAX); |
207 |
0 |
if (viewPage == null) |
208 |
|
{ |
209 |
0 |
PortletPreferences prefs = request.getPreferences(); |
210 |
0 |
viewPage = prefs.getValue(PARAM_MAX_PAGE, null); |
211 |
0 |
if (viewPage == null) |
212 |
|
{ |
213 |
0 |
viewPage = this.getInitParameter(PARAM_MAX_PAGE); |
214 |
0 |
if (viewPage == null) |
215 |
0 |
viewPage = "maximized"; |
216 |
|
} |
217 |
0 |
request.getPortletSession().setAttribute(PortalReservedParameters.PAGE_LAYOUT_MAX, viewPage); |
218 |
0 |
} |
219 |
|
} |
220 |
0 |
else if (solo) |
221 |
|
{ |
222 |
0 |
viewPage = (String)request.getPortletSession().getAttribute(PortalReservedParameters.PAGE_LAYOUT_SOLO); |
223 |
0 |
if (viewPage == null) |
224 |
|
{ |
225 |
0 |
PortletPreferences prefs = request.getPreferences(); |
226 |
0 |
viewPage = prefs.getValue(PARAM_SOLO_PAGE, null); |
227 |
0 |
if (viewPage == null) |
228 |
|
{ |
229 |
0 |
viewPage = this.getInitParameter(PARAM_SOLO_PAGE); |
230 |
0 |
if (viewPage == null) |
231 |
|
{ |
232 |
0 |
viewPage = "solo"; |
233 |
|
} |
234 |
|
} |
235 |
0 |
request.getPortletSession().setAttribute(PortalReservedParameters.PAGE_LAYOUT_SOLO, viewPage); |
236 |
0 |
} |
237 |
|
} |
238 |
|
else |
239 |
|
{ |
240 |
0 |
viewPage = (String)request.getPortletSession().getAttribute(PortalReservedParameters.PAGE_LAYOUT_VIEW); |
241 |
0 |
if (viewPage == null) |
242 |
|
{ |
243 |
0 |
PortletPreferences prefs = request.getPreferences(); |
244 |
0 |
viewPage = prefs.getValue(PARAM_VIEW_PAGE, null); |
245 |
0 |
if (viewPage == null) |
246 |
|
{ |
247 |
0 |
viewPage = this.getInitParameter(PARAM_VIEW_PAGE); |
248 |
0 |
if (viewPage == null) |
249 |
0 |
viewPage = "columns"; |
250 |
|
} |
251 |
0 |
request.getPortletSession().setAttribute(PortalReservedParameters.PAGE_LAYOUT_VIEW, viewPage); |
252 |
|
} |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
0 |
Configuration props = getConfiguration(request, viewPage); |
257 |
0 |
String ext = (String) props.getString(TEMPLATE_EXTENSION_KEY); |
258 |
|
|
259 |
|
|
260 |
0 |
absViewPage = jpt.getTemplate(viewPage + "/" + JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE + ext, |
261 |
|
JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE).getAppRelativePath(); |
262 |
0 |
log.debug("Path to view page for LayoutPortlet " + absViewPage); |
263 |
0 |
request.setAttribute(PARAM_VIEW_PAGE, absViewPage); |
264 |
|
} |
265 |
0 |
catch (TemplateLocatorException e) |
266 |
|
{ |
267 |
0 |
throw new PortletException("Unable to locate view page " + absViewPage, e); |
268 |
0 |
} |
269 |
0 |
super.doView(request, response); |
270 |
|
|
271 |
0 |
request.removeAttribute(PortalReservedParameters.PAGE_ATTRIBUTE); |
272 |
0 |
request.removeAttribute("fragment"); |
273 |
0 |
request.removeAttribute("layout"); |
274 |
0 |
request.removeAttribute("dispatcher"); |
275 |
0 |
} |
276 |
|
|
277 |
|
public void processAction(ActionRequest request, ActionResponse response) |
278 |
|
throws PortletException, IOException |
279 |
|
{ |
280 |
0 |
String page = request.getParameter("page"); |
281 |
0 |
String deleteFragmentId = request.getParameter("deleteId"); |
282 |
0 |
String portlets = request.getParameter("portlets"); |
283 |
0 |
if (deleteFragmentId != null && deleteFragmentId.length() > 0) |
284 |
|
{ |
285 |
0 |
removeFragment(page, deleteFragmentId); |
286 |
|
} |
287 |
0 |
else if (portlets != null && portlets.length() > 0) |
288 |
|
{ |
289 |
0 |
int count = 0; |
290 |
0 |
StringTokenizer tokenizer = new StringTokenizer(portlets, ","); |
291 |
0 |
while (tokenizer.hasMoreTokens()) |
292 |
|
{ |
293 |
0 |
String portlet = tokenizer.nextToken(); |
294 |
|
try |
295 |
|
{ |
296 |
0 |
if (portlet.startsWith("box_")) |
297 |
|
{ |
298 |
0 |
portlet = portlet.substring("box_".length()); |
299 |
0 |
addPortletToPage(page, portlet); |
300 |
0 |
count++; |
301 |
|
} |
302 |
|
} |
303 |
0 |
catch (Exception e) |
304 |
|
{ |
305 |
0 |
log.error("failed to add portlet to page: " + portlet); |
306 |
0 |
} |
307 |
0 |
} |
308 |
|
|
309 |
|
} |
310 |
0 |
} |
311 |
|
|
312 |
|
protected void removeFragment(String pageId, String fragmentId) |
313 |
|
{ |
314 |
0 |
Page page = null; |
315 |
|
try |
316 |
|
{ |
317 |
0 |
page = pageManager.getPage(pageId); |
318 |
|
|
319 |
|
} |
320 |
0 |
catch (Exception e) |
321 |
|
{ |
322 |
0 |
log.error("failed to remove portlet " + fragmentId + " from page: " + pageId, e); |
323 |
0 |
} |
324 |
0 |
removeFragment(page,page.getRootFragment(), fragmentId); |
325 |
0 |
} |
326 |
|
|
327 |
|
protected void removeFragment(Page page, Fragment root, String fragmentId) |
328 |
|
{ |
329 |
|
try |
330 |
|
{ |
331 |
0 |
Fragment f = page.getFragmentById(fragmentId); |
332 |
0 |
if ( f == null ) |
333 |
|
{ |
334 |
|
|
335 |
0 |
return; |
336 |
|
} |
337 |
0 |
root.getFragments().remove(f); |
338 |
0 |
pageManager.updatePage(page); |
339 |
|
} |
340 |
0 |
catch (Exception e) |
341 |
|
{ |
342 |
0 |
log.error("failed to remove portlet " + fragmentId + " from page: " + page, e); |
343 |
0 |
} |
344 |
0 |
} |
345 |
|
|
346 |
|
protected void addPortletToPage(String pageId, String portletId) |
347 |
|
{ |
348 |
0 |
Page page = null; |
349 |
|
try |
350 |
|
{ |
351 |
0 |
page = pageManager.getContentPage(pageId); |
352 |
|
} |
353 |
0 |
catch (Exception e) |
354 |
|
{ |
355 |
0 |
log.error("failed to add portlet " + portletId + " to page: " + pageId, e); |
356 |
0 |
} |
357 |
0 |
addPortletToPage(page, page.getRootFragment(), portletId); |
358 |
0 |
} |
359 |
|
|
360 |
|
protected void addPortletToPage(Page page, Fragment root, String portletId) |
361 |
|
{ |
362 |
|
try |
363 |
|
{ |
364 |
0 |
Fragment fragment = pageManager.newFragment(); |
365 |
0 |
fragment.setType(Fragment.PORTLET); |
366 |
0 |
fragment.setName(portletId); |
367 |
|
|
368 |
0 |
root.getFragments().add(fragment); |
369 |
0 |
pageManager.updatePage(page); |
370 |
|
} |
371 |
0 |
catch (Exception e) |
372 |
|
{ |
373 |
0 |
log.error("failed to add portlet " + portletId + " to page: " + page, e); |
374 |
0 |
} |
375 |
0 |
} |
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
protected JetspeedPowerTool getJetspeedPowerTool( RenderRequest request ) throws PortletException |
388 |
|
{ |
389 |
0 |
JetspeedPowerTool tool = (JetspeedPowerTool) request.getAttribute(PortalReservedParameters.JETSPEED_POWER_TOOL_REQ_ATTRIBUTE); |
390 |
0 |
RequestContext requestContext = (RequestContext) request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); |
391 |
|
|
392 |
0 |
if (tool == null) |
393 |
|
{ |
394 |
|
|
395 |
|
try |
396 |
|
{ |
397 |
0 |
if (requestContext == null) |
398 |
|
{ |
399 |
0 |
throw new IllegalStateException( |
400 |
|
"LayoutPortlet unable to handle request because there is no RequestContext in " |
401 |
|
+ "the HttpServletRequest."); |
402 |
|
} |
403 |
|
|
404 |
0 |
tool = this.jptFactory.getJetspeedPowerTool(requestContext); |
405 |
0 |
request.setAttribute(PortalReservedParameters.JETSPEED_POWER_TOOL_REQ_ATTRIBUTE, tool); |
406 |
|
} |
407 |
|
|
408 |
0 |
catch (Exception e1) |
409 |
|
{ |
410 |
0 |
throw new PortletException("Unable to init JetspeedPowerTool: " + e1.toString(), e1); |
411 |
0 |
} |
412 |
|
} |
413 |
|
|
414 |
0 |
return tool; |
415 |
|
} |
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
protected Fragment getFragment( RenderRequest request, boolean maximized ) |
424 |
|
{ |
425 |
0 |
String attribute = (maximized) |
426 |
|
? PortalReservedParameters.MAXIMIZED_FRAGMENT_ATTRIBUTE |
427 |
|
: PortalReservedParameters.FRAGMENT_ATTRIBUTE; |
428 |
0 |
return (Fragment) request.getAttribute(attribute); |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
435 |
|
|
436 |
|
protected Fragment getMaximizedLayout( RenderRequest request ) |
437 |
|
{ |
438 |
0 |
return (Fragment) request.getAttribute(PortalReservedParameters.MAXIMIZED_LAYOUT_ATTRIBUTE); |
439 |
|
} |
440 |
|
|
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
protected RequestContext getRequestContext( RenderRequest request ) |
447 |
|
{ |
448 |
0 |
RequestContext requestContext = (RequestContext) request |
449 |
|
.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); |
450 |
0 |
if (requestContext != null) |
451 |
|
{ |
452 |
0 |
return requestContext; |
453 |
|
} |
454 |
|
else |
455 |
|
{ |
456 |
0 |
throw new IllegalStateException( |
457 |
|
"getRequestContext() failed as it appears that no RenderRequest is available within the RenderRequest"); |
458 |
|
} |
459 |
|
} |
460 |
|
|
461 |
|
|
462 |
|
|
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
|
473 |
|
public void doEdit( RenderRequest request, RenderResponse response ) throws PortletException, IOException |
474 |
|
{ |
475 |
0 |
doView(request, response); |
476 |
0 |
} |
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
|
|
484 |
|
protected LocatorDescriptor getTemplateLocatorDescriptor(RenderRequest request) throws TemplateLocatorException |
485 |
|
{ |
486 |
0 |
RequestContext requestContext = getRequestContext(request); |
487 |
0 |
CapabilityMap capabilityMap = requestContext.getCapabilityMap(); |
488 |
0 |
Locale locale = requestContext.getLocale(); |
489 |
|
|
490 |
0 |
LocatorDescriptor templateLocatorDescriptor = templateLocator.createLocatorDescriptor(null); |
491 |
0 |
templateLocatorDescriptor.setMediaType(capabilityMap.getPreferredMediaType().getName()); |
492 |
0 |
templateLocatorDescriptor.setCountry(locale.getCountry()); |
493 |
0 |
templateLocatorDescriptor.setLanguage(locale.getLanguage()); |
494 |
0 |
return templateLocatorDescriptor; |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
protected LocatorDescriptor getDecoratorLocatorDescriptor(RenderRequest request) throws TemplateLocatorException |
505 |
|
{ |
506 |
0 |
RequestContext requestContext = getRequestContext(request); |
507 |
0 |
CapabilityMap capabilityMap = requestContext.getCapabilityMap(); |
508 |
0 |
Locale locale = requestContext.getLocale(); |
509 |
|
|
510 |
0 |
LocatorDescriptor decorationLocatorDescriptor = decorationLocator.createLocatorDescriptor(null); |
511 |
0 |
decorationLocatorDescriptor.setMediaType(capabilityMap.getPreferredMediaType().getName()); |
512 |
0 |
decorationLocatorDescriptor.setCountry(locale.getCountry()); |
513 |
0 |
decorationLocatorDescriptor.setLanguage(locale.getLanguage()); |
514 |
|
|
515 |
0 |
return decorationLocatorDescriptor; |
516 |
|
} |
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
522 |
|
|
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
public String decorateAndInclude(RenderRequest request, Fragment fragment, Page page) throws TemplateLocatorException, ConfigurationException |
528 |
|
{ |
529 |
0 |
String fragmentType = fragment.getType(); |
530 |
0 |
String decorator = fragment.getDecorator(); |
531 |
0 |
LocatorDescriptor decorationLocatorDescriptor = getDecoratorLocatorDescriptor(request); |
532 |
0 |
if (decorator == null) |
533 |
|
{ |
534 |
0 |
decorator = page.getEffectiveDefaultDecorator(fragmentType); |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
0 |
TemplateDescriptor propsTemp = getTemplate(decorator + "/" + DECORATOR_TYPE + ".properties", fragmentType, |
539 |
|
decorationLocator, decorationLocatorDescriptor); |
540 |
0 |
if (propsTemp == null) |
541 |
|
{ |
542 |
0 |
fragmentType = GENERIC_TEMPLATE_TYPE; |
543 |
0 |
propsTemp = getTemplate(decorator + "/" + DECORATOR_TYPE + ".properties", fragmentType, decorationLocator, |
544 |
|
decorationLocatorDescriptor); |
545 |
|
} |
546 |
|
|
547 |
|
|
548 |
0 |
Configuration decoConf = new PropertiesConfiguration(propsTemp.getAbsolutePath()); |
549 |
0 |
String ext = decoConf.getString("template.extension"); |
550 |
0 |
String decoratorPath = decorator + "/" + DECORATOR_TYPE + ext; |
551 |
0 |
TemplateDescriptor template = null; |
552 |
|
try |
553 |
|
{ |
554 |
0 |
template = getDecoration(request, decoratorPath, fragmentType); |
555 |
|
} |
556 |
0 |
catch (TemplateLocatorException e) |
557 |
|
{ |
558 |
0 |
String parent = decoConf.getString("extends"); |
559 |
0 |
if (parent != null) |
560 |
|
{ |
561 |
0 |
template = getDecoration(request, parent + "/" + DECORATOR_TYPE + ext, fragmentType); |
562 |
|
} |
563 |
0 |
} |
564 |
|
|
565 |
0 |
return template.getAppRelativePath(); |
566 |
|
} |
567 |
|
|
568 |
|
|
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
|
573 |
|
|
574 |
|
|
575 |
|
|
576 |
|
protected TemplateDescriptor getDecoration( RenderRequest request, String path, String templateType ) throws TemplateLocatorException |
577 |
|
{ |
578 |
0 |
return getTemplate(path, templateType, decorationLocator, getDecoratorLocatorDescriptor(request)); |
579 |
|
} |
580 |
|
|
581 |
|
|
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
protected TemplateDescriptor getTemplate( String path, String templateType, TemplateLocator locator, |
591 |
|
LocatorDescriptor descriptor ) throws TemplateLocatorException |
592 |
|
{ |
593 |
|
|
594 |
0 |
if (templateType == null) |
595 |
|
{ |
596 |
0 |
templateType = GENERIC_TEMPLATE_TYPE; |
597 |
|
} |
598 |
|
try |
599 |
|
{ |
600 |
|
|
601 |
0 |
descriptor.setName(path); |
602 |
0 |
descriptor.setType(templateType); |
603 |
|
|
604 |
0 |
TemplateDescriptor template = locator.locateTemplate(descriptor); |
605 |
0 |
return template; |
606 |
|
} |
607 |
0 |
catch (TemplateLocatorException e) |
608 |
|
{ |
609 |
0 |
log.error("Unable to locate template: " + path, e); |
610 |
|
|
611 |
0 |
throw e; |
612 |
|
} |
613 |
|
} |
614 |
|
|
615 |
|
|
616 |
|
|
617 |
|
|
618 |
|
|
619 |
|
|
620 |
|
|
621 |
|
protected Configuration getConfiguration( RenderRequest request, String name ) |
622 |
|
{ |
623 |
0 |
Configuration props = null; |
624 |
0 |
JetspeedPowerTool jpt = null; |
625 |
0 |
String templatePropertiesPath = null; |
626 |
0 |
String key = name; |
627 |
|
try |
628 |
|
{ |
629 |
0 |
jpt = getJetspeedPowerTool(request); |
630 |
0 |
templatePropertiesPath = jpt.getTemplate(name + "/" + JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE + ".properties", |
631 |
|
JetspeedPowerTool.LAYOUT_TEMPLATE_TYPE).getAbsolutePath(); |
632 |
|
} |
633 |
0 |
catch (PortletException e) |
634 |
|
{ |
635 |
0 |
log.warn("Could not acquire JetspeedPowerTool from request",e); |
636 |
|
} |
637 |
0 |
catch (TemplateLocatorException e) |
638 |
|
{ |
639 |
0 |
log.warn("Could not find templatePorpertiesPath",e); |
640 |
|
} |
641 |
0 |
catch (Exception e) |
642 |
|
{ |
643 |
0 |
log.warn("Could not determine Layout template properties file",e); |
644 |
0 |
} |
645 |
|
|
646 |
0 |
if (null == templatePropertiesPath) |
647 |
|
{ |
648 |
0 |
key = "default"; |
649 |
|
} |
650 |
|
else |
651 |
|
{ |
652 |
0 |
key = templatePropertiesPath; |
653 |
|
} |
654 |
0 |
props = (Configuration)this.layoutTemplateProperties.get(key); |
655 |
|
|
656 |
0 |
if ( props != null ) |
657 |
|
{ |
658 |
0 |
return props; |
659 |
|
} |
660 |
0 |
if (log.isDebugEnabled()){ |
661 |
0 |
log.debug( |
662 |
|
"Template descriptor path:<" + templatePropertiesPath + ">" |
663 |
|
); |
664 |
|
} |
665 |
|
|
666 |
|
|
667 |
|
try |
668 |
|
{ |
669 |
0 |
props = new PropertiesConfiguration(templatePropertiesPath); |
670 |
0 |
if (log.isDebugEnabled()) |
671 |
0 |
log.debug("Successfully read in: <" + templatePropertiesPath + "> "); |
672 |
|
} |
673 |
0 |
catch (Exception e) |
674 |
|
{ |
675 |
0 |
props = new PropertiesConfiguration(); |
676 |
0 |
log.warn( "Could not locate the " + templatePropertiesPath + " file for layout template \"" + name + "\". This layout template may not exist.",e ); |
677 |
0 |
props.setProperty( "id", name ); |
678 |
0 |
props.setProperty( TEMPLATE_TYPE_KEY, DEFAULT_TEMPLATE_TYPE ); |
679 |
0 |
props.setProperty( TEMPLATE_EXTENSION_KEY, DEFAULT_TEMPLATE_EXT); |
680 |
|
} |
681 |
|
finally |
682 |
|
{ |
683 |
0 |
String templateIdPropVal = (String) props.getProperty( "id" ); |
684 |
0 |
String templateNamePropVal = (String) props.getProperty( TEMPLATE_TYPE_KEY ); |
685 |
0 |
String templateExtPropVal = (String) props.getProperty(TEMPLATE_EXTENSION_KEY); |
686 |
|
|
687 |
0 |
if ( templateIdPropVal == null ) |
688 |
|
{ |
689 |
0 |
templateIdPropVal = name; |
690 |
0 |
props.setProperty( "id", templateIdPropVal ); |
691 |
|
} |
692 |
|
|
693 |
0 |
if ( templateNamePropVal == null ) |
694 |
|
{ |
695 |
0 |
props.setProperty( TEMPLATE_TYPE_KEY, DEFAULT_TEMPLATE_TYPE ); |
696 |
|
} |
697 |
0 |
if ( templateExtPropVal == null ) |
698 |
|
{ |
699 |
0 |
props.setProperty( TEMPLATE_EXTENSION_KEY, DEFAULT_TEMPLATE_EXT ); |
700 |
|
} |
701 |
0 |
} |
702 |
|
|
703 |
0 |
this.layoutTemplateProperties.put(key, props); |
704 |
0 |
if (log.isDebugEnabled()) |
705 |
|
{ |
706 |
0 |
log.debug("Template layout.properties extension is:<" + props.getString(TEMPLATE_EXTENSION_KEY)); |
707 |
|
} |
708 |
0 |
return props; |
709 |
|
} |
710 |
|
|
711 |
|
} |