Source Code Cross Referenced for ParameterParser.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » util » 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 » ERP CRM Financial » sakai » org.sakaiproject.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/velocity/tags/sakai_2-4-1/tool/src/java/org/sakaiproject/util/ParameterParser.java $
003:         * $Id: ParameterParser.java 21413 2007-02-13 17:22:50Z jimeng@umich.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.util;
021:
022:        import java.io.IOException;
023:        import java.util.Iterator;
024:
025:        import javax.servlet.http.HttpServletRequest;
026:
027:        /**
028:         * ParameterParser is a wrapper over the request that provides compatibility with Sakai 1.5 and before.
029:         */
030:        public class ParameterParser {
031:            /** The request. */
032:            protected HttpServletRequest m_req = null;
033:
034:            /**
035:             * Construct with this request.
036:             * 
037:             * @param req
038:             *        The current request.
039:             */
040:            public ParameterParser(HttpServletRequest req) {
041:                m_req = req;
042:            }
043:
044:            /**
045:             * Access the parameter names.
046:             * 
047:             * @return An Iterator of parameter names (String).
048:             */
049:            public Iterator getNames() {
050:                return new EnumerationIterator(m_req.getParameterNames());
051:            }
052:
053:            /**
054:             * Get a (String) parameter by name.
055:             * 
056:             * @param name
057:             *        The parameter name.
058:             * @return The parameter value, or null if it's not defined.
059:             */
060:            public String get(String name) {
061:                return m_req.getParameter(name);
062:            }
063:
064:            /**
065:             * Get a (String) parameter by name.
066:             * 
067:             * @param name
068:             *        The parameter name.
069:             * @return The parameter value, or null if it's not defined.
070:             */
071:            public String getString(String name) {
072:                return get(name);
073:            }
074:
075:            /**
076:             * Get a (String[]) multi-valued parameter by name.
077:             * 
078:             * @param name
079:             *        The parameter name.
080:             * @return The parameter values array (of String), or null if it's not defined.
081:             */
082:            public String[] getStrings(String name) {
083:                return m_req.getParameterValues(name);
084:            }
085:
086:            /**
087:             * Get a boolean parameter by name.
088:             * 
089:             * @param name
090:             *        The parameter name.
091:             * @return The parameter boolean value, or false if it's not defined.
092:             */
093:            public boolean getBoolean(String name) {
094:                return "true".equalsIgnoreCase(get(name));
095:            }
096:
097:            /**
098:             * Get an int parameter by name, with default.
099:             * 
100:             * @param name
101:             *        The parameter name.
102:             * @param deflt
103:             *        The default value.
104:             * @return The parameter int value, or the default if it's not defined or not int.
105:             */
106:            public int getInt(String name, int deflt) {
107:                try {
108:                    return Integer.parseInt(get(name));
109:                } catch (Throwable t) {
110:                    return deflt;
111:                }
112:            }
113:
114:            /**
115:             * Get an int parameter by name.
116:             * 
117:             * @param name
118:             *        The parameter name.
119:             * @return The parameter int value, or 0 if it's not defined or not int.
120:             */
121:            public int getInt(String name) {
122:                return getInt(name, 0);
123:            }
124:
125:            /**
126:             * Clean the user input string of strange newlines, etc.
127:             * 
128:             * @param value
129:             *        The user input string.
130:             * @return value cleaned of string newlines, etc.
131:             */
132:            public String getCleanString(String name) {
133:                String value = getString(name);
134:                if (value == null)
135:                    return null;
136:                if (value.length() == 0)
137:                    return value;
138:
139:                final int len = value.length();
140:                StringBuffer buf = new StringBuffer();
141:
142:                for (int i = 0; i < len; i++) {
143:                    char c = value.charAt(i);
144:                    char next = 0;
145:                    if (i + 1 < len)
146:                        next = value.charAt(i + 1);
147:
148:                    switch (c) {
149:                    case '\r': {
150:                        // detect CR LF, make it a \n
151:                        if (next == '\n') {
152:                            buf.append('\n');
153:                            // eat the next character
154:                            i++;
155:                        } else {
156:                            buf.append(c);
157:                        }
158:
159:                    }
160:                        break;
161:
162:                    default: {
163:                        buf.append(c);
164:                    }
165:                    }
166:                }
167:
168:                if (buf.charAt(buf.length() - 1) == '\n') {
169:                    buf.setLength(buf.length() - 1);
170:                }
171:
172:                return buf.toString();
173:            }
174:
175:            /**
176:             * Access the pathInfo.
177:             * 
178:             * @return The pathInfo.
179:             */
180:            public String getPath() {
181:                return m_req.getPathInfo();
182:            }
183:
184:            /**
185:             * Get a FileItem parameter by name.
186:             * 
187:             * @param name
188:             *        The parameter name.
189:             * @return The parameter FileItem value, or null if it's not defined.
190:             */
191:            public FileItem getFileItem(String name) {
192:                // wrap the Apache FileItem in our own homegrown FileItem
193:                Object o = m_req.getAttribute(name);
194:                if (o != null
195:                        && o instanceof  org.apache.commons.fileupload.FileItem) {
196:                    org.apache.commons.fileupload.FileItem item = (org.apache.commons.fileupload.FileItem) o;
197:                    try {
198:                        return new FileItem(item.getName(), item
199:                                .getContentType(), item.getInputStream());
200:                    } catch (IOException e) {
201:                        return new FileItem(item.getName(), item
202:                                .getContentType(), item.get());
203:                    }
204:                }
205:
206:                return null;
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.