Source Code Cross Referenced for ParamUtils.java in  » Forum » yazd » com » Yasna » forum » 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 » Forum » yazd » com.Yasna.forum.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.Yasna.forum.util;
002:
003:        import javax.servlet.http.*;
004:        import java.text.SimpleDateFormat;
005:        import java.util.LinkedList;
006:        import java.util.List;
007:        import java.util.Calendar;
008:
009:        /**
010:         *  This class assists skin writers in getting parameters.
011:         */
012:        public class ParamUtils {
013:
014:            /**
015:             *  Gets a parameter as a string.
016:             *  @param request The HttpServletRequest object, known as "request" in a
017:             *  JSP page.
018:             *  @param paramName The name of the parameter you want to get
019:             *  @return The value of the parameter or null if the parameter was not
020:             *  found or if the parameter is a zero-length string.
021:             */
022:            public static String getParameter(HttpServletRequest request,
023:                    String paramName) {
024:                return getParameter(request, paramName, false);
025:            }
026:
027:            /**
028:             *  Gets a parameter as a string.
029:             *  @param request The HttpServletRequest object, known as "request" in a
030:             *  JSP page.
031:             *  @param paramName The name of the parameter you want to get
032:             *  @param emptyStringsOK Return the parameter values even if it is an empty string.
033:             *  @return The value of the parameter or null if the parameter was not
034:             *  found.
035:             */
036:            public static String getParameter(HttpServletRequest request,
037:                    String paramName, boolean emptyStringsOK) {
038:                String temp = request.getParameter(paramName);
039:                if (temp != null) {
040:                    if (temp.equals("") && !emptyStringsOK) {
041:                        return null;
042:                    } else {
043:                        return temp;
044:                    }
045:                } else {
046:                    return null;
047:                }
048:            }
049:
050:            public static java.sql.Date getDateParameter(
051:                    HttpServletRequest request, String paramName) {
052:                String temp = request.getParameter(paramName);
053:                if (temp != null && !temp.equals("")) {
054:                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
055:
056:                    try {
057:                        return new java.sql.Date(df.parse(temp).getTime());
058:                    } catch (Exception ignored) {
059:                    }
060:                    return null;
061:                } else {
062:                    return null;
063:                }
064:            }
065:
066:            public static Calendar getCalendarParameter(
067:                    HttpServletRequest request, String paramName) {
068:                String temp = request.getParameter(paramName);
069:                java.sql.Date tempdt = null;
070:                if (temp != null && !temp.equals("")) {
071:                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
072:
073:                    try {
074:                        tempdt = new java.sql.Date(df.parse(temp).getTime());
075:                    } catch (Exception ignored) {
076:                    }
077:                } else {
078:                    return null;
079:                }
080:                if (tempdt != null) {
081:                    Calendar tempcal = Calendar.getInstance();
082:                    tempcal.setTime(tempdt);
083:                    return tempcal;
084:                } else {
085:                    return null;
086:                }
087:            }
088:
089:            /**
090:             *  Gets a parameter as a boolean.
091:             *  @param request The HttpServletRequest object, known as "request" in a
092:             *  JSP page.
093:             *  @param paramName The name of the parameter you want to get
094:             *  @return True if the value of the parameter was "true", false otherwise.
095:             */
096:            public static boolean getBooleanParameter(
097:                    HttpServletRequest request, String paramName) {
098:                String temp = request.getParameter(paramName);
099:                if (temp != null && temp.equals("true")) {
100:                    return true;
101:                } else {
102:                    return false;
103:                }
104:            }
105:
106:            /**
107:             *  Gets a parameter as a int.
108:             *  @param request The HttpServletRequest object, known as "request" in a
109:             *  JSP page.
110:             *  @param paramName The name of the parameter you want to get
111:             *  @return The int value of the parameter specified or the default value if
112:             *  the parameter is not found.
113:             */
114:            public static int getIntParameter(HttpServletRequest request,
115:                    String paramName, int defaultNum) {
116:                String temp = request.getParameter(paramName);
117:                if (temp != null && !temp.equals("")) {
118:                    int num = defaultNum;
119:                    try {
120:                        num = Integer.parseInt(temp);
121:                    } catch (Exception ignored) {
122:                    }
123:                    return num;
124:                } else {
125:                    return defaultNum;
126:                }
127:            }
128:
129:            public static float getFloatParameter(HttpServletRequest request,
130:                    String paramName, float defaultNum) {
131:                String temp = request.getParameter(paramName);
132:                if (temp != null && !temp.equals("")) {
133:                    float num = defaultNum;
134:                    try {
135:                        num = Float.parseFloat(temp);
136:                    } catch (Exception ignored) {
137:                    }
138:                    return num;
139:                } else {
140:                    return defaultNum;
141:                }
142:            }
143:
144:            public static String[] getArrayParameter(
145:                    HttpServletRequest request, String paramName) {
146:                return request.getParameterValues(paramName);
147:            }
148:
149:            public static int[] getIntArrayParameter(
150:                    HttpServletRequest request, String paramName) {
151:                String delim = ",";
152:                String s = request.getParameter(paramName);
153:                if (s == null) {
154:                    return null;
155:                }
156:                if (delim == null) {
157:                    return null;
158:                }
159:
160:                List l = new LinkedList();
161:                int pos = 0;
162:                int delPos = 0;
163:                while ((delPos = s.indexOf(delim, pos)) != -1) {
164:                    l.add(s.substring(pos, delPos));
165:                    pos = delPos + delim.length();
166:                }
167:                if (pos <= s.length()) {
168:                    // add rest of String
169:                    l.add(s.substring(pos));
170:                }
171:
172:                String[] temp = (String[]) l.toArray(new String[l.size()]);
173:                if (temp == null) {
174:                    return null;
175:                } else {
176:                    int[] tempInt = new int[temp.length];
177:                    for (int i = 0; i < temp.length; i++) {
178:                        tempInt[i] = Integer.parseInt(temp[i]);
179:                    }
180:                    return tempInt;
181:                }
182:            }
183:
184:            /**
185:             *  Gets a checkbox parameter value as a boolean.
186:             *  @param request The HttpServletRequest object, known as "request" in a
187:             *  JSP page.
188:             *  @param paramName The name of the parameter you want to get
189:             *  @return True if the value of the checkbox is "on", false otherwise.
190:             */
191:            public static boolean getCheckboxParameter(
192:                    HttpServletRequest request, String paramName) {
193:                String temp = request.getParameter(paramName);
194:                if (temp != null && temp.equals("on")) {
195:                    return true;
196:                } else {
197:                    return false;
198:                }
199:            }
200:
201:            /**
202:             *  Gets a parameter as a string.
203:             *  @param request The HttpServletRequest object, known as "request" in a
204:             *  JSP page.
205:             *  @param attribName The name of the parameter you want to get
206:             *  @return The value of the parameter or null if the parameter was not
207:             *  found or if the parameter is a zero-length string.
208:             */
209:            public static String getAttribute(HttpServletRequest request,
210:                    String attribName) {
211:                return getAttribute(request, attribName, false);
212:            }
213:
214:            /**
215:             *  Gets a parameter as a string.
216:             *  @param request The HttpServletRequest object, known as "request" in a
217:             *  JSP page.
218:             *  @param attribName The name of the parameter you want to get
219:             *  @param emptyStringsOK Return the parameter values even if it is an empty string.
220:             *  @return The value of the parameter or null if the parameter was not
221:             *  found.
222:             */
223:            public static String getAttribute(HttpServletRequest request,
224:                    String attribName, boolean emptyStringsOK) {
225:                String temp = (String) request.getAttribute(attribName);
226:                if (temp != null) {
227:                    if (temp.equals("") && !emptyStringsOK) {
228:                        return null;
229:                    } else {
230:                        return temp;
231:                    }
232:                } else {
233:                    return null;
234:                }
235:            }
236:
237:            /**
238:             *  Gets an attribute as a boolean.
239:             *  @param request The HttpServletRequest object, known as "request" in a
240:             *  JSP page.
241:             *  @param attribName The name of the attribute you want to get
242:             *  @return True if the value of the attribute is "true", false otherwise.
243:             */
244:            public static boolean getBooleanAttribute(
245:                    HttpServletRequest request, String attribName) {
246:                String temp = (String) request.getAttribute(attribName);
247:                if (temp != null && temp.equals("true")) {
248:                    return true;
249:                } else {
250:                    return false;
251:                }
252:            }
253:
254:            /**
255:             *  Gets an attribute as a int.
256:             *  @param request The HttpServletRequest object, known as "request" in a
257:             *  JSP page.
258:             *  @param attribName The name of the attribute you want to get
259:             *  @return The int value of the attribute or the default value if the attribute is not
260:             *  found or is a zero length string.
261:             */
262:            public static int getIntAttribute(HttpServletRequest request,
263:                    String attribName, int defaultNum) {
264:                String temp = (String) request.getAttribute(attribName);
265:                if (temp != null && !temp.equals("")) {
266:                    int num = defaultNum;
267:                    try {
268:                        num = Integer.parseInt(temp);
269:                    } catch (Exception ignored) {
270:                    }
271:                    return num;
272:                } else {
273:                    return defaultNum;
274:                }
275:            }
276:
277:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.