001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.util.requests;
006:
007: import org.vfny.geoserver.servlets.Dispatcher;
008: import org.xml.sax.Attributes;
009: import org.xml.sax.ContentHandler;
010: import org.xml.sax.SAXException;
011: import org.xml.sax.helpers.XMLFilterImpl;
012: import java.util.logging.Logger;
013:
014: /**
015: * Uses SAX to extact a GetFeature query from and incoming GetFeature request
016: * XML stream.
017: *
018: * <p>
019: * Note that this Handler extension ignores Filters completely and must be
020: * chained as a parent to the PredicateFilter method in order to recognize
021: * them. If it is not chained, it will still generate valid queries, but with
022: * no filtering whatsoever.
023: * </p>
024: *
025: * @author Chris Holmes, TOPP
026: * @version $Id: DispatcherHandler.java 7746 2007-11-13 15:38:35Z aaime $
027: */
028: public class DispatcherHandler extends XMLFilterImpl implements
029: ContentHandler {
030: /** Class logger */
031: private static Logger LOGGER = org.geotools.util.logging.Logging
032: .getLogger("org.vfny.geoserver.requests");
033:
034: /** Stores internal request type */
035: private int requestType = Dispatcher.UNKNOWN;
036:
037: /** Stores internal service type. */
038: private int serviceType = Dispatcher.UNKNOWN;
039:
040: /** Stores the internal request type as string */
041: private String request = null;
042:
043: /** Stores hte internal service type as string */
044: private String service = null;
045:
046: /** Flags whether or not type has been set */
047: private boolean gotType = false;
048:
049: /**
050: * @return the service type.
051: */
052: public String getService() {
053: return service;
054: }
055:
056: /**
057: * @return The request type.
058: */
059: public String getRequest() {
060: return request;
061: }
062:
063: //JD: kill these methods
064: /**
065: * Gets the request type. See Dispatcher for the available types.
066: *
067: * @return an int of the request type.
068: *
069: */
070:
071: // public int getRequestType() {
072: // return requestType;
073: // }
074: /**
075: * Gets the service type, for now either WMS or WFS types of Dispatcher.
076: *
077: * @return an int of the service type.
078: */
079:
080: // public int getServiceType() {
081: // return serviceType;
082: // }
083: /**
084: * Notes the start of the element and checks for request type.
085: *
086: * @param namespaceURI URI for namespace appended to element.
087: * @param localName Local name of element.
088: * @param rawName Raw name of element.
089: * @param atts Element attributes.
090: *
091: * @throws SAXException DOCUMENT ME!
092: */
093: public void startElement(String namespaceURI, String localName,
094: String rawName, Attributes atts) throws SAXException {
095: if (gotType) {
096: return;
097: }
098:
099: this .request = localName;
100:
101: //JD: kill this
102: // if (localName.equals("GetCapabilities")) {
103: // this.requestType = Dispatcher.GET_CAPABILITIES_REQUEST;
104: // } else if (localName.equals("DescribeFeatureType")) {
105: // this.requestType = Dispatcher.DESCRIBE_FEATURE_TYPE_REQUEST;
106: // } else if (localName.equals("GetFeature")) {
107: // this.requestType = Dispatcher.GET_FEATURE_REQUEST;
108: // } else if (localName.equals("Transaction")) {
109: // this.requestType = Dispatcher.TRANSACTION_REQUEST;
110: // } else if (localName.equals("GetFeatureWithLock")) {
111: // this.requestType = Dispatcher.GET_FEATURE_LOCK_REQUEST;
112: // } else if (localName.equals("LockFeature")) {
113: // this.requestType = Dispatcher.LOCK_REQUEST;
114: // } else if (localName.equals("GetMap")) {
115: // this.requestType = Dispatcher.GET_MAP_REQUEST;
116: // } else if (localName.equals("GetFeatureInfo")) {
117: // this.requestType = Dispatcher.GET_FEATURE_INFO_REQUEST;
118: // } else {
119: // this.requestType = Dispatcher.UNKNOWN;
120: // }
121: for (int i = 0, n = atts.getLength(); i < n; i++) {
122: if (atts.getLocalName(i).equals("service")) {
123: this .service = atts.getValue(i);
124:
125: //JD: kill this
126: // if (service.equals("WFS")) {
127: // this.serviceType = Dispatcher.WFS_SERVICE;
128: // } else if (service.equals("WMS")) {
129: // this.serviceType = Dispatcher.WMS_SERVICE;
130: // }
131: // } else {
132: // this.serviceType = Dispatcher.UNKNOWN;
133: }
134: }
135:
136: gotType = true;
137: }
138: }
|