01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.test.ows;
06:
07: import org.geoserver.ows.KvpParser;
08: import org.geoserver.ows.KvpRequestReader;
09: import org.geoserver.ows.util.CaseInsensitiveMap;
10: import org.geoserver.platform.GeoServerExtensions;
11: import org.geoserver.test.GeoServerTestSupport;
12: import java.util.HashMap;
13: import java.util.Iterator;
14: import java.util.List;
15: import java.util.Map;
16:
17: /**
18: * Test class for testing instances of {@link KvpRequestReader}.
19: * <p>
20: * The {@link #parseKvp(Map)} method of this class sets up a kvp map and parses it
21: * by processing instances of {@link KvpParser} in the application context.
22: * </p>
23: *
24: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
25: *
26: */
27: public abstract class KvpRequestReaderTestSupport extends
28: GeoServerTestSupport {
29: /**
30: * Parses a raw set of kvp's into a parsed set of kvps.
31: *
32: * @param kvp Map of String,String.
33: */
34: protected Map parseKvp(Map /*<String,String>*/raw)
35: throws Exception {
36: //parse the raw values
37: List parsers = GeoServerExtensions.extensions(KvpParser.class,
38: applicationContext);
39: Map kvp = new CaseInsensitiveMap(new HashMap());
40:
41: for (Iterator e = raw.entrySet().iterator(); e.hasNext();) {
42: Map.Entry entry = (Map.Entry) e.next();
43: String key = (String) entry.getKey();
44: String val = (String) entry.getValue();
45: Object parsed = null;
46:
47: for (Iterator p = parsers.iterator(); p.hasNext();) {
48: KvpParser parser = (KvpParser) p.next();
49:
50: if (key.equalsIgnoreCase(parser.getKey())) {
51: parsed = parser.parse(val);
52:
53: if (parsed != null) {
54: break;
55: }
56: }
57: }
58:
59: if (parsed == null) {
60: parsed = val;
61: }
62:
63: kvp.put(key, parsed);
64: }
65:
66: return kvp;
67: }
68: }
|