1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.portlet.context;
23
24 import org.apache.tiles.TilesApplicationContext;
25 import org.apache.tiles.context.TilesContextFactory;
26 import org.apache.tiles.context.TilesRequestContext;
27
28 import javax.portlet.PortletContext;
29 import javax.portlet.PortletRequest;
30 import javax.portlet.PortletResponse;
31 import java.util.Map;
32
33 /***
34 * Creates an instance of the appropriate TilesApplicationContext implementation.
35 *
36 * @version $Rev: 531864 $ $Date: 2007-04-24 12:24:30 +0200 (Tue, 24 Apr 2007) $
37 */
38 public class PortletTilesContextFactory implements TilesContextFactory {
39
40 /*** {@inheritDoc} */
41 public void init(Map<String, String> configParameters) {
42 }
43
44 /*** {@inheritDoc} */
45 public TilesApplicationContext createApplicationContext(Object context) {
46 if (context instanceof PortletContext) {
47 PortletContext portletContext = (PortletContext) context;
48 return new PortletTilesApplicationContext(portletContext);
49 }
50
51 return null;
52 }
53
54 /*** {@inheritDoc} */
55 public TilesRequestContext createRequestContext(TilesApplicationContext context,
56 Object... requestItems) {
57 if (requestItems.length == 2) {
58 PortletContext portletContext = getPortletContext(context);
59 if (portletContext != null) {
60 PortletTilesApplicationContext app = (PortletTilesApplicationContext) context;
61 return new PortletTilesRequestContext(app.getPortletContext(),
62 (PortletRequest) requestItems[0],
63 (PortletResponse) requestItems[1]);
64 }
65 }
66
67 return null;
68 }
69
70 /***
71 * Returns the original portlet context.
72 *
73 * @param context The application context.
74 * @return The original portlet context, if found.
75 */
76 protected PortletContext getPortletContext(TilesApplicationContext context) {
77 if (context instanceof PortletTilesApplicationContext) {
78 PortletTilesApplicationContext app = (PortletTilesApplicationContext) context;
79 return app.getPortletContext();
80 }
81 return null;
82 }
83 }