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.util.requests;
06:
07: import org.vfny.geoserver.servlets.AbstractService;
08: import org.xml.sax.Attributes;
09: import org.xml.sax.ContentHandler;
10: import org.xml.sax.SAXException;
11: import org.xml.sax.helpers.XMLFilterImpl;
12: import java.util.logging.Logger;
13: import javax.servlet.http.HttpServletRequest;
14:
15: /**
16: * A SAX content handler that acquires a GetCapabilities request from an
17: * incoming XML stream.
18: *
19: * @author Rob Hranac, TOPP
20: * @version $Id: CapabilitiesHandler.java 8406 2008-02-14 19:49:39Z saul.farber $
21: */
22: public class CapabilitiesHandler extends XMLFilterImpl implements
23: ContentHandler {
24: /** Class logger */
25: private static Logger LOGGER = org.geotools.util.logging.Logging
26: .getLogger("org.vfny.geoserver.requests");
27:
28: /** Internal Capabilities request for construction. */
29: private CapabilitiesRequest request = null;
30:
31: /**
32: * Creates a new CapabilitiesHandler
33: * @param service this is the AbstractService Handling the Request
34: * @deprecated use {@link #CapabilitiesHandler(CapabilitiesRequest)}.
35: */
36: public CapabilitiesHandler(AbstractService service) {
37: this (new CapabilitiesRequest("WFS", service));
38: }
39:
40: /**
41: * Creates a new CapabilitiesHandler
42: * @param service this is the AbstractService Handling the Request
43: * @param req
44: */
45: public CapabilitiesHandler(CapabilitiesRequest request) {
46: this .request = request;
47: }
48:
49: /**
50: * Returns the GetCapabilities request.
51: *
52: * @return GetCapabilities request.
53: */
54: public CapabilitiesRequest getRequest(HttpServletRequest req) {
55: request.setHttpServletRequest(req);
56:
57: return request;
58: }
59:
60: /* ***********************************************************************
61: * Standard SAX content handler methods *
62: * ***********************************************************************/
63:
64: /**
65: * Notes the start of the element and sets version and service tags, as
66: * required.
67: *
68: * @param namespaceURI URI for namespace appended to element.
69: * @param localName Local name of element.
70: * @param rawName Raw name of element.
71: * @param atts Element attributes.
72: *
73: * @throws SAXException For any standard SAX errors.
74: */
75: public void startElement(String namespaceURI, String localName,
76: String rawName, Attributes atts) throws SAXException {
77: if (localName.equals("GetCapabilities")) {
78: LOGGER.finer("found capabilities start.");
79:
80: for (int i = 0, n = atts.getLength(); i < n; i++) {
81: if (atts.getLocalName(i).equals("version")) {
82: request.setVersion(atts.getValue(i));
83: } else if (atts.getLocalName(i).equals("service")) {
84: request.setService(atts.getValue(i));
85: } else if (atts.getLocalName(i)
86: .equals("updateSequence")) {
87: request.setUpdateSequence(atts.getValue(i));
88: }
89: }
90: }
91: }
92: }
|