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.wms.responses;
006:
007: import org.springframework.context.ApplicationContext;
008: import org.vfny.geoserver.Request;
009: import org.vfny.geoserver.Response;
010: import org.vfny.geoserver.ServiceException;
011: import org.vfny.geoserver.global.GeoServer;
012: import org.vfny.geoserver.global.Service;
013: import org.vfny.geoserver.wms.WmsException;
014: import org.vfny.geoserver.wms.requests.DescribeLayerRequest;
015: import org.vfny.geoserver.wms.responses.helpers.DescribeLayerTransformer;
016: import java.io.ByteArrayOutputStream;
017: import java.io.IOException;
018: import java.io.OutputStream;
019: import java.util.HashMap;
020: import java.util.logging.Level;
021: import java.util.logging.Logger;
022: import javax.xml.transform.TransformerException;
023:
024: /**
025: * Executes a <code>DescribeLayer</code> WMS request.
026: *
027: * <p>
028: * Recieves a <code>DescribeLayerRequest</code> object holding the references to
029: * the requested layers and utilizes a transformer based on the org.geotools.xml.transform
030: * framework to encode the response.
031: * </p>
032: *
033: * @author Gabriel Roldan, Axios Engineering
034: * @version $Id: DescribeLayerResponse.java 7746 2007-11-13 15:38:35Z aaime $
035: */
036: public class DescribeLayerResponse implements Response {
037: /** DOCUMENT ME! */
038: private static final Logger LOGGER = org.geotools.util.logging.Logging
039: .getLogger(DescribeLayerResponse.class.getPackage()
040: .getName());
041: public static final String DESCLAYER_MIME_TYPE = "application/vnd.ogc.wms_xml";
042:
043: /** the request holding the required FeatureTypeInfo's */
044: private DescribeLayerRequest request;
045:
046: /** the transformer wich takes care of xmlencoding the
047: * DescribeLayer response
048: */
049: private DescribeLayerTransformer transformer;
050:
051: /** the raw XML content ready to be sent to the client */
052: private byte[] content;
053:
054: /**
055: * Returns any extra headers that this service might want to set in the HTTP response object.
056: * @see org.vfny.geoserver.Response#getResponseHeaders()
057: */
058: public HashMap getResponseHeaders() {
059: return null;
060: }
061:
062: /**
063: * DOCUMENT ME!
064: *
065: * @param request DOCUMENT ME!
066: *
067: * @throws ServiceException DOCUMENT ME!
068: * @throws WmsException DOCUMENT ME!
069: */
070: public void execute(Request request) throws ServiceException {
071: this .request = (DescribeLayerRequest) request;
072:
073: if (LOGGER.isLoggable(Level.FINE)) {
074: LOGGER.fine(new StringBuffer("executing request ").append(
075: request).toString());
076: }
077:
078: this .transformer = new DescribeLayerTransformer(this .request
079: .getBaseUrl(), request.getServiceRef().getGeoServer());
080: this .transformer.setNamespaceDeclarationEnabled(false);
081: this .transformer.setEncoding(this .request.getGeoServer()
082: .getCharSet());
083:
084: ByteArrayOutputStream out = new ByteArrayOutputStream();
085:
086: try {
087: transformer.transform(this .request, out);
088: } catch (TransformerException e) {
089: throw new WmsException(e);
090: }
091:
092: this .content = out.toByteArray();
093: }
094:
095: /**
096: * Writes this respone to the provided output stream.
097: *
098: * @param out DOCUMENT ME!
099: *
100: * @throws ServiceException never.
101: * @throws IOException if it is thrown while writing the response content
102: * to <code>out</code>.
103: * @throws IllegalStateException if <code>execute()</code> has not been
104: * called or does not succeed (i.e.: <code>this.content ==
105: * null</code>).
106: */
107: public void writeTo(OutputStream out) throws ServiceException,
108: IOException {
109: if (this .content == null) {
110: throw new IllegalStateException(
111: "execute() has not been called or does not succeed.");
112: }
113:
114: out.write(this .content);
115: }
116:
117: /**
118: * Do nothing, since <code>execute()</code> took care of obtaining the
119: * response, and after that nothing remains to be done but sending the
120: * response content to the client.
121: *
122: * @param gs
123: */
124: public void abort(Service gs) {
125: }
126:
127: /**
128: * Returns the fixed <code>"application/vnd.ogc.wms_xml"</code> MIME type
129: * of this response, as specified in SLD 1.0 spec, section 6.7.
130: *
131: * @param gs the geoserver instance config. Not used here.
132: *
133: * @return <code>"application/vnd.ogc.wms_xml"</code> as the response MIME
134: * type
135: *
136: * @throws IllegalStateException DOCUMENT ME!
137: */
138: public String getContentType(GeoServer gs)
139: throws IllegalStateException {
140: return DESCLAYER_MIME_TYPE;
141: }
142:
143: /**
144: * Returns <code>null</code> since no special encoding is applyed to the
145: * response content.
146: *
147: * @return <code>null</code>
148: */
149: public String getContentEncoding() {
150: return null;
151: }
152:
153: /* (non-Javadoc)
154: * @see org.vfny.geoserver.Response#getContentDisposition()
155: */
156: public String getContentDisposition() {
157: // TODO Auto-generated method stub
158: return null;
159: }
160: }
|