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.wms.requests.readers;
06:
07: import org.geotools.filter.FilterFilter;
08: import org.geotools.gml.GMLFilterDocument;
09: import org.geotools.gml.GMLFilterGeometry;
10: import org.opengis.filter.Filter;
11: import org.vfny.geoserver.Request;
12: import org.vfny.geoserver.ServiceException;
13: import org.vfny.geoserver.servlets.AbstractService;
14: import org.vfny.geoserver.util.requests.FilterHandlerImpl;
15: import org.vfny.geoserver.util.requests.readers.XmlRequestReader;
16: import org.xml.sax.InputSource;
17: import org.xml.sax.SAXException;
18: import org.xml.sax.helpers.ParserAdapter;
19: import java.io.IOException;
20: import java.io.Reader;
21: import javax.servlet.http.HttpServletRequest;
22: import javax.xml.parsers.ParserConfigurationException;
23: import javax.xml.parsers.SAXParser;
24: import javax.xml.parsers.SAXParserFactory;
25:
26: public abstract class WmsXmlRequestReader extends XmlRequestReader {
27: /**
28: * Constructs the new wfs xml reader.
29: *
30: * @param service Reference to the service handing a reuqest.
31: */
32: public WmsXmlRequestReader(AbstractService service) {
33: super (service);
34: }
35:
36: /**
37: * Reads the Filter XML request into a geotools Feature object.
38: *
39: * @param rawRequest The plain POST text from the client.
40: *
41: * @return The geotools filter constructed from rawRequest.
42: *
43: * @throws WfsException For any problems reading the request.
44: */
45: public static Filter readFilter(Reader rawRequest) throws Exception {
46: // translate string into a proper SAX input source
47: InputSource requestSource = new InputSource(rawRequest);
48:
49: // instantiante parsers and content handlers
50: FilterHandlerImpl contentHandler = new FilterHandlerImpl();
51: FilterFilter filterParser = new FilterFilter(contentHandler,
52: null);
53: GMLFilterGeometry geometryFilter = new GMLFilterGeometry(
54: filterParser);
55: GMLFilterDocument documentFilter = new GMLFilterDocument(
56: geometryFilter);
57:
58: // read in XML file and parse to content handler
59: SAXParserFactory factory = SAXParserFactory.newInstance();
60: SAXParser parser = factory.newSAXParser();
61: ParserAdapter adapter = new ParserAdapter(parser.getParser());
62:
63: adapter.setContentHandler(documentFilter);
64: adapter.parse(requestSource);
65: LOGGER.fine("just parsed: " + requestSource);
66: LOGGER.fine("passing filter: " + contentHandler.getFilter());
67:
68: return contentHandler.getFilter();
69: }
70: }
|