KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > impl > invocation > CoreInvocation


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.impl.invocation;
10
11 import java.util.Map JavaDoc;
12
13 import javax.servlet.http.HttpServletRequest JavaDoc;
14 import javax.servlet.http.HttpServletResponse JavaDoc;
15
16 import org.jboss.portal.core.CorePortal;
17 import org.jboss.portal.core.CoreConstants;
18 import org.jboss.portal.core.invocation.CoreAttachmentKey;
19 import org.jboss.portal.core.plugins.page.Page;
20 import org.jboss.portal.core.plugins.page.PageRepository;
21 import org.jboss.portal.server.Portal;
22 import org.jboss.portal.server.PortalServer;
23 import org.jboss.portal.server.ServerObject;
24 import org.jboss.portal.server.ServerURL;
25 import org.jboss.portal.server.Window;
26 import org.jboss.portal.server.WindowURL;
27 import org.jboss.portal.server.impl.invocation.InvocationImpl;
28 import org.jboss.portal.server.util.Parameters;
29
30 /**
31  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
32  * @version $Revision: 1.7 $
33  */

34 public class CoreInvocation
35    extends InvocationImpl
36    implements MappingContext
37 {
38
39    public CoreInvocation(
40          PortalServer container,
41          HttpServletRequest JavaDoc req,
42          HttpServletResponse JavaDoc resp,
43          int nonSecurePort,
44          int securePort)
45    {
46       super(container, req, resp, nonSecurePort, securePort);
47    }
48
49
50    protected void decodeTarget()
51    {
52       // Process id if any
53
super.decodeTarget();
54
55       // The portal path info
56
String JavaDoc portalPathInfo = null;
57
58       // Map the request
59
if (target != null)
60       {
61          portalPathInfo = null;
62       }
63       else
64       {
65          // Find if we have a target portal
66
String JavaDoc pathInfo = req.getPathInfo();
67
68          // Map the path info to a portal oject
69
MappingResult result = new SimpleMapper().map(this, pathInfo);
70
71          // Unwrap the result
72
target = (ServerObject)result.getTarget();
73          portalPathInfo = result.getTargetPathInfo();
74       }
75
76       //
77
if (target == null || target instanceof Portal)
78       {
79          CorePortal cp = null;
80          if (target == null)
81          {
82             cp = (CorePortal)container.getDefaultPortal();
83          }
84          else
85          {
86             cp = (CorePortal)target;
87          }
88
89          //
90
Map JavaDoc props = cp.getProperties();
91          String JavaDoc defaultWindowName = (String JavaDoc)props.get("org.jboss.portal.property.action");
92          if (defaultWindowName != null)
93          {
94             target = cp.getWindow(defaultWindowName);
95             if (target != null)
96             {
97                // Create a fake action for the default portlet so it can process it
98
WindowURL url = (WindowURL)target.createURL();
99                url.setType(WindowURL.TYPE_ACTION);
100                url.setTargetParameter(CoreConstants.REQ_ACTION_PARAM_PATH, portalPathInfo);
101                targetParameters = url.getTargetParameters();
102                controlParameters = url.getControlParameters();
103             }
104             else
105             {
106                log.warn("Cannot find default window " + defaultWindowName + " in portal " + cp.getName());
107             }
108          }
109       }
110
111       // Find the page
112
Page page = null;
113       if (target instanceof Window)
114       {
115          CorePortal portal = (CorePortal)((Window)target).getPortal();
116          PageRepository repository = portal.getPageRepository();
117          page = repository.getPageByWindow(target.getID());
118       }
119       else if (target instanceof Portal)
120       {
121          PageRepository repository = ((CorePortal)target).getPageRepository();
122          page = repository.getDefaultPage();
123       }
124       else if (target instanceof Page)
125       {
126          page = (Page)target;
127       }
128       else
129       {
130          // Nothing, use default page of default portal
131
CorePortal portal = (CorePortal)container.getDefaultPortal();
132          PageRepository repository = portal.getPageRepository();
133          page = repository.getDefaultPage();
134       }
135
136       // If the target is valid generate the incoming URL
137
if (target != null)
138       {
139          // Get current state
140
Map JavaDoc controlMap = controlParameters.getParameterMap();
141          Map JavaDoc targetMap = targetParameters.getParameterMap();
142          boolean secure = req.isSecure();
143
144          // Ask the object to create an URL
145
ServerURL tmp = target.createURL();
146          Parameters urlControlMap = tmp.getControlParameters();
147          Parameters urlTargetMap = tmp.getTargetParameters();
148
149          // Update its state with the incoming request
150
urlControlMap.setParameterMap(controlMap);
151          urlTargetMap.setParameterMap(targetMap);
152          tmp.setSecure(Boolean.valueOf(secure));
153          this.url = tmp;
154       }
155
156       //
157
if (page != null)
158       {
159          setAttachment(CoreAttachmentKey.PAGE, page);
160          req.setAttribute(CoreConstants.REQ_ATT_SERVLET_PATH, req.getServletPath());
161          req.setAttribute(CoreConstants.REQ_ATT_CONTEXT_PATH, req.getContextPath());
162       }
163       else
164       {
165          // No page, this is a problem and must be raised
166
throw new IllegalStateException JavaDoc("No page found");
167       }
168    }
169
170    // MappingContext implementation ------------------------------------------------------------------------------------
171

172    public Object JavaDoc getRoot()
173    {
174       return container;
175    }
176
177    public Object JavaDoc getChild(Object JavaDoc parent, String JavaDoc name)
178    {
179       if (parent == container)
180       {
181          CorePortal portal = (CorePortal)container.getPortal(name);
182          if (portal != null)
183          {
184             return portal;
185          }
186          portal = (CorePortal)container.getDefaultPortal();
187          Page page = portal.getPageRepository().getPageByName(name);
188          return page;
189       }
190       else if (parent instanceof Portal)
191       {
192          CorePortal portal = (CorePortal)parent;
193          Page page = portal.getPageRepository().getPageByName(name);
194          return page;
195       }
196       else
197       {
198          return null;
199       }
200    }
201 }
202
Popular Tags