Source Code Cross Referenced for StandardServletInputData.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » http » core » 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 » aranea mvc 1.1.1 » org.araneaframework.http.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2006 Webmedia Group Ltd.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *  http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         **/package org.araneaframework.http.core;
016:
017:        import java.io.UnsupportedEncodingException;
018:        import java.util.Collections;
019:        import java.util.Enumeration;
020:        import java.util.HashMap;
021:        import java.util.Iterator;
022:        import java.util.LinkedList;
023:        import java.util.Locale;
024:        import java.util.Map;
025:        import javax.servlet.http.HttpServletRequest;
026:        import org.apache.commons.collections.iterators.EnumerationIterator;
027:        import org.araneaframework.OutputData;
028:        import org.araneaframework.Path;
029:        import org.araneaframework.core.Assert;
030:        import org.araneaframework.core.NoCurrentOutputDataSetException;
031:        import org.araneaframework.core.NoSuchNarrowableException;
032:        import org.araneaframework.core.util.ExceptionUtil;
033:        import org.araneaframework.http.HttpInputData;
034:
035:        /**
036:         * A ServletInputdata implementation which uses a StandardPath for determining
037:         * the scope.
038:         * 
039:         * @author "Toomas Römer" <toomas@webmedia.ee>
040:         */
041:        public class StandardServletInputData implements  HttpInputData {
042:            private HttpServletRequest req;
043:
044:            private Map extensions = new HashMap();
045:
046:            private Map globalData = new HashMap();
047:            private Map scopedData = new HashMap();
048:            private boolean dataInited;
049:
050:            private StringBuffer path;
051:            private LinkedList pathPrefixes = new LinkedList();
052:
053:            private String servletPath;
054:
055:            /**
056:             * Constructs a StandardServletInputData from the request. 
057:             * @param request
058:             */
059:            public StandardServletInputData(HttpServletRequest request) {
060:                Assert.notNullParam(request, "request");
061:
062:                servletPath = request.getServletPath();
063:
064:                setRequest(request);
065:                extend(HttpServletRequest.class, req);
066:            }
067:
068:            private void setRequest(HttpServletRequest request) {
069:                req = request;
070:                dataInited = false;
071:
072:                path = new StringBuffer(req.getPathInfo() == null ? "" : req
073:                        .getPathInfo());
074:                pathPrefixes = new LinkedList();
075:            }
076:
077:            private void initData() {
078:                globalData.clear();
079:                scopedData.clear();
080:
081:                Enumeration params = req.getParameterNames();
082:
083:                while (params.hasMoreElements()) {
084:                    String key = (String) params.nextElement();
085:
086:                    if (key.lastIndexOf(".") == -1) {
087:                        //global data - no prefix data
088:                        globalData.put(key, req.getParameter(key));
089:                    } else {
090:                        //scoped data
091:                        String prefix = key.substring(0, key.lastIndexOf("."));
092:                        String subKey = key.substring(key.lastIndexOf(".") + 1);
093:
094:                        Map map = (Map) scopedData.get(prefix);
095:
096:                        if (map == null) {
097:                            map = new HashMap();
098:                            scopedData.put(prefix, map);
099:                        }
100:
101:                        map.put(subKey, req.getParameter(key));
102:                    }
103:                }
104:
105:                dataInited = true;
106:            }
107:
108:            public Map getGlobalData() {
109:                if (!dataInited)
110:                    initData();
111:                return Collections.unmodifiableMap(globalData);
112:            }
113:
114:            public Map getScopedData(Path scope) {
115:                if (!dataInited)
116:                    initData();
117:                Map result = (Map) scopedData.get(scope.toString());
118:                if (result != null) {
119:                    return Collections.unmodifiableMap(result);
120:                } else {
121:                    return Collections.EMPTY_MAP;
122:                }
123:            }
124:
125:            public void extend(Class interfaceClass, Object implementation) {
126:                if (HttpServletRequest.class.equals(interfaceClass)
127:                        && implementation != null)
128:                    setRequest((HttpServletRequest) implementation);
129:
130:                extensions.put(interfaceClass, implementation);
131:            }
132:
133:            public Object narrow(Class interfaceClass) {
134:                Object extension = extensions.get(interfaceClass);
135:                if (extension == null)
136:                    throw new NoSuchNarrowableException(interfaceClass);
137:                return extension;
138:            }
139:
140:            public OutputData getOutputData() {
141:                OutputData output = (OutputData) req
142:                        .getAttribute(OutputData.OUTPUT_DATA_KEY);
143:                if (output == null)
144:                    throw new NoCurrentOutputDataSetException(
145:                            "No OutputData set in the request.");
146:                else
147:                    return output;
148:            }
149:
150:            public String getCharacterEncoding() {
151:                return req.getCharacterEncoding();
152:            }
153:
154:            public String getContainerURL() {
155:                StringBuffer url = new StringBuffer();
156:                url.append(req.getScheme());
157:                url.append("://");
158:                url.append(req.getServerName());
159:                url.append(":");
160:                url.append(req.getServerPort());
161:                url.append(req.getContextPath());
162:                url.append(servletPath);
163:                return url.toString();
164:            }
165:
166:            public String getContainerPath() {
167:                return servletPath;
168:            }
169:
170:            public String getContextURL() {
171:                StringBuffer url = new StringBuffer();
172:                url.append(req.getScheme());
173:                url.append("://");
174:                url.append(req.getServerName());
175:                url.append(":");
176:                url.append(req.getServerPort());
177:                url.append(req.getContextPath());
178:                return url.toString();
179:            }
180:
181:            public String getContextPath() {
182:                return req.getContextPath();
183:            }
184:
185:            public String getRequestURL() {
186:                return req.getRequestURL().toString();
187:            }
188:
189:            public String getContentType() {
190:                return req.getContentType();
191:            }
192:
193:            public Locale getLocale() {
194:                return req.getLocale();
195:            }
196:
197:            public Iterator getParameterNames() {
198:                return new EnumerationIterator(req.getParameterNames());
199:            }
200:
201:            public String[] getParameterValues(String name) {
202:                return req.getParameterValues(name);
203:            }
204:
205:            public String getPath() {
206:                return path.toString();
207:            }
208:
209:            public void popPathPrefix() {
210:                path.insert(0, (String) pathPrefixes.removeLast());
211:            }
212:
213:            public void pushPathPrefix(String pathPrefix) {
214:                Assert.notEmptyParam(pathPrefix, "pathPrefix");
215:
216:                pathPrefixes.addLast(pathPrefix);
217:                path.delete(0, pathPrefix.length() - 1);
218:            }
219:
220:            public void setCharacterEncoding(String encoding) {
221:                Assert.notEmptyParam(encoding, "encoding");
222:
223:                try {
224:                    req.setCharacterEncoding(encoding);
225:                } catch (UnsupportedEncodingException e) {
226:                    ExceptionUtil.uncheckException(e);
227:                }
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.