Source Code Cross Referenced for StateStoreSession.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » engine » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: StateStoreSession.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.engine;
009:
010:        import com.uwyn.rife.config.RifeConfig;
011:        import com.uwyn.rife.engine.exceptions.EngineException;
012:        import com.uwyn.rife.tools.UniqueID;
013:        import com.uwyn.rife.tools.UniqueIDGenerator;
014:        import java.util.LinkedHashMap;
015:        import java.util.Map;
016:        import javax.servlet.http.HttpSession;
017:
018:        public class StateStoreSession implements  StateStore {
019:            public static final String IDENTIFIER = "session";
020:
021:            private static final String ATTRIBUTE_STATES_SUFFIX = "\u0000states";
022:
023:            StateStoreSession() {
024:            }
025:
026:            public void init(Request request) throws EngineException {
027:                request.getSession();
028:            }
029:
030:            public void exportQueryUrl(CharSequenceDeferred deferred,
031:                    String url, FlowState state, ElementInfo source,
032:                    String type, String name) throws EngineException {
033:                Request request = RequestState.getActiveRequestState()
034:                        .getRequest();
035:                Response response = RequestState.getActiveRequestState()
036:                        .getResponse();
037:                HttpSession session = request.getSession();
038:
039:                if (state.isEmpty()) {
040:                    deferred.setContent(response.encodeURL(url));
041:                    return;
042:                }
043:
044:                UniqueID id = UniqueIDGenerator.generate(request
045:                        .getRemoteAddr());
046:                storeStates(id, session);
047:                session.setAttribute(id.toString(), state);
048:
049:                StringBuilder query_parameters = new StringBuilder("?");
050:                query_parameters.append(ReservedParameters.STATEID);
051:                query_parameters.append("=");
052:                query_parameters.append(id.toString());
053:
054:                deferred.setContent(response.encodeURL(url
055:                        + query_parameters.toString()));
056:            }
057:
058:            public void exportFormState(CharSequenceDeferred deferred,
059:                    FlowState state, FormStateType stateType)
060:                    throws EngineException {
061:                Request request = RequestState.getActiveRequestState()
062:                        .getRequest();
063:
064:                HttpSession session = request.getSession();
065:
066:                if (state.isEmpty()) {
067:                    deferred.setContent("");
068:                    return;
069:                }
070:
071:                UniqueID id = UniqueIDGenerator.generate(request
072:                        .getRemoteAddr());
073:                storeStates(id, session);
074:                session.setAttribute(id.toString(), state);
075:
076:                StringBuilder form_state = new StringBuilder();
077:                if (FormStateType.PARAMS == stateType) {
078:                    StateStoreTools.appendHtmlHiddenParam(form_state, deferred,
079:                            ReservedParameters.STATEID, id.toString());
080:                } else if (FormStateType.JAVASCRIPT == stateType) {
081:                    StateStoreTools.appendJavascriptHeader(form_state);
082:                    StateStoreTools.appendJavascriptHiddenParam(form_state,
083:                            ReservedParameters.STATEID, id.toString());
084:                    StateStoreTools.appendJavascriptFooter(form_state);
085:                }
086:
087:                deferred.setContent(form_state.toString());
088:            }
089:
090:            public void exportFormUrl(CharSequenceDeferred deferred, String url)
091:                    throws EngineException {
092:                Response response = RequestState.getActiveRequestState()
093:                        .getResponse();
094:                deferred.setContent(response.encodeURL(url));
095:            }
096:
097:            private FlowState getSessionFlowState(Request request) {
098:                String[] value = request.getParameters().get(
099:                        ReservedParameters.STATEID);
100:                if (null == value || 0 == value.length) {
101:                    return null;
102:                }
103:
104:                String state_id = value[0];
105:                HttpSession session = request.getSession(false);
106:                if (null == session) {
107:                    return null;
108:                }
109:
110:                return (FlowState) session.getAttribute(state_id);
111:            }
112:
113:            public Map<String, String[]> restoreParameters(Request request)
114:                    throws EngineException {
115:                FlowState state = getSessionFlowState(request);
116:                if (null == state) {
117:                    return null;
118:                }
119:
120:                Map<String, String[]> result = new LinkedHashMap<String, String[]>();
121:                if (state.hasParameters()) {
122:                    result.putAll(state.getParameters());
123:                }
124:
125:                String[] values = null;
126:                for (Map.Entry<String, String[]> entry : request
127:                        .getParameters().entrySet()) {
128:                    values = entry.getValue();
129:
130:                    // only override with non empty values
131:                    if (values != null
132:                            && (values.length > 1 || (values[0] != null && values[0]
133:                                    .trim().length() > 0))) {
134:                        result.put(entry.getKey(), values);
135:                    }
136:                }
137:                return result;
138:            }
139:
140:            public ResultStates restoreResultStates(Request request)
141:                    throws EngineException {
142:                ResultStates result_states = null;
143:
144:                String[] value = request.getParameters().get(
145:                        ReservedParameters.STATEID);
146:                if (value != null && value.length > 0) {
147:                    String state_id = value[0];
148:                    HttpSession session = request.getSession(false);
149:                    if (session != null) {
150:                        String states_id = (String) session
151:                                .getAttribute(state_id
152:                                        + ATTRIBUTE_STATES_SUFFIX);
153:                        if (states_id != null
154:                                && states_id.startsWith(ResultStates.ID_PREFIX)) {
155:                            result_states = (ResultStates) session
156:                                    .getAttribute(states_id);
157:                            if (RifeConfig.Engine.getSessionStateStoreCloning()) {
158:                                result_states = result_states
159:                                        .cloneForStateStore(this );
160:                                result_states.regenerateId();
161:                            } else {
162:                                session.removeAttribute(states_id);
163:                            }
164:                        }
165:                    }
166:                }
167:
168:                if (null == result_states) {
169:                    result_states = new ResultStates();
170:                }
171:
172:                FlowState flowstate = getSessionFlowState(request);
173:                if (flowstate != null) {
174:                    if (flowstate.hasSubmissionGlobalInputs()) {
175:                        ElementResultStateSession result_state = new ElementResultStateSession(
176:                                "");
177:                        result_state.setPreservedInputs(flowstate
178:                                .getSubmissionGlobalInputs());
179:                        result_states.put(result_state);
180:                    }
181:
182:                    if (flowstate.hasSubmissionElementInputs()
183:                            && flowstate.getSubmissionContextId() != null) {
184:                        ElementResultStateSession result_state = new ElementResultStateSession(
185:                                flowstate.getSubmissionContextId());
186:                        result_state.setPreservedInputs(flowstate
187:                                .getSubmissionElementInputs());
188:                        result_states.put(result_state);
189:                    }
190:                }
191:
192:                return result_states;
193:            }
194:
195:            public ElementResultState createNewResultState(String contextId)
196:                    throws EngineException {
197:                return new ElementResultStateSession(contextId);
198:            }
199:
200:            public Class getResultStateType() throws EngineException {
201:                return ElementResultStateSession.class;
202:            }
203:
204:            protected void storeStates(UniqueID stateId, HttpSession session) {
205:                ResultStates states = RequestState.getActiveRequestState()
206:                        .getElementResultStatesObtained();
207:                if (null == session.getAttribute(states.getId())) {
208:                    session.setAttribute(states.getId(), states);
209:                }
210:                session.setAttribute(stateId + ATTRIBUTE_STATES_SUFFIX, states
211:                        .getId());
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.