KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > portlet > PortletObjectModelHelper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.environment.portlet;
17
18 import javax.portlet.ActionRequest;
19 import javax.portlet.ActionResponse;
20 import javax.portlet.PortletContext;
21 import javax.portlet.PortletRequest;
22 import javax.portlet.PortletResponse;
23 import javax.portlet.RenderRequest;
24 import javax.portlet.RenderResponse;
25
26 import java.util.Map JavaDoc;
27
28 /**
29  * A set of constants and methods to access the JSR-168 (Portlet)
30  * specific objects from the object model.
31  *
32  * The object model is a <code>Map</code> used to pass information about the
33  * calling environment to the sitemap and its components (matchers, actions,
34  * transformers, etc).
35  *
36  * @author <a HREF="mailto:alex.rudnev@dc.gov">Alex Rudnev</a>
37  * @version CVS $Id: PortletObjectModelHelper.java 30932 2004-07-29 17:35:38Z vgritsenko $
38  */

39 public final class PortletObjectModelHelper {
40
41     /** Key for the environment {@link javax.portlet.RenderRequest} in the object model. */
42     public final static String JavaDoc RENDER_REQUEST_OBJECT = "render-request";
43
44     /** Key for the environment {@link javax.portlet.ActionRequest} in the object model. */
45     public final static String JavaDoc ACTION_REQUEST_OBJECT = "action-request";
46
47     /** Key for the environment {@link javax.portlet.RenderResponse} in the object model. */
48     public final static String JavaDoc RENDER_RESPONSE_OBJECT = "render-response";
49
50     /** Key for the environment {@link javax.portlet.ActionResponse} in the object model. */
51     public final static String JavaDoc ACTION_RESPONSE_OBJECT = "action-response";
52
53     /** Key for the environment {@link javax.portlet.PortletRequest} in the object model. */
54     public static final String JavaDoc PORTLET_REQUEST_OBJECT = "portlet-request";
55
56     /** Key for the environment {@link javax.portlet.PortletResponse} in the object model. */
57     public static final String JavaDoc PORTLET_RESPONSE_OBJECT = "portlet-response";
58
59     /** Key for the environment {@link javax.portlet.PortletContext} in the object model. */
60     public static final String JavaDoc PORTLET_CONTEXT_OBJECT = "portlet-context";
61
62     private PortletObjectModelHelper() {
63         // Forbid instantiation
64
}
65
66     public static final RenderRequest getRenderRequest(Map JavaDoc objectModel) {
67         return (RenderRequest) objectModel.get(RENDER_REQUEST_OBJECT);
68     }
69
70     public static final RenderResponse getRenderResponse(Map JavaDoc objectModel) {
71         return (RenderResponse) objectModel.get(RENDER_RESPONSE_OBJECT);
72     }
73
74     public static final ActionRequest getActionRequest(Map JavaDoc objectModel) {
75         return (ActionRequest) objectModel.get(ACTION_REQUEST_OBJECT);
76     }
77
78     public static final ActionResponse getActionResponse(Map JavaDoc objectModel) {
79         return (ActionResponse) objectModel.get(ACTION_RESPONSE_OBJECT);
80     }
81
82     public static final PortletRequest getPortletRequest(Map JavaDoc objectModel) {
83         return (PortletRequest) objectModel.get(PORTLET_REQUEST_OBJECT);
84     }
85
86     public static final PortletResponse getPortletResponse(Map JavaDoc objectModel) {
87         return (PortletResponse) objectModel.get(PORTLET_RESPONSE_OBJECT);
88     }
89
90     public static final PortletContext getPortletContext(Map JavaDoc objectModel) {
91         return (PortletContext) objectModel.get(PORTLET_CONTEXT_OBJECT);
92     }
93
94     public static final void setPortletRequest(Map JavaDoc objectModel, PortletRequest object) {
95         if (objectModel.get(PORTLET_REQUEST_OBJECT) != null) {
96             throw new IllegalStateException JavaDoc("PortletRequest has been set already");
97         }
98         objectModel.put(PORTLET_REQUEST_OBJECT, object);
99         if (object instanceof ActionRequest) {
100             objectModel.put(ACTION_REQUEST_OBJECT, object);
101         }
102         if (object instanceof RenderRequest) {
103             objectModel.put(RENDER_REQUEST_OBJECT, object);
104         }
105     }
106
107     public static final void setPortletResponse(Map JavaDoc objectModel, PortletResponse object) {
108         if (objectModel.get(PORTLET_RESPONSE_OBJECT) != null) {
109             throw new IllegalStateException JavaDoc("PortletResponse has been set already");
110         }
111         objectModel.put(PORTLET_RESPONSE_OBJECT, object);
112         if (object instanceof ActionResponse) {
113             objectModel.put(ACTION_RESPONSE_OBJECT, object);
114         }
115         if (object instanceof RenderResponse) {
116             objectModel.put(RENDER_RESPONSE_OBJECT, object);
117         }
118     }
119
120     public static final void setPortletContext(Map JavaDoc objectModel, PortletContext object) {
121         if (objectModel.get(PORTLET_CONTEXT_OBJECT) != null) {
122             throw new IllegalStateException JavaDoc("PortletContext has been set already");
123         }
124         objectModel.put(PORTLET_CONTEXT_OBJECT, object);
125     }
126 }
127
Popular Tags