KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > tck > ViewInterceptor


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet.tck;
10
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
13
14 import org.apache.log4j.Logger;
15 import org.jboss.portal.server.Portal;
16 import org.jboss.portal.server.PortalRequest;
17 import org.jboss.portal.server.PortalServer;
18 import org.jboss.portal.server.Window;
19 import org.jboss.portal.server.invocation.AttachmentKey;
20 import org.jboss.portal.server.invocation.Interceptor;
21 import org.jboss.portal.server.invocation.Invocation;
22
23 /**
24  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
25  * @version $Revision: 1.5 $
26  */

27 public class ViewInterceptor
28    implements Interceptor
29 {
30
31    private static Logger log = Logger.getLogger(ViewInterceptor.class);
32
33    // The requested windows accross the different invocations
34
// It is not concurrently safe but this is for the tests of the TCK.
35
private List JavaDoc windows = new ArrayList JavaDoc();
36
37    public Object JavaDoc invoke(Invocation invocation)
38    {
39       try
40       {
41          // The target portal
42
PortalRequest req = (PortalRequest)invocation.getAttachment(AttachmentKey.PORTAL_REQUEST);
43          PortalServer container = req.getServer();
44          Portal portal = container.getDefaultPortal();
45
46          // Compute the list of windows for this test
47
String JavaDoc[] values = req.getParameterValues("portletName");
48          if (values != null)
49          {
50             // If there is a set of portlet name, that means we begin a test
51
StringBuffer JavaDoc tmp = new StringBuffer JavaDoc("Portlet name request [");
52             for (int i = 0;i < values.length;i++)
53             {
54                tmp.append(i == 0 ? "" : ",").append(values[i]);
55             }
56             tmp.append("]");
57             log.debug(tmp);
58
59             windows.clear();
60             for (int i = 0;i < values.length;i++)
61             {
62                String JavaDoc portletName = "/" + values[i];
63                Window window = portal.getWindow(portletName);
64                if (window != null)
65                {
66                   windows.add(window);
67                }
68                else
69                {
70                   log.error("Cannot find window for the portlet " + portletName);
71                }
72             }
73          }
74
75          // Add all the found windows and follow the invocation path
76
invocation.setAttachment(AttachmentKey.VIEW, new ArrayList JavaDoc(windows));
77          invocation.setAttachment(AttachmentKey.PORTAL, portal);
78          return invocation.invokeNext();
79       }
80       finally
81       {
82          invocation.removeAttachment(AttachmentKey.VIEW);
83       }
84    }
85 }
86
Popular Tags