Source Code Cross Referenced for PortletResult.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » portlet » result » 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 » J2EE » webwork 2.2.6 » com.opensymphony.webwork.portlet.result 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.portlet.result;
006:
007:        import java.io.IOException;
008:        import java.util.StringTokenizer;
009:
010:        import javax.portlet.ActionResponse;
011:        import javax.portlet.PortletConfig;
012:        import javax.portlet.PortletException;
013:        import javax.portlet.PortletRequestDispatcher;
014:        import javax.portlet.RenderRequest;
015:        import javax.portlet.RenderResponse;
016:        import javax.servlet.ServletContext;
017:        import javax.servlet.ServletException;
018:        import javax.servlet.http.HttpServletRequest;
019:        import javax.servlet.http.HttpServletResponse;
020:
021:        import org.apache.commons.lang.StringUtils;
022:        import org.apache.commons.logging.Log;
023:        import org.apache.commons.logging.LogFactory;
024:
025:        import com.opensymphony.webwork.ServletActionContext;
026:        import com.opensymphony.webwork.dispatcher.WebWorkResultSupport;
027:        import com.opensymphony.webwork.portlet.PortletActionConstants;
028:        import com.opensymphony.webwork.portlet.context.PortletActionContext;
029:        import com.opensymphony.xwork.ActionInvocation;
030:
031:        /**
032:         * Result type that includes a JSP to render.
033:         * 
034:         * @author Nils-Helge Garli
035:         * @author Rainer Hermanns
036:         * @version $Revision: 2338 $
037:         */
038:        public class PortletResult extends WebWorkResultSupport {
039:
040:            /**
041:             * Logger instance.
042:             */
043:            private static final Log LOG = LogFactory
044:                    .getLog(PortletResult.class);
045:
046:            private String contentType = "text/html";
047:
048:            private String title;
049:
050:            /**
051:             * Execute the result. Obtains the
052:             * {@link javax.portlet.PortletRequestDispatcher}from the
053:             * {@link PortletActionContext}and includes the JSP.
054:             * 
055:             * @see com.opensymphony.xwork.Result#execute(com.opensymphony.xwork.ActionInvocation)
056:             */
057:            public void doExecute(String finalLocation,
058:                    ActionInvocation actionInvocation) throws Exception {
059:
060:                if (PortletActionContext.isRender()) {
061:                    executeRenderResult(finalLocation);
062:                } else if (PortletActionContext.isEvent()) {
063:                    executeActionResult(finalLocation, actionInvocation);
064:                } else {
065:                    executeRegularServletResult(finalLocation, actionInvocation);
066:                }
067:            }
068:
069:            /**
070:             * Executes the regular servlet result.
071:             *
072:             * @param finalLocation
073:             * @param actionInvocation
074:             */
075:            private void executeRegularServletResult(String finalLocation,
076:                    ActionInvocation actionInvocation) throws ServletException,
077:                    IOException {
078:                ServletContext ctx = ServletActionContext.getServletContext();
079:                HttpServletRequest req = ServletActionContext.getRequest();
080:                HttpServletResponse res = ServletActionContext.getResponse();
081:                try {
082:                    ctx.getRequestDispatcher(finalLocation).include(req, res);
083:                } catch (ServletException e) {
084:                    LOG.error("ServletException including " + finalLocation, e);
085:                    throw e;
086:                } catch (IOException e) {
087:                    LOG.error("IOException while including result '"
088:                            + finalLocation + "'", e);
089:                    throw e;
090:                }
091:            }
092:
093:            /**
094:             * Executes the action result.
095:             *
096:             * @param finalLocation
097:             * @param invocation
098:             */
099:            protected void executeActionResult(String finalLocation,
100:                    ActionInvocation invocation) {
101:                LOG.debug("Executing result in Event phase");
102:                ActionResponse res = PortletActionContext.getActionResponse();
103:                LOG.debug("Setting event render parameter: " + finalLocation);
104:                if (finalLocation.indexOf('?') != -1) {
105:                    convertQueryParamsToRenderParams(res, finalLocation
106:                            .substring(finalLocation.indexOf('?') + 1));
107:                    finalLocation = finalLocation.substring(0, finalLocation
108:                            .indexOf('?'));
109:                }
110:                if (finalLocation.endsWith(".action")) {
111:                    // View is rendered with a view action...luckily...
112:                    finalLocation = finalLocation.substring(0, finalLocation
113:                            .lastIndexOf("."));
114:                    res.setRenderParameter(PortletActionConstants.ACTION_PARAM,
115:                            finalLocation);
116:                } else {
117:                    // View is rendered outside an action...uh oh...
118:                    res.setRenderParameter(PortletActionConstants.ACTION_PARAM,
119:                            "renderDirect");
120:                    res.setRenderParameter("location", finalLocation);
121:                }
122:                res.setRenderParameter(PortletActionConstants.MODE_PARAM,
123:                        PortletActionContext.getRequest().getPortletMode()
124:                                .toString());
125:            }
126:
127:            /**
128:             * Converts the query params to render params.
129:             *
130:             * @param response
131:             * @param queryParams
132:             */
133:            protected static void convertQueryParamsToRenderParams(
134:                    ActionResponse response, String queryParams) {
135:                StringTokenizer tok = new StringTokenizer(queryParams, "&");
136:                while (tok.hasMoreTokens()) {
137:                    String token = tok.nextToken();
138:                    String key = token.substring(0, token.indexOf('='));
139:                    String value = token.substring(token.indexOf('=') + 1);
140:                    response.setRenderParameter(key, value);
141:                }
142:            }
143:
144:            /**
145:             * Executes the render result.
146:             *
147:             * @param finalLocation
148:             * @throws PortletException
149:             * @throws IOException
150:             */
151:            protected void executeRenderResult(final String finalLocation)
152:                    throws PortletException, IOException {
153:                LOG.debug("Executing result in Render phase");
154:                PortletConfig cfg = PortletActionContext.getPortletConfig();
155:                RenderRequest req = PortletActionContext.getRenderRequest();
156:                RenderResponse res = PortletActionContext.getRenderResponse();
157:                LOG.debug("PortletConfig: " + cfg);
158:                LOG.debug("RenderRequest: " + req);
159:                LOG.debug("RenderResponse: " + res);
160:                res.setContentType(contentType);
161:                if (StringUtils.isNotEmpty(title)) {
162:                    res.setTitle(title);
163:                }
164:                LOG.debug("Location: " + finalLocation);
165:                PortletRequestDispatcher preparator = cfg.getPortletContext()
166:                        .getNamedDispatcher("preparator");
167:                if (preparator == null) {
168:                    throw new PortletException(
169:                            "Cannot look up 'preparator' servlet. Make sure that you"
170:                                    + "have configured it correctly in the web.xml file.");
171:                }
172:                new IncludeTemplate() {
173:                    protected void when(PortletException e) {
174:                        LOG
175:                                .error(
176:                                        "PortletException while dispatching to 'preparator' servlet",
177:                                        e);
178:                    }
179:
180:                    protected void when(IOException e) {
181:                        LOG
182:                                .error(
183:                                        "IOException while dispatching to 'preparator' servlet",
184:                                        e);
185:                    }
186:                }.include(preparator, req, res);
187:                PortletRequestDispatcher dispatcher = cfg.getPortletContext()
188:                        .getRequestDispatcher(finalLocation);
189:                if (dispatcher == null) {
190:                    throw new PortletException(
191:                            "Could not locate dispatcher for '" + finalLocation
192:                                    + "'");
193:                }
194:                new IncludeTemplate() {
195:                    protected void when(PortletException e) {
196:                        LOG.error("PortletException while dispatching to '"
197:                                + finalLocation + "'");
198:                    }
199:
200:                    protected void when(IOException e) {
201:                        LOG.error("IOException while dispatching to '"
202:                                + finalLocation + "'");
203:                    }
204:                }.include(dispatcher, req, res);
205:            }
206:
207:            /**
208:             * Sets the content type.
209:             *
210:             * @param contentType The content type to set.
211:             */
212:            public void setContentType(String contentType) {
213:                this .contentType = contentType;
214:            }
215:
216:            /**
217:             * Sets the title.
218:             *
219:             * @param title The title to set.
220:             */
221:            public void setTitle(String title) {
222:                this .title = title;
223:            }
224:
225:            static class IncludeTemplate {
226:                protected void include(PortletRequestDispatcher dispatcher,
227:                        RenderRequest req, RenderResponse res)
228:                        throws PortletException, IOException {
229:                    try {
230:                        dispatcher.include(req, res);
231:                    } catch (PortletException e) {
232:                        when(e);
233:                        throw e;
234:                    } catch (IOException e) {
235:                        when(e);
236:                        throw e;
237:                    }
238:                }
239:
240:                protected void when(PortletException e) {
241:                }
242:
243:                protected void when(IOException e) {
244:                }
245:            }
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.