Source Code Cross Referenced for InternalExpressionUtils.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » pageflow » internal » 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 » Library » Apache beehive 1.0.2 src » org.apache.beehive.netui.pageflow.internal 
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:         * $Header:$
018:         */
019:        package org.apache.beehive.netui.pageflow.internal;
020:
021:        import java.util.Map;
022:        import java.util.Enumeration;
023:        import java.util.HashMap;
024:
025:        import javax.servlet.ServletContext;
026:        import javax.servlet.jsp.el.ExpressionEvaluator;
027:        import javax.servlet.jsp.el.VariableResolver;
028:        import javax.servlet.jsp.el.ELException;
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpSession;
031:        import javax.servlet.http.Cookie;
032:
033:        import org.apache.beehive.netui.util.logging.Logger;
034:        import org.apache.commons.el.ExpressionEvaluatorImpl;
035:        import org.apache.commons.el.EnumeratedMap;
036:
037:        /**
038:         * Internal class used to evaluate simple action expressions.
039:         * 
040:         * todo: need to merge this down into the expression language registration infrastructure
041:         * todo: need to provdie an ImplicitObjectFactory that will create Maps for requestScope, sessionScope, etc.
042:         */
043:        public class InternalExpressionUtils {
044:            private static final Logger _logger = Logger
045:                    .getInstance(InternalExpressionUtils.class);
046:
047:            public static final boolean evaluateCondition(String expression,
048:                    Object actionForm, HttpServletRequest request,
049:                    ServletContext servletContext) throws ELException {
050:                return ((Boolean) evaluate(expression, Boolean.class,
051:                        actionForm, request, servletContext)).booleanValue();
052:            }
053:
054:            public static final String evaluateMessage(String expression,
055:                    Object actionForm, HttpServletRequest request,
056:                    ServletContext servletContext) throws ELException {
057:                return (String) evaluate(expression, String.class, actionForm,
058:                        request, servletContext);
059:            }
060:
061:            /* do not construct */
062:            private InternalExpressionUtils() {
063:            }
064:
065:            private static final Object evaluate(String expression,
066:                    Class expectedType, Object actionForm,
067:                    HttpServletRequest request, ServletContext servletContext)
068:                    throws ELException {
069:                // todo: can this be static / final?
070:                ExpressionEvaluator ee = getExpressionEvaluator();
071:                return ee
072:                        .evaluate(expression, expectedType,
073:                                getVariableResolver(actionForm, request,
074:                                        servletContext), null);
075:            }
076:
077:            private static final ExpressionEvaluator getExpressionEvaluator() {
078:                return new ExpressionEvaluatorImpl();
079:            }
080:
081:            private static final VariableResolver getVariableResolver(
082:                    Object actionForm, HttpServletRequest request,
083:                    ServletContext servletContext) {
084:                return new SimpleActionVariableResolver(actionForm, request,
085:                        servletContext);
086:            }
087:
088:            private static class SimpleActionVariableResolver implements 
089:                    VariableResolver {
090:                private Object _actionForm = null;
091:                private HttpServletRequest _request = null;
092:                private ServletContext _servletContext = null;
093:
094:                private SimpleActionVariableResolver(Object actionForm,
095:                        HttpServletRequest request,
096:                        ServletContext servletContext) {
097:                    _actionForm = actionForm;
098:                    _request = request;
099:                    _servletContext = servletContext;
100:                }
101:
102:                public Object resolveVariable(String name) {
103:                    // requestScope, sessionScope, applicationScope, param, paramValues, header, headerValues, cookie, initParam, <default>
104:                    if (name.equals("actionForm"))
105:                        return _actionForm;
106:                    else if (name.equals("requestScope"))
107:                        return buildRequestScopeMap(_request);
108:                    else if (name.equals("sessionScope"))
109:                        return buildSessionScopeMap(_request);
110:                    else if (name.equals("applicationScope"))
111:                        return buildServletContextMap(_servletContext);
112:                    else if (name.equals("param"))
113:                        return buildParamMap(_request);
114:                    else if (name.equals("paramValues"))
115:                        return buildParamsMap(_request);
116:                    else if (name.equals("header"))
117:                        return buildHeaderMap(_request);
118:                    else if (name.equals("headerValues"))
119:                        return buildHeadersMap(_request);
120:                    else if (name.equals("cookie"))
121:                        return buildCookieMap(_request);
122:                    else if (name.equals("initParam"))
123:                        return buildInitParamMap(_servletContext);
124:                    // chain up the request > session (if exists) > application
125:                    // note, this should handle pageFlow, globalApp, sharedFlow, and bundle if they're in the request
126:                    // attribute map already
127:                    else if (_request.getAttribute(name) != null)
128:                        return _request.getAttribute(name);
129:                    else if (_request.getSession(false) != null
130:                            && _request.getSession(false).getAttribute(name) != null)
131:                        return _request.getSession(false).getAttribute(name);
132:                    else
133:                        return _servletContext.getAttribute(name);
134:                }
135:
136:                private static final Map buildCookieMap(
137:                        HttpServletRequest httpServletRequest) {
138:                    HttpServletRequest servletRequest = httpServletRequest;
139:                    Map/*<String, Cookie>*/cookieMap = new HashMap/*<String, Cookie>*/();
140:                    Cookie[] cookies = servletRequest.getCookies();
141:                    for (int i = 0; i < cookies.length; i++) {
142:                        if (!cookieMap.containsKey(cookies[i].getName()))
143:                            cookieMap.put(cookies[i].getName(), cookies[i]);
144:                    }
145:                    return cookieMap;
146:                }
147:
148:                private static final Map buildHeadersMap(
149:                        HttpServletRequest httpServletRequest) {
150:                    final HttpServletRequest _servletRequest = httpServletRequest;
151:                    return new EnumeratedMap() {
152:                        public Enumeration enumerateKeys() {
153:                            return _servletRequest.getHeaderNames();
154:                        }
155:
156:                        public Object getValue(Object key) {
157:                            return (key instanceof  String ? _servletRequest
158:                                    .getHeaders((String) key) : null);
159:                        }
160:
161:                        public boolean isMutable() {
162:                            return false;
163:                        }
164:                    };
165:                }
166:
167:                private static final Map buildHeaderMap(
168:                        HttpServletRequest httpServletRequest) {
169:                    final HttpServletRequest _servletRequest = httpServletRequest;
170:                    return new EnumeratedMap() {
171:                        public Enumeration enumerateKeys() {
172:                            return _servletRequest.getHeaderNames();
173:                        }
174:
175:                        public Object getValue(Object key) {
176:                            return (key instanceof  String ? _servletRequest
177:                                    .getHeader((String) key) : null);
178:                        }
179:
180:                        public boolean isMutable() {
181:                            return false;
182:                        }
183:                    };
184:                }
185:
186:                private static final Map buildInitParamMap(
187:                        ServletContext servletContext) {
188:                    final ServletContext _servletContext = servletContext;
189:                    return new EnumeratedMap() {
190:                        public Enumeration enumerateKeys() {
191:                            return _servletContext.getInitParameterNames();
192:                        }
193:
194:                        public Object getValue(Object key) {
195:                            return (key instanceof  String ? _servletContext
196:                                    .getInitParameter((String) key) : null);
197:                        }
198:
199:                        public boolean isMutable() {
200:                            return false;
201:                        }
202:                    };
203:                }
204:
205:                private static final Map buildParamsMap(
206:                        HttpServletRequest servletRequest) {
207:                    final HttpServletRequest _servletRequest = servletRequest;
208:                    return new EnumeratedMap() {
209:                        public Enumeration enumerateKeys() {
210:                            return _servletRequest.getParameterNames();
211:                        }
212:
213:                        public Object getValue(Object key) {
214:                            return (key instanceof  String ? _servletRequest
215:                                    .getParameterValues((String) key) : null);
216:                        }
217:
218:                        public boolean isMutable() {
219:                            return false;
220:                        }
221:                    };
222:                }
223:
224:                private static final Map buildParamMap(
225:                        HttpServletRequest servletRequest) {
226:                    final HttpServletRequest _servletRequest = servletRequest;
227:                    return new EnumeratedMap() {
228:                        public Enumeration enumerateKeys() {
229:                            return _servletRequest.getParameterNames();
230:                        }
231:
232:                        public Object getValue(Object key) {
233:                            return (key instanceof  String ? _servletRequest
234:                                    .getParameter((String) key) : null);
235:                        }
236:
237:                        public boolean isMutable() {
238:                            return false;
239:                        }
240:                    };
241:                }
242:
243:                private static final Map buildRequestScopeMap(
244:                        HttpServletRequest servletRequest) {
245:                    final HttpServletRequest _servletRequest = servletRequest;
246:                    return new EnumeratedMap() {
247:                        public Enumeration enumerateKeys() {
248:                            return _servletRequest.getAttributeNames();
249:                        }
250:
251:                        public Object getValue(Object key) {
252:                            return (key instanceof  String ? _servletRequest
253:                                    .getAttribute((String) key) : null);
254:                        }
255:
256:                        public boolean isMutable() {
257:                            return false;
258:                        }
259:                    };
260:                }
261:
262:                private static final Map buildSessionScopeMap(
263:                        HttpServletRequest servletRequest) {
264:                    if (servletRequest.getSession(false) == null)
265:                        return null;
266:
267:                    final HttpSession _session = servletRequest
268:                            .getSession(false);
269:                    return new EnumeratedMap() {
270:                        public Enumeration enumerateKeys() {
271:                            return _session.getAttributeNames();
272:                        }
273:
274:                        public Object getValue(Object key) {
275:                            return (key instanceof  String ? _session
276:                                    .getAttribute((String) key) : null);
277:                        }
278:
279:                        public boolean isMutable() {
280:                            return false;
281:                        }
282:                    };
283:                }
284:
285:                private static final Map buildServletContextMap(
286:                        ServletContext servletContext) {
287:                    final ServletContext _servletContext = servletContext;
288:                    return new EnumeratedMap() {
289:                        public Enumeration enumerateKeys() {
290:                            return _servletContext.getAttributeNames();
291:                        }
292:
293:                        public Object getValue(Object key) {
294:                            return (key instanceof  String ? _servletContext
295:                                    .getAttribute((String) key) : null);
296:                        }
297:
298:                        public boolean isMutable() {
299:                            return false;
300:                        }
301:                    };
302:                }
303:            }
304:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.