Source Code Cross Referenced for ActionResponseImpl.java in  » Portal » Pluto » org » apache » pluto » internal » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Pluto » org.apache.pluto.internal.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.pluto.internal.impl;
018:
019:        import java.util.Enumeration;
020:        import java.util.HashMap;
021:        import java.util.Iterator;
022:        import java.util.Map;
023:
024:        import javax.portlet.ActionResponse;
025:        import javax.portlet.PortalContext;
026:        import javax.portlet.PortletMode;
027:        import javax.portlet.PortletModeException;
028:        import javax.portlet.WindowState;
029:        import javax.portlet.WindowStateException;
030:        import javax.servlet.http.HttpServletRequest;
031:        import javax.servlet.http.HttpServletResponse;
032:        import javax.servlet.http.HttpServletResponseWrapper;
033:
034:        import org.apache.pluto.PortletContainer;
035:        import org.apache.pluto.descriptors.portlet.PortletDD;
036:        import org.apache.pluto.descriptors.portlet.SupportsDD;
037:        import org.apache.pluto.internal.InternalActionResponse;
038:        import org.apache.pluto.internal.InternalPortletWindow;
039:        import org.apache.pluto.spi.ResourceURLProvider;
040:        import org.apache.pluto.spi.PortalCallbackService;
041:        import org.apache.pluto.util.StringUtils;
042:
043:        public class ActionResponseImpl extends PortletResponseImpl implements 
044:                ActionResponse, InternalActionResponse {
045:
046:            /**
047:             * Is it still allowed to invoke the method sendRedirect() ?
048:             */
049:            boolean redirectAllowed = true;
050:
051:            private boolean redirected;
052:            private String redirectLocation;
053:
054:            private Map renderParameters = new HashMap();
055:            private WindowState windowState = null;
056:            private PortletMode portletMode = null;
057:
058:            private PortalCallbackService callback;
059:            private PortalContext context;
060:
061:            public ActionResponseImpl(PortletContainer container,
062:                    InternalPortletWindow internalPortletWindow,
063:                    HttpServletRequest servletRequest,
064:                    HttpServletResponse servletResponse) {
065:                super (container, internalPortletWindow, servletRequest,
066:                        servletResponse);
067:                context = container.getRequiredContainerServices()
068:                        .getPortalContext();
069:                callback = container.getRequiredContainerServices()
070:                        .getPortalCallbackService();
071:            }
072:
073:            //
074:            // javax.portlet.ActionResponse
075:            //
076:            public void setWindowState(WindowState windowState)
077:                    throws WindowStateException {
078:                if (redirected) {
079:                    throw new IllegalStateException(
080:                            "it is not allowed to invoke setWindowState after sendRedirect has been called");
081:                }
082:
083:                if (isWindowStateAllowed(windowState)) {
084:                    this .windowState = windowState;
085:                } else {
086:                    throw new WindowStateException(
087:                            "Can't set this WindowState", windowState);
088:                }
089:                redirectAllowed = false;
090:            }
091:
092:            public void setPortletMode(PortletMode portletMode)
093:                    throws PortletModeException {
094:                if (redirected) {
095:                    throw new IllegalStateException(
096:                            "it is not allowed to invoke setPortletMode after sendRedirect has been called");
097:                }
098:
099:                // check if portal supports portlet mode
100:                boolean supported = isPortletModeAllowed(portletMode);
101:
102:                // if porlet mode is allowed
103:                if (supported) {
104:                    this .portletMode = portletMode;
105:                } else {
106:                    throw new PortletModeException(
107:                            "Can't set this PortletMode", portletMode);
108:                }
109:
110:                redirectAllowed = false;
111:
112:            }
113:
114:            public void sendRedirect(String location)
115:                    throws java.io.IOException {
116:                if (redirectAllowed) {
117:                    if (location != null) {
118:                        HttpServletResponse redirectResponse = getHttpServletResponse();
119:                        while (redirectResponse instanceof  HttpServletResponseWrapper) {
120:                            redirectResponse = (HttpServletResponse) ((HttpServletResponseWrapper) redirectResponse)
121:                                    .getResponse();
122:                        }
123:
124:                        ResourceURLProvider provider = callback
125:                                .getResourceURLProvider(
126:                                        getHttpServletRequest(),
127:                                        getInternalPortletWindow());
128:
129:                        if (location.indexOf("://") != -1) {
130:                            provider.setAbsoluteURL(location);
131:                        } else {
132:                            provider.setFullPath(location);
133:                        }
134:                        location = redirectResponse.encodeRedirectURL(provider
135:                                .toString());
136:                        //redirectResponse.sendRedirect(location);
137:                        redirectLocation = location;
138:                        redirected = true;
139:                    }
140:                } else {
141:                    throw new java.lang.IllegalStateException(
142:                            "Can't invoke sendRedirect() after certain methods have been called");
143:                }
144:
145:            }
146:
147:            public void setRenderParameters(Map parameters) {
148:                if (redirected) {
149:                    throw new IllegalStateException(
150:                            "Can't invoke setRenderParameters() after sendRedirect() has been called");
151:                }
152:                if (parameters == null) {
153:                    throw new IllegalArgumentException(
154:                            "Render parameters must not be null.");
155:                }
156:                for (Iterator iter = parameters.entrySet().iterator(); iter
157:                        .hasNext();) {
158:                    Map.Entry entry = (Map.Entry) iter.next();
159:                    if (!(entry.getKey() instanceof  String)) {
160:                        throw new IllegalArgumentException(
161:                                "Key must not be null and of type java.lang.String.");
162:                    }
163:                    if (!(entry.getValue() instanceof  String[])) {
164:                        throw new IllegalArgumentException(
165:                                "Value must not be null and of type java.lang.String[].");
166:                    }
167:                }
168:
169:                renderParameters = StringUtils.copyParameters(parameters);
170:
171:                redirectAllowed = false;
172:            }
173:
174:            public void setRenderParameter(String key, String value) {
175:                if (redirected) {
176:                    throw new IllegalStateException(
177:                            "Can't invoke setRenderParameter() after sendRedirect() has been called");
178:                }
179:
180:                if ((key == null) || (value == null)) {
181:                    throw new IllegalArgumentException(
182:                            "Render parameter key or value must not be null.");
183:                }
184:
185:                renderParameters.put(key, new String[] { value });
186:
187:                redirectAllowed = false;
188:            }
189:
190:            public void setRenderParameter(String key, String[] values) {
191:                if (redirected) {
192:                    throw new IllegalStateException(
193:                            "Can't invoke setRenderParameter() after sendRedirect() has been called");
194:                }
195:
196:                if (key == null || values == null || values.length == 0) {
197:                    throw new IllegalArgumentException(
198:                            "Render parameter key or value must not be null or values be an empty array.");
199:                }
200:
201:                renderParameters.put(key, StringUtils.copy(values));
202:
203:                redirectAllowed = false;
204:            }
205:
206:            // --------------------------------------------------------------------------------------------
207:
208:            // org.apache.pluto.core.InternalActionResponse implementation --------------------------------
209:            public Map getRenderParameters() {
210:                return renderParameters;
211:            }
212:
213:            public PortletMode getChangedPortletMode() {
214:                return this .portletMode;
215:            }
216:
217:            public WindowState getChangedWindowState() {
218:                return this .windowState;
219:            }
220:
221:            public String getRedirectLocation() {
222:                return redirectLocation;
223:            }
224:
225:            private boolean isPortletModeAllowed(PortletMode mode) {
226:                return isPortletModeAllowedByPortlet(mode)
227:                        && isPortletModeAllowedByPortal(mode);
228:            }
229:
230:            private boolean isPortletModeAllowedByPortlet(PortletMode mode) {
231:                PortletDD dd = getInternalPortletWindow().getPortletEntity()
232:                        .getPortletDefinition();
233:
234:                Iterator supports = dd.getSupports().iterator();
235:                while (supports.hasNext()) {
236:                    SupportsDD sup = (SupportsDD) supports.next();
237:                    Iterator modes = sup.getPortletModes().iterator();
238:                    while (modes.hasNext()) {
239:                        if (modes.next().toString().equalsIgnoreCase(
240:                                mode.toString())) {
241:                            return true;
242:                        }
243:                    }
244:                }
245:                return false;
246:            }
247:
248:            private boolean isPortletModeAllowedByPortal(PortletMode mode) {
249:                Enumeration supportedModes = context.getSupportedPortletModes();
250:                while (supportedModes.hasMoreElements()) {
251:                    if (supportedModes.nextElement().toString()
252:                            .equalsIgnoreCase((mode.toString()))) {
253:                        return true;
254:                    }
255:                }
256:                return false;
257:            }
258:
259:            private boolean isWindowStateAllowed(WindowState state) {
260:                Enumeration supportedStates = context
261:                        .getSupportedWindowStates();
262:                while (supportedStates.hasMoreElements()) {
263:                    if (supportedStates.nextElement().toString()
264:                            .equalsIgnoreCase((state.toString()))) {
265:                        return true;
266:                    }
267:                }
268:                return false;
269:            }
270:
271:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.