Package org.geoserver.wfs.request

Examples of org.geoserver.wfs.request.GetFeatureRequest


        if (dft != null) {
            qualifyTypeNames(dft.getTypeNames(), workspace, ns);
            return;
        }
       
        GetFeatureRequest gf = GetFeatureRequest.adapt(
            OwsUtils.parameter(operation.getParameters(), EObject.class));
        if (gf != null) {
            for (Query q : gf.getQueries()) {
                qualifyTypeNames(q.getTypeNames(), workspace, ns);
            }
            return;
        }
       
View Full Code Here


        }
    }

    protected void write(FeatureCollectionResponse featureCollection, OutputStream output,
        Operation getFeature) throws IOException, ServiceException {
        GetFeatureRequest request = GetFeatureRequest.adapt(getFeature.getParameters()[0]);
       
        prepare(request.getOutputFormat(), featureCollection, request);
        encode(output, featureCollection, request );
    }
View Full Code Here

    public String getAttachmentFileName(Object value, Operation operation) {
        SimpleFeatureCollection fc = (SimpleFeatureCollection) ((FeatureCollectionResponse) value).getFeature().get(0);
        FeatureTypeInfo ftInfo = getFeatureTypeInfo(fc);
       
        String filename = null;
        GetFeatureRequest request = GetFeatureRequest.adapt(operation.getParameters()[0]);
        if (request != null) {
            Map<String, ?> formatOptions = request.getFormatOptions();
            filename = (String) formatOptions.get("FILENAME");
        }
        if (filename == null) {
            filename = new FileNameSource(getClass()).getZipName(ftInfo);
        }
View Full Code Here

     * @return the found charset, or the platform's default one if none was specified
     */
    private Charset getShapefileCharset(Operation getFeature) {
        Charset result = null;
       
        GetFeatureRequest gft = GetFeatureRequest.adapt(getFeature.getParameters()[0]);
        if(gft.getFormatOptions() != null && gft.getFormatOptions().get("CHARSET") != null) {
           result = (Charset) gft.getFormatOptions().get("CHARSET");
        } else {
            final String charsetName = GeoServerExtensions.getProperty(GS_SHAPEFILE_CHARSET, applicationContext);
            if(charsetName != null)
                result = Charset.forName(charsetName);
        }
View Full Code Here

    /**
     * @see WFSGetFeatureOutputFormat#getMimeType(Object, Operation)
     */
    public String getMimeType(Object value, Operation operation) throws ServiceException {
        GetFeatureRequest request = GetFeatureRequest.adapt(operation.getParameters()[0]);
        String outputFormat = request.getOutputFormat();
       
        OgrFormat format = formats.get(outputFormat);
        if (format == null) {
            throw new WFSException("Unknown output format " + outputFormat);
        } else if (format.singleFile && request.getQueries().size() <= 1) {
            if(format.mimeType != null) {
                return format.mimeType;
            } else {
                // use a default binary blob
                return "application/octet-stream";
View Full Code Here

        return DISPOSITION_ATTACH;
    }
   
    @Override
    public String getAttachmentFileName(Object value, Operation operation) {
        GetFeatureRequest request = GetFeatureRequest.adapt(operation.getParameters()[0]);
        String outputFormat = request.getOutputFormat();
       
        OgrFormat format = formats.get(outputFormat);
        List<Query> queries = request.getQueries();
        if (format == null) {
            throw new WFSException("Unknown output format " + outputFormat);
        } else if (!format.singleFile || queries.size() > 1) {
            String outputFileName = queries.get(0).getTypeNames().get(0).getLocalPart();
            return outputFileName + ".zip";
View Full Code Here

    @Override
    protected void write(FeatureCollectionResponse featureCollection, OutputStream output,
        Operation getFeature) throws IOException ,ServiceException {

        // figure out which output format we're going to generate
        GetFeatureRequest request = GetFeatureRequest.adapt(getFeature.getParameters()[0]);
        String outputFormat = request.getOutputFormat();

        OgrFormat format = formats.get(outputFormat);
        if (format == null)
            throw new WFSException("Unknown output format " + outputFormat);
View Full Code Here

    protected void write(FeatureCollectionResponse results, OutputStream output, Operation getFeature)
        throws ServiceException, IOException {
       
        //declare wfs schema location
        GetFeatureRequest gft = GetFeatureRequest.adapt(getFeature.getParameters()[0]);
       
        List featureCollections = results.getFeature();

        //round up the info objects for each feature collection
        MultiHashMap ns2metas = new MultiHashMap();
       
        for (Iterator fc = featureCollections.iterator(); fc.hasNext();) {
            SimpleFeatureCollection features = (SimpleFeatureCollection) fc.next();
            SimpleFeatureType featureType = features.getSchema();

            //load the metadata for the feature type
            String namespaceURI = featureType.getName().getNamespaceURI();
            FeatureTypeInfo meta = catalog.getFeatureTypeByName( namespaceURI, featureType.getTypeName() );
            if(meta == null)
                throw new WFSException(gft, "Could not find feature type " + namespaceURI + ":"
                    + featureType.getTypeName() + " in the GeoServer catalog");

            NamespaceInfo ns = catalog.getNamespaceByURI( namespaceURI );
            ns2metas.put( ns, meta );
        }

        Collection<FeatureTypeInfo> featureTypes = ns2metas.values();
       
        //create the encoder
        ApplicationSchemaXSD xsd = new ApplicationSchemaXSD( null, catalog, gft.getBaseUrl(),
            org.geotools.wfs.v1_0.WFS.getInstance(), featureTypes );
        Configuration configuration = new ApplicationSchemaConfiguration( xsd, new org.geotools.wfs.v1_0.WFSConfiguration() );
       
        Encoder encoder = new Encoder(configuration);
        //encoder.setEncoding(wfs.getCharSet());
       
       encoder.setSchemaLocation(org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE,
               buildSchemaURL(gft.getBaseUrl(), "wfs/1.0.0/WFS-basic.xsd"));

        //declare application schema namespaces
        Map<String, String> params = params("service", "WFS", "version", "1.0.0", "request", "DescribeFeatureType");
        for (Iterator i = ns2metas.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();

            NamespaceInfo ns = (NamespaceInfo) entry.getKey();
            String namespaceURI = ns.getURI();
           
            Collection metas = (Collection) entry.getValue();

            StringBuffer typeNames = new StringBuffer();

            for (Iterator m = metas.iterator(); m.hasNext();) {
                FeatureTypeInfo meta = (FeatureTypeInfo) m.next();
                typeNames.append(meta.getPrefixedName());

                if (m.hasNext()) {
                    typeNames.append(",");
                }
            }

            //set the schema location
            params.put("typeName", typeNames.toString());
            encoder.setSchemaLocation(namespaceURI,
                    buildURL(gft.getBaseUrl(), "wfs", params, URLType.RESOURCE));
        }

        encoder.encode(results.getAdaptee(), org.geotools.wfs.v1_0.WFS.FeatureCollection, output);
    }
View Full Code Here

        return DISPOSITION_ATTACH;
    }
   
    @Override
    public String getAttachmentFileName(Object value, Operation operation) {
        GetFeatureRequest request = GetFeatureRequest.adapt(operation.getParameters()[0]);
        String outputFileName = request.getQueries().get(0).getTypeNames().get(0).getLocalPart();
        return outputFileName + ".csv";
    }
View Full Code Here

    protected void write(FeatureCollectionResponse results, OutputStream output, Operation getFeature)
            throws ServiceException, IOException, UnsupportedEncodingException {
        List featureCollections = results.getFeature();

        GetFeatureRequest request = GetFeatureRequest.adapt(getFeature.getParameters()[0]);

        // round up the info objects for each feature collection
        HashMap<String, Set<ResourceInfo>> ns2metas = new HashMap<String, Set<ResourceInfo>>();
        for (int fcIndex = 0; fcIndex < featureCollections.size(); fcIndex++) {
            if(request != null) {
                List<Query> queries = request.getQueries();
                Query queryType = queries.get(fcIndex);
               
                // may have multiple type names in each query, so add them all
                for (QName name : queryType.getTypeNames()) {
                    // get a feature type name from the query
                    Name featureTypeName = new NameImpl(name.getNamespaceURI(), name.getLocalPart());
                    ResourceInfo meta = catalog.getResourceByName(featureTypeName, ResourceInfo.class);
                   
                    if (meta == null) {
                        throw new WFSException(request, "Could not find feature type " + featureTypeName
                                + " in the GeoServer catalog");
                    }
                   
                    // add it to the map
                    Set<ResourceInfo> metas = ns2metas.get(featureTypeName.getNamespaceURI());
                   
                    if (metas == null) {
                        metas = new HashSet<ResourceInfo>();
                        ns2metas.put(featureTypeName.getNamespaceURI(), metas);
                    }
                    metas.add(meta);
                }
            } else {
                FeatureType featureType = ((FeatureCollection) featureCollections.get(fcIndex)).getSchema();

                //load the metadata for the feature type
                String namespaceURI = featureType.getName().getNamespaceURI();
                FeatureTypeInfo meta = catalog.getFeatureTypeByName(featureType.getName());
               
                if(meta == null)
                    throw new WFSException(request, "Could not find feature type " +
                        featureType.getName() + " in the GeoServer catalog");

                //add it to the map
                Set metas = (Set) ns2metas.get(namespaceURI);

                if (metas == null) {
                    metas = new HashSet();
                    ns2metas.put(namespaceURI, metas);
                }

                metas.add(meta);
            }
        }

        WFSInfo wfs = getInfo();
       
        //set feature bounding parameter
        //JD: this is quite bad as its not at all thread-safe, once we remove the configuration
        // as being a singleton on trunk/2.0.x this should not be an issue
        if ( wfs.isFeatureBounding() ) {
            configuration.getProperties().remove( GMLConfiguration.NO_FEATURE_BOUNDS );
        }
        else {
            configuration.getProperties().add( GMLConfiguration.NO_FEATURE_BOUNDS);
        }

        if (wfs.isCiteCompliant()) {
            //cite compliance forces us to forgo srsDimension attribute
            configuration.getProperties().add(GMLConfiguration.NO_SRS_DIMENSION);
        }
        else {
            configuration.getProperties().remove(GMLConfiguration.NO_SRS_DIMENSION);
        }

        //set up the srsname syntax
        configuration.setSrsSyntax(wfs.getGML().get(WFSInfo.Version.V_11).getSrsNameStyle().toSrsSyntax());

        /*
         * Set property encoding featureMemeber as opposed to featureMembers
         *
         */
        if (wfs.isEncodeFeatureMember()) {
            configuration.getProperties().add(GMLConfiguration.ENCODE_FEATURE_MEMBER);
        } else {
            configuration.getProperties().remove(GMLConfiguration.ENCODE_FEATURE_MEMBER);
        }
       
        //declare wfs schema location
        Object gft = getFeature.getParameters()[0];
       
        Encoder encoder = createEncoder(configuration, ns2metas, gft);
        encoder.setEncoding(Charset.forName( geoServer.getSettings().getCharset() ));

        if (wfs.isCanonicalSchemaLocation()) {
            encoder.setSchemaLocation(getWfsNamespace(), getCanonicalWfsSchemaLocation());
        } else {
            encoder.setSchemaLocation(getWfsNamespace(),
                    buildSchemaURL(request.getBaseURL(), getRelativeWfsSchemaLocation()));
        }

        //declare application schema namespaces
       
        Map<String, String> params = params("service", "WFS", "version", request.getVersion(),
                "request", "DescribeFeatureType");
        for (Iterator i = ns2metas.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();

            String namespaceURI = (String) entry.getKey();
            Set metas = (Set) entry.getValue();

            StringBuffer typeNames = new StringBuffer();
            for (Iterator m = metas.iterator(); m.hasNext();) {
                ResourceInfo ri = (ResourceInfo) m.next();
                if(ri instanceof FeatureTypeInfo) {
                    FeatureTypeInfo meta = (FeatureTypeInfo) ri;
                    FeatureType featureType = meta.getFeatureType();
                    Object userSchemaLocation = featureType.getUserData().get("schemaURI");
                    if (userSchemaLocation != null && userSchemaLocation instanceof Map) {
                        Map<String, String> schemaURIs = (Map<String, String>) userSchemaLocation;
                        for (String namespace : schemaURIs.keySet()) {
                            encoder.setSchemaLocation(namespace, schemaURIs.get(namespace));
                        }
                    } else {
                        typeNames.append(meta.getPrefixedName());
                        if (m.hasNext()) {
                            typeNames.append(",");
                        }
                    }
                }
            }

            if (typeNames.length() > 0) {
                params.put("typeName", typeNames.toString());
                // set the made up schema location for types not provided by the user
                String schemaLocation = buildURL(request.getBaseURL(), "wfs", params, URLType.SERVICE);
                LOGGER.finer("Unable to find user-defined schema location for: " + namespaceURI
                        + ". Using a built schema location by default: " + schemaLocation);
                encoder.setSchemaLocation(namespaceURI, schemaLocation);
            }
        }
View Full Code Here

TOP

Related Classes of org.geoserver.wfs.request.GetFeatureRequest

Copyright © 2018 www.massapicom. 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.