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.vfny.geoserver.sld.requests;
06:
07: import org.vfny.geoserver.Request;
08: import org.vfny.geoserver.ServiceException;
09: import org.vfny.geoserver.global.WMS;
10: import org.vfny.geoserver.servlets.AbstractService;
11: import org.vfny.geoserver.sld.SldException;
12: import org.vfny.geoserver.util.requests.readers.KvpRequestReader;
13: import java.util.Map;
14: import javax.servlet.http.HttpServletRequest;
15:
16: public class PutStylesKvpReader extends KvpRequestReader {
17: public PutStylesKvpReader(Map kvpPairs, AbstractService service) {
18: super (kvpPairs, service);
19: }
20:
21: public Request getRequest(HttpServletRequest httpRequest)
22: throws ServiceException {
23: PutStylesRequest request = new PutStylesRequest(getServiceRef());
24: request.setHttpServletRequest(httpRequest);
25:
26: String version = getRequestVersion();
27: request.setVersion(version);
28:
29: parseMandatoryParameters(request);
30: parseOptionalParameters(request);
31:
32: return request;
33: }
34:
35: public void parseMandatoryParameters(PutStylesRequest request)
36: throws SldException {
37: String req = getValue("REQUEST");
38:
39: if ((req != null) && !req.equals("")) {
40: if (!req.equalsIgnoreCase("PutStyles")) {
41: throw new SldException("Expecting 'request=PutStyles'");
42: }
43: }
44:
45: String mode = getValue("MODE");
46:
47: if ((mode != null) && !mode.equals("")) {
48: if (mode.equalsIgnoreCase("InsertAndReplace")
49: || mode.equalsIgnoreCase("ReplaceAll")) {
50: request.setMode(mode);
51: } else {
52: throw new SldException(
53: "Parameter must be 'InsertAndReplace' or 'ReplaceAll'.");
54: }
55: }
56: }
57:
58: public void parseOptionalParameters(PutStylesRequest request) {
59: String sld = getValue("SLD");
60:
61: if ((sld != null) && !sld.equals("")) {
62: request.setSLD(sld);
63: }
64:
65: String sld_body = getValue("SLD_BODY");
66:
67: if ((sld_body != null) && !sld_body.equals("")) {
68: request.setSldBody(sld_body);
69: }
70: }
71:
72: protected String getRequestVersion() {
73: String version = getValue("VERSION");
74:
75: if (version == null) {
76: version = getValue("WMTVER");
77: }
78:
79: if (version == null) {
80: version = WMS.getVersion();
81: }
82:
83: return version;
84: }
85: }
|