Source Code Cross Referenced for MultiPagePortlet.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » console » 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 » EJB Server geronimo » plugins » org.apache.geronimo.console 
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:         */package org.apache.geronimo.console;
017:
018:        import org.apache.commons.logging.Log;
019:        import org.apache.commons.logging.LogFactory;
020:        import org.apache.commons.fileupload.portlet.PortletFileUpload;
021:        import org.apache.commons.fileupload.disk.DiskFileItemFactory;
022:        import org.apache.commons.fileupload.FileItem;
023:        import org.apache.commons.fileupload.FileUploadException;
024:
025:        import javax.portlet.ActionRequest;
026:        import javax.portlet.ActionResponse;
027:        import javax.portlet.PortletException;
028:        import javax.portlet.RenderRequest;
029:        import javax.portlet.RenderResponse;
030:        import javax.portlet.WindowState;
031:        import javax.portlet.PortletConfig;
032:        import javax.portlet.PortletRequest;
033:        import java.util.Map;
034:        import java.util.HashMap;
035:        import java.util.Iterator;
036:        import java.util.List;
037:        import java.io.IOException;
038:
039:        /**
040:         * A base class for porlets consisting on multiple JSPs with before and after
041:         * actions (e.g. for load and validation/save) and the ability for an "after"
042:         * action to set the next page to load.
043:         *
044:         * @version $Rev: 612052 $ $Date: 2008-01-15 01:10:00 -0800 (Tue, 15 Jan 2008) $
045:         */
046:        public abstract class MultiPagePortlet extends BasePortlet {
047:            private final static Log log = LogFactory
048:                    .getLog(MultiPagePortlet.class);
049:            protected static final String MODE_KEY = "mode";
050:            protected final Map<String, MultiPageAbstractHandler> helpers = new HashMap<String, MultiPageAbstractHandler>();
051:
052:            public void destroy() {
053:                for (MultiPageAbstractHandler handler : helpers.values()) {
054:                    handler.destroy();
055:                }
056:                helpers.clear();
057:                super .destroy();
058:            }
059:
060:            public void processAction(ActionRequest actionRequest,
061:                    ActionResponse actionResponse) throws PortletException,
062:                    IOException {
063:                String mode = null;
064:                Map<String, FileItem> files = null;
065:                Map<String, String> fields = null;
066:                if (actionRequest.getContentType() != null
067:                        && actionRequest.getContentType().startsWith(
068:                                "multipart/form-data")) {
069:                    files = new HashMap<String, FileItem>();
070:                    fields = new HashMap<String, String>();
071:                    PortletFileUpload request = new PortletFileUpload(
072:                            new DiskFileItemFactory());
073:                    try {
074:                        List<FileItem> items = request
075:                                .parseRequest(actionRequest);
076:                        for (FileItem item : items) {
077:                            if (item.isFormField()) {
078:                                if (item.getFieldName().equals(MODE_KEY)) {
079:                                    mode = item.getString();
080:                                }
081:                                fields.put(item.getFieldName(), item
082:                                        .getString());
083:                            } else {
084:                                files.put(item.getFieldName(), item);
085:                            }
086:                        }
087:                    } catch (FileUploadException e) {
088:                        log
089:                                .error(
090:                                        "Unable to process form including a file upload",
091:                                        e);
092:                    }
093:                } else {
094:                    mode = actionRequest.getParameter(MODE_KEY);
095:                }
096:                MultiPageModel model = getModel(actionRequest);
097:                while (true) {
098:                    if (mode == null) {
099:                        break;
100:                    }
101:                    int pos = mode.lastIndexOf('-');
102:                    if (pos == -1) { // Assume it's a render request
103:                        break;
104:                    } else {
105:                        String type = mode.substring(pos + 1);
106:                        mode = mode.substring(0, pos);
107:                        MultiPageAbstractHandler handler = helpers.get(mode);
108:                        if (handler == null) {
109:                            log.error("No handler for action mode '" + mode
110:                                    + "'");
111:                            break;
112:                        }
113:                        if (files == null) {
114:                            handler.getUploadFields().clear();
115:                            handler.getUploadFiles().clear();
116:                        } else {
117:                            handler.getUploadFields().putAll(fields);
118:                            handler.getUploadFiles().putAll(files);
119:                        }
120:                        log.debug("Using action handler '"
121:                                + handler.getClass().getName() + "'");
122:                        if (type.equals("before")) {
123:                            mode = handler.actionBeforeView(actionRequest,
124:                                    actionResponse, model);
125:                        } else if (type.equals("after")) {
126:                            mode = handler.actionAfterView(actionRequest,
127:                                    actionResponse, model);
128:                        } else {
129:                            log.error("Unrecognized portlet action '" + mode
130:                                    + "'");
131:                            mode = null;
132:                        }
133:                    }
134:                }
135:                if (mode != null) {
136:                    actionResponse.setRenderParameter(MODE_KEY, mode);
137:                }
138:                if (model != null) {
139:                    model.save(actionResponse, actionRequest
140:                            .getPortletSession(true));
141:                }
142:            }
143:
144:            protected void doView(RenderRequest renderRequest,
145:                    RenderResponse renderResponse) throws IOException,
146:                    PortletException {
147:                if (WindowState.MINIMIZED
148:                        .equals(renderRequest.getWindowState())) {
149:                    return;
150:                }
151:                String mode = renderRequest.getParameter(MODE_KEY);
152:                MultiPageModel model = getModel(renderRequest);
153:                if (mode == null || mode.equals("")) {
154:                    mode = getDefaultMode();
155:                }
156:                MultiPageAbstractHandler handler = helpers.get(mode);
157:                try {
158:                    if (handler == null) {
159:                        log.error("No handler for render mode '" + mode + "'");
160:                    } else {
161:                        log.debug("Using render handler '"
162:                                + handler.getClass().getName() + "'");
163:                        handler
164:                                .renderView(renderRequest, renderResponse,
165:                                        model);
166:                    }
167:                } catch (Throwable e) {
168:                    log.error("Unable to render portlet", e);
169:                }
170:                renderRequest.setAttribute(getModelJSPVariableName(), model);
171:                if (handler != null) {
172:                    handler.getView().include(renderRequest, renderResponse);
173:                }
174:            }
175:
176:            protected void addHelper(MultiPageAbstractHandler handler,
177:                    PortletConfig config) throws PortletException {
178:                handler.init(config);
179:                helpers.put(handler.getMode(), handler);
180:            }
181:
182:            protected String getDefaultMode() {
183:                if (helpers.containsKey("index"))
184:                    return "index";
185:                if (helpers.containsKey("list"))
186:                    return "list";
187:                return null;
188:            }
189:
190:            protected abstract String getModelJSPVariableName();
191:
192:            protected abstract MultiPageModel getModel(PortletRequest request);
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.