Package org.vfny.geoserver.wms.responses.featureInfo

Source Code of org.vfny.geoserver.wms.responses.featureInfo.GmlFeatureInfoResponse

/* Copyright (c) 2001, 2003 TOPP - www.openplans.org.  All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.vfny.geoserver.wms.responses.featureInfo;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.geotools.data.FeatureResults;
import org.vfny.geoserver.ServiceException;
import org.vfny.geoserver.global.FeatureTypeInfo;
import org.vfny.geoserver.wfs.requests.FeatureRequest;
import org.vfny.geoserver.wfs.responses.GML2FeatureResponseDelegate;
import org.vfny.geoserver.wfs.responses.GetFeatureResults;
import org.vfny.geoserver.wms.requests.GetFeatureInfoRequest;


/**
* A GetFeatureInfo response handler specialized in producing GML data for a
* GetFeatureInfo request.
*
* <p>
* This class does not deals directly with GML encoding. Instead, it works by
* taking the FeatureResults produced in <code>execute()</code> and constructs
* a <code>GetFeaturesResult</code> wich is passed to a
* <code>GML2FeatureResponseDelegate</code>, as if it where the result of a
* GetFeature WFS request.
* </p>
*
* @author Gabriel Roldan, Axios Engineering
*/
public class GmlFeatureInfoResponse extends AbstractFeatureInfoResponse {
    /**
     * The MIME type of the format this response produces:
     * <code>"application/vnd.ogc.gml"</code>
     */
    private static final String FORMAT = "application/vnd.ogc.gml";

    /**
     * Default constructor, sets up the supported output format string.
     */
    public GmlFeatureInfoResponse() {
        super.supportedFormats = Collections.singletonList(FORMAT);
    }

    /**
     * Takes the <code>FeatureResult</code>s generated by the
     * <code>execute</code> method in the superclass and constructs a
     * <code>GetFeaturesResult</code> wich is passed to a
     * <code>GML2FeatureResponseDelegate</code>.
     *
     * @param out DOCUMENT ME!
     *
     * @throws ServiceException DOCUMENT ME!
     * @throws IOException DOCUMENT ME!
     */
    public void writeTo(OutputStream out) throws ServiceException, IOException {
        GetFeatureInfoRequest fInfoReq = (GetFeatureInfoRequest) getRequest();
        FeatureRequest freq = new FeatureRequest();
        freq.setHttpServletRequest(fInfoReq.getHttpServletRequest());

        freq.setRequest("GETFEATURE");
        freq.setHandle("GetFeatureInfo");
        freq.setMaxFeatures(fInfoReq.getFeatureCount());

        List queries = null;
        freq.setQueries(queries);

        GetFeatureResults getFeatureResults = new GetFeatureResults(freq);
        FeatureTypeInfo finfo;
        FeatureResults fresults;
        int i = 0;

        for (Iterator it = results.iterator(); it.hasNext(); i++) {
            fresults = (FeatureResults) it.next();
            finfo = (FeatureTypeInfo) metas.get(i);
            getFeatureResults.addFeatures(finfo, fresults);
        }

        GML2FeatureResponseDelegate encoder = new GML2FeatureResponseDelegate();
        encoder.prepare("GML2", getFeatureResults);
        encoder.encode(out);
    }
}
TOP

Related Classes of org.vfny.geoserver.wms.responses.featureInfo.GmlFeatureInfoResponse

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.