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.wfs.response;
06:
07: import net.opengis.wfs.GetCapabilitiesType;
08: import org.geoserver.ows.Response;
09: import org.geoserver.ows.util.OwsUtils;
10: import org.geoserver.platform.Operation;
11: import org.geotools.xml.transform.TransformerBase;
12: import java.io.IOException;
13: import java.io.OutputStream;
14: import java.util.Iterator;
15: import java.util.List;
16: import javax.xml.transform.TransformerException;
17:
18: public class GetCapabilitiesResponse extends Response {
19: public GetCapabilitiesResponse() {
20: super (TransformerBase.class);
21: }
22:
23: public String getMimeType(Object value, Operation operation) {
24: GetCapabilitiesType request = (GetCapabilitiesType) OwsUtils
25: .parameter(operation.getParameters(),
26: GetCapabilitiesType.class);
27:
28: if ((request != null) && (request.getAcceptFormats() != null)) {
29: //look for an accepted format
30: List formats = request.getAcceptFormats().getOutputFormat();
31:
32: for (Iterator f = formats.iterator(); f.hasNext();) {
33: String format = (String) f.next();
34:
35: if (format.endsWith("/xml")) {
36: return format;
37: }
38: }
39: }
40:
41: //default
42: return "application/xml";
43: }
44:
45: public void write(Object value, OutputStream output,
46: Operation operation) throws IOException {
47: TransformerBase tx = (TransformerBase) value;
48:
49: try {
50: tx.transform(operation.getParameters()[0], output);
51: } catch (TransformerException e) {
52: throw (IOException) new IOException().initCause(e);
53: }
54: }
55: }
|