View Javadoc

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.struts.flow.portlet;
17  
18  import org.apache.struts.flow.core.*;
19  import javax.portlet.*;
20  import org.apache.commons.chain.web.WebContext;
21  import org.apache.commons.chain.web.portlet.PortletWebContext;
22  import org.apache.struts.flow.core.javascript.fom.FOM_Flow;
23  
24  import java.util.Map;
25  
26  /***
27   *  Access to Portlet resources
28   *
29   * @jsname portlet
30   */
31  public class Portlet {
32      
33      protected FOM_Flow flow = null;
34      protected static final Logger logger = Factory.getLogger();
35  
36      public Portlet() {
37          throw new IllegalStateException("Cannot create new Struts object in a flow script");
38      }
39              
40  
41      /***  Constructor for the JSLog object */
42      public Portlet(FOM_Flow flow) {
43          this.flow = flow;
44      }
45      
46      private PortletWebContext getContext() {
47          WebContext ctx = flow.getWebContext();
48          if (ctx instanceof PortletWebContext) {
49              return (PortletWebContext)ctx;
50          } else {
51              throw new IllegalStateException("The web context must be the PortletWebContext");
52          }
53      }
54      
55      /***
56       *  Gets a map of request parameters as Strings
57       */
58      public Map getParam() {
59          return getContext().getParam();
60      }
61      
62      /***
63       *  Gets a map of request parameters as String arrays
64       */
65      public Map getParamValues() {
66          return getContext().getParamValues();
67      }
68      
69      /***
70       *  Gets a map of request attributes
71       */
72      public Map getRequestScope() {
73          return getContext().getRequestScope();
74      }
75      
76      /***
77       *  Gets a map of session attributes
78       */
79      public Map getSessionScope() {
80          return getContext().getSessionScope();
81      }
82      
83      /***
84       *  Gets a map of application attributes
85       */
86      public Map getApplicationScope() {
87          return getContext().getApplicationScope();
88      }
89      
90      /***
91       *  Gets the portlet request
92       */
93      public PortletRequest getRequest() {
94          return getContext().getRequest();
95      }
96      
97      /***
98       *  Gets the portlet context
99       */
100     public PortletContext getPortletContext() {
101         return getContext().getContext();
102     }
103 }
104