KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > invocation > 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.core.invocation;
10
11 import org.jboss.portal.core.CoreConstants;
12 import org.jboss.portal.core.plugins.page.Page;
13 import org.jboss.portal.core.plugins.page.WindowLocation;
14 import org.jboss.portal.server.Portal;
15 import org.jboss.portal.server.PortalRequest;
16 import org.jboss.portal.server.PortalServer;
17 import org.jboss.portal.server.ServerObjectID;
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 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 /**
28  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
29  * @version $Revision: 1.8 $
30  */

31 public class ViewInterceptor implements Interceptor
32 {
33
34    public Object JavaDoc invoke(Invocation invocation)
35    {
36       try
37       {
38          PortalRequest req = (PortalRequest)invocation.getAttachment(AttachmentKey.PORTAL_REQUEST);
39          PortalServer container = req.getServer();
40          Page page = (Page)invocation.getAttachment(CoreAttachmentKey.PAGE);
41
42          // Portal
43
Portal portal = page.getRepository().getPortal();
44
45          // Get all windows in the page
46
List JavaDoc windows = new ArrayList JavaDoc();
47          for (Iterator JavaDoc i = page.getLocations().iterator(); i.hasNext();)
48          {
49             WindowLocation ref = (WindowLocation)i.next();
50             ServerObjectID id = ref.getID();
51             Window window = (Window)container.getObject(id);
52             if (window != null && container.isStarted(window))
53             {
54                // fixme ???
55
// That means the window is still in the repository
56
// and does not exist in the object container anymore
57
windows.add(window);
58             }
59          }
60
61 /*
62          //
63          UserContext uctx = (UserContext)invocation.getAttachment(AttachmentKey.USER_CONTEXT);
64
65          // Look for a maximized window
66          ServerObjectID maximized = null;
67
68          //
69          ServerObject target = req.getTarget();
70          if (target instanceof Window)
71          {
72             WindowContext wctx = (WindowContext)uctx.getContext((ServerObject)target);
73             if (WindowState.MAXIMIZED.equals(wctx.getWindowState()))
74             {
75                maximized = target.getID();
76             }
77          }
78
79          //
80          if (maximized == null)
81          {
82             for (Iterator i = windows.iterator(); i.hasNext();)
83             {
84                Window window = (Window)i.next();
85                WindowContext wctx = (WindowContext)uctx.getContext(window);
86                if (WindowState.MAXIMIZED.equals(wctx.getWindowState()))
87                {
88                   maximized = window.getID();
89                   break;
90                }
91             }
92          }
93
94          // Use default
95          if (maximized == null)
96          {
97             maximized = page.getDefaultWindow();
98             Window window = (Window)container.getObject(maximized);
99             WindowContext wctx = (WindowContext)uctx.getContext(window);
100             wctx.setWindowState(WindowState.MAXIMIZED);
101          }
102          // Minimize all other
103          for (Iterator i = windows.iterator(); i.hasNext();)
104          {
105             Window window = (Window)i.next();
106             WindowContext wctx = (WindowContext)uctx.getContext(window);
107             if (!window.getID().equals(maximized) && WindowState.MAXIMIZED.equals(wctx.getWindowState()))
108             {
109                wctx.setWindowState(WindowState.NORMAL);
110             }
111          }
112 */

113
114          // Follow invocation path
115
invocation.setAttachment(AttachmentKey.VIEW, windows);
116          invocation.setAttachment(AttachmentKey.PORTAL, portal);
117          // req.setAttribute(CoreConstants.REQ_ATT_DEFAULTWINDOWID, page.getDefaultWindow());
118
return invocation.invokeNext();
119       }
120       finally
121       {
122          invocation.removeAttachment(AttachmentKey.VIEW);
123       }
124    }
125 }
126
Popular Tags