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.wfsv.xml.v1_1_0;
06:
07: import org.geoserver.ows.XmlRequestReader;
08: import org.geoserver.wfs.WFS;
09: import org.geoserver.wfs.WFSException;
10: import org.geotools.util.Version;
11: import org.geotools.xml.Parser;
12: import org.xml.sax.InputSource;
13: import java.io.Reader;
14: import java.util.Iterator;
15: import java.util.Map;
16:
17: import javax.xml.namespace.QName;
18:
19: public class WfsXmlReader extends XmlRequestReader {
20: private WFS wfs;
21: private WFSVConfiguration configuration;
22:
23: public WfsXmlReader(String element, WFS wfs,
24: WFSVConfiguration configuration) {
25: super (new QName(org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE,
26: element), new Version("1.1.0"), "wfsv");
27: this .wfs = wfs;
28: this .configuration = configuration;
29: }
30:
31: public Object read(Object request, Reader reader, Map kvp)
32: throws Exception {
33: // TODO: make this configurable?
34: configuration.getProperties().add(
35: Parser.Properties.PARSE_UNKNOWN_ELEMENTS);
36:
37: Parser parser = new Parser(configuration);
38:
39: // set the input source with the correct encoding
40: InputSource source = new InputSource(reader);
41: source.setEncoding(wfs.getCharSet().name());
42:
43: Object parsed = parser.parse(source);
44:
45: // valid request? this should definitley be a configuration option
46: // TODO: HACK, disabling validation for transaction
47: if (!"Transaction"
48: .equalsIgnoreCase(getElement().getLocalPart())) {
49: if (!parser.getValidationErrors().isEmpty()) {
50: WFSException exception = new WFSException(
51: "Invalid request", "InvalidParameterValue");
52:
53: for (Iterator e = parser.getValidationErrors()
54: .iterator(); e.hasNext();) {
55: Exception error = (Exception) e.next();
56: exception.getExceptionText().add(
57: error.getLocalizedMessage());
58: }
59:
60: throw exception;
61: }
62: }
63:
64: return parsed;
65: }
66: }
|