| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
package org.webmacro.servlet; |
| 25 | |
|
| 26 | |
import java.util.Enumeration; |
| 27 | |
|
| 28 | |
import javax.servlet.http.HttpServletRequest; |
| 29 | |
|
| 30 | |
import org.webmacro.UnsettableException; |
| 31 | |
import org.webmacro.util.Bag; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
final public class Form implements Bag |
| 41 | |
{ |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
final HttpServletRequest _request; |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
Form(final HttpServletRequest r) |
| 52 | 1040 | { |
| 53 | 1040 | _request = r; |
| 54 | 1040 | } |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
final public Object get(String field) |
| 60 | |
{ |
| 61 | 6096 | String[] values = _request.getParameterValues(field); |
| 62 | |
try |
| 63 | |
{ |
| 64 | 6096 | return values[0]; |
| 65 | |
} |
| 66 | 5194 | catch (NullPointerException ne) |
| 67 | |
{ |
| 68 | 5194 | return null; |
| 69 | |
} |
| 70 | 0 | catch (ArrayIndexOutOfBoundsException e) |
| 71 | |
{ |
| 72 | |
|
| 73 | 0 | return null; |
| 74 | |
} |
| 75 | |
} |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
final public Object getPossibleForm(String strKey) |
| 86 | |
{ |
| 87 | |
String strElement; |
| 88 | |
Object obValue; |
| 89 | |
|
| 90 | |
Enumeration obEnumeration; |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | 0 | obValue = get(strKey); |
| 95 | 0 | if (obValue == null) |
| 96 | |
{ |
| 97 | 0 | obEnumeration = _request.getParameterNames(); |
| 98 | 0 | while (obEnumeration.hasMoreElements()) |
| 99 | |
{ |
| 100 | 0 | strElement = obEnumeration.nextElement().toString(); |
| 101 | 0 | if (strElement.equalsIgnoreCase(strKey)) |
| 102 | |
{ |
| 103 | 0 | obValue = get(strElement); |
| 104 | 0 | break; |
| 105 | |
} |
| 106 | |
} |
| 107 | |
} |
| 108 | |
|
| 109 | 0 | return obValue; |
| 110 | |
} |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
final public Object[] getList(String field) |
| 117 | |
{ |
| 118 | |
try |
| 119 | |
{ |
| 120 | 0 | return _request.getParameterValues(field); |
| 121 | |
} |
| 122 | 0 | catch (NullPointerException ne) |
| 123 | |
{ |
| 124 | 0 | return null; |
| 125 | |
} |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
final public void put(String key, Object value) |
| 132 | |
throws UnsettableException |
| 133 | |
{ |
| 134 | 0 | throw new UnsettableException("Cannot set a form property"); |
| 135 | |
} |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
final public void remove (String key) |
| 142 | |
throws UnsettableException |
| 143 | |
{ |
| 144 | 0 | throw new UnsettableException("Cannot unset a form property"); |
| 145 | |
} |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
final public String toString () |
| 151 | |
{ |
| 152 | 0 | StringBuffer sb = new StringBuffer(); |
| 153 | 0 | String eol = java.lang.System.getProperty("line.separator"); |
| 154 | 0 | for (Enumeration params = _request.getParameterNames(); params.hasMoreElements(); ) |
| 155 | |
{ |
| 156 | 0 | String key = (String) params.nextElement(); |
| 157 | 0 | String[] value = _request.getParameterValues(key); |
| 158 | |
|
| 159 | 0 | for (int x = 0; value != null && x < value.length; x++) |
| 160 | |
{ |
| 161 | 0 | sb.append(key).append("=").append(value[x]).append(eol); |
| 162 | |
} |
| 163 | 0 | } |
| 164 | 0 | return sb.toString(); |
| 165 | |
} |
| 166 | |
|
| 167 | |
} |
| 168 | |
|