01: package com.technoetic.xplanner.util;
02:
03: import java.util.Map;
04: import java.util.ArrayList;
05: import java.util.Collections;
06: import javax.servlet.ServletRequest;
07:
08: public class RequestUtils {
09: public static String toString(ServletRequest request) {
10: Map parameterMap = request.getParameterMap();
11: ArrayList names = new ArrayList(parameterMap.keySet());
12: Collections.sort(names);
13: StringBuffer str = new StringBuffer();
14: str.append("{\n");
15: for (int i = 0; i < names.size(); i++) {
16: str.append(" ");
17: String name = (String) names.get(i);
18: str.append(name);
19: str.append("=");
20: Object o = parameterMap.get(name);
21: str.append(ToStringUtils.arrayToString((Object[]) o));
22: str.append("\n");
23: }
24: str.append("}\n");
25: return str.toString();
26: }
27:
28: public static boolean isParameterTrue(ServletRequest request,
29: String paramName) {
30: return Boolean.valueOf(request.getParameter(paramName))
31: .booleanValue();
32: }
33:
34: public static boolean isAttributeTrue(ServletRequest request,
35: String attrName) {
36: Object value = request.getAttribute(attrName);
37: if (value == null || !(value instanceof Boolean))
38: return false;
39: return ((Boolean) value).booleanValue();
40: }
41: }
|