Package org.vfny.geoserver.wfs.requests

Examples of org.vfny.geoserver.wfs.requests.FeatureRequest


    public void prepare(String outputFormat, GetFeatureResults results)
        throws IOException {
        this.compressOutput = formatNameCompressed.equalsIgnoreCase(outputFormat);
        this.results = results;

        FeatureRequest request = results.getRequest();
        GeoServer config = request.getWFS().getGeoServer();
        transformer = new FeatureTransformer();

        FeatureTypeNamespaces ftNames = transformer.getFeatureTypeNamespaces();
        int maxFeatures = request.getMaxFeatures();
        int serverMaxFeatures = config.getMaxFeatures();

        if (maxFeatures > serverMaxFeatures) {
            maxFeatures = serverMaxFeatures;
        }

        StringBuffer typeNames = new StringBuffer();
        FeatureResults features;
        FeatureTypeInfo meta = null;
        NameSpaceInfo namespace;
        int resCount = results.getResultsetsCount();
        Map ftNamespaces = new HashMap(resCount);

        for (int resIndex = 0; resIndex < resCount; resIndex++) {
            features = results.getFeatures(resIndex);
            meta = results.getTypeInfo(resIndex);
            namespace = meta.getDataStoreInfo().getNameSpace();

            String uri = namespace.getUri();
            ftNames.declareNamespace(features.getSchema(),
                namespace.getPrefix(), uri);

            if (ftNamespaces.containsKey(uri)) {
                String location = (String) ftNamespaces.get(uri);
                ftNamespaces.put(uri, location + "," + meta.getName());
            } else {
                ftNamespaces.put(uri,
                    request.getBaseUrl() + "wfs/"
                    + "DescribeFeatureType?typeName=" + meta.getName());
            }
        }

        System.setProperty("javax.xml.transform.TransformerFactory",
            "org.apache.xalan.processor.TransformerFactoryImpl");

        transformer.setIndentation(config.isVerbose() ? INDENT_SIZE
                                                      : (NO_FORMATTING));
        transformer.setNumDecimals(config.getNumDecimals());
        transformer.setFeatureBounding(request.getWFS().isFeatureBounding());
        transformer.setEncoding(request.getWFS().getGeoServer().getCharSet());

        String wfsSchemaLoc = request.getSchemaBaseUrl()
            + "wfs/1.0.0/WFS-basic.xsd";

        transformer.addSchemaLocation("http://www.opengis.net/wfs", wfsSchemaLoc);

        for (Iterator it = ftNamespaces.keySet().iterator(); it.hasNext();) {
            String uri = (String) it.next();
            transformer.addSchemaLocation(uri, (String) ftNamespaces.get(uri));
        }

        transformer.setGmlPrefixing(request.getWFS().getCiteConformanceHacks());

        FeatureLock featureLock = results.getFeatureLock();

        if (featureLock != null) {
            transformer.setLockId(featureLock.getAuthorization());
        }

        transformer.setSrsName(request.getWFS().getSrsPrefix() + meta.getSRS());
    }
View Full Code Here


     * @throws WfsException If no typename or featureid is present, or if the
     *         filter list size doesn't match the feature list size.
     */
    public FeatureRequest getRequest(boolean withLock, HttpServletRequest srequest)
        throws WfsException {
        FeatureRequest currentRequest = new FeatureRequest();
        currentRequest.setHttpServletRequest(srequest);

        boolean useLock = false;

        if (withLock || keyExists("REQUEST")) {
            String request = getValue("REQUEST");
            useLock = withLock
                || request.equalsIgnoreCase("GETFEATUREWITHLOCK");

            if (useLock) {
                currentRequest = new FeatureWithLockRequest();
            }

            currentRequest.setRequest(request);
        }

        // set global request parameters
        LOGGER.finest("setting global request parameters");

        if (keyExists("MAXFEATURES")) {
            currentRequest.setMaxFeatures(getValue("MAXFEATURES"));
        }

        if (keyExists("VERSION")) {
            currentRequest.setVersion(getValue("VERSION"));
        }

        if (keyExists("REQUEST")) {
            currentRequest.setRequest(getValue("REQUEST"));
        }

        if (keyExists("FEATUREVERSION")) {
            currentRequest.setFeatureVersion(getValue("FEATUREVERSION"));
        }

        if (keyExists("OUTPUTFORMAT")) {
            currentRequest.setOutputFormat(getValue("OUTPUTFORMAT"));
        }

        if (useLock && keyExists("EXPIRY")) {
            ((FeatureWithLockRequest) currentRequest).setExpiry(Integer
                .parseInt(getValue("EXPIRY")));
        }

        // declare tokenizers for repeating elements
        LOGGER.finest("setting query request parameters");

        List typeList = readFlat(getValue("TYPENAME"), INNER_DELIMETER);
        List propertyList = readNested(getValue("PROPERTYNAME"));
        String fidKvps = getValue("FEATUREID");
        List filterList = readFilters(fidKvps, getValue("FILTER"),
                getValue("BBOX"));

        int propertySize = propertyList.size();
        int filterSize = filterList.size();

        if (typeList.size() == 0) {
            typeList = getTypesFromFids(fidKvps);

            if (typeList.size() == 0) {
                throw new WfsException("The typename element is mandatory if "
                    + "no FEATUREID is present");
            }
        }

        int featureSize = typeList.size();

        // check for errors in the request
        if (((propertySize != featureSize) && (propertySize > 1))
                || ((filterSize != featureSize) && (filterSize > 1))) {
            throw new WfsException("Properties or filter sizes do not match"
                + " feature types.  Property size: " + propertySize
                + " Filter size: " + filterSize + " Feature size: "
                + featureSize);
        } else {
            // loops through feature types, and creates queries based on them
            LOGGER.finest("setting query request parameters");

            for (int i = 0; i < featureSize; i++) {
                String featureType = (String) typeList.get(i);
                List properties;
                Filter filter;

                // permissive logic: lets one property list apply to all types
                LOGGER.finest("setting properties: " + i);

                if (propertySize == 0) {
                    properties = null;
                } else if (propertySize == 1) {
                    properties = (List) propertyList.get(0);
                } else {
                    properties = (List) propertyList.get(i);
                }

                // permissive logic: lets one filter apply to all types
                LOGGER.finest("setting filters: " + i);

                if (filterSize == 0) {
                    filter = null;
                } else if (filterSize == 1) {
                    filter = (Filter) filterList.get(0);
                } else {
                    filter = (Filter) filterList.get(i);
                }

                LOGGER.finest("query filter: " + filter);

                // add query
                currentRequest.addQuery(makeQuery(featureType, properties,
                        filter));
            }

            return currentRequest;
        }
View Full Code Here

     * @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;
View Full Code Here

        Query query = new Query();
        query.setTypeName("rail");
        query.addFilter(filter);

        FeatureRequest baseRequest = new FeatureRequest();
        baseRequest.setVersion("1.0.0");
        baseRequest.addQuery(query);

        // run test      
        assertTrue(runKvpTest(baseRequest, testRequest, true));
    }
View Full Code Here

    public void test15() throws Exception {
        String testRequest = "VERSION=1.0.0&" + "SERVICE=WFS&"
            + "REQUEST=GETFEATURE&" + "TYPENAME=rail,roads";

        // make base comparison objects       
        FeatureRequest baseRequest = new FeatureRequest();
        Query query = new Query();
        query.setTypeName("rail");
        baseRequest.addQuery(query);

        query = new Query();
        query.setTypeName("roads");
        baseRequest.addQuery(query);

        baseRequest.setVersion("1.0.0");

        // run test      
        assertTrue(runKvpTest(baseRequest, testRequest, true));
    }
View Full Code Here

        String testRequest = "VERSION=1.0.0&" + "SERVICE=WFS&"
            + "REQUEST=GETFEATURE&" + "PROPERTYNAME=(loc1,id1)(*)&"
            + "TYPENAME=rail,roads";

        // make base comparison objects       
        FeatureRequest baseRequest = new FeatureRequest();
        Query query = new Query();
        query.setTypeName("rail");
        query.addPropertyName("loc1");
        query.addPropertyName("id1");
        baseRequest.addQuery(query);

        query = new Query();
        query.setTypeName("roads");
        baseRequest.addQuery(query);

        baseRequest.setVersion("1.0.0");

        // run test      
        assertTrue(runKvpTest(baseRequest, testRequest, true));
    }
View Full Code Here

            + "REQUEST=GETFEATURE&" +
            //"TYPENAME=rail&" +
            "FEATUREID=rail.123,rail.456";

        // make base comparison objects       
        FeatureRequest baseRequest = new FeatureRequest();
        baseRequest.setVersion("1.0.0");

        FidFilter filter = factory.createFidFilter("rail.123");
        FidFilter filter2 = factory.createFidFilter("rail.456");
        Query query = new Query();
        query.setTypeName("rail");
        query.addFilter(filter);
        baseRequest.addQuery(query);
        query = new Query();
        query.setTypeName("rail");
        query.addFilter(filter2);
        baseRequest.addQuery(query);

        // run test      
        assertTrue(runKvpTest(baseRequest, testRequest, true));
    }
View Full Code Here

            + "REQUEST=GETFEATURE&" +
            //     "TYPENAME=rail1,rail2&" +
            "PROPERTYNAME=(loc1,id1)(loc2)&" + "FEATUREID=rail1.123,rail2.456";

        // make base comparison objects       
        FeatureRequest baseRequest = new FeatureRequest();
        baseRequest.setVersion("1.0.0");

        FidFilter filter = factory.createFidFilter("rail1.123");
        FidFilter filter2 = factory.createFidFilter("rail2.456");
        Query query = new Query();
        query.setTypeName("rail1");
        query.addFilter(filter);
        query.addPropertyName("loc1");
        query.addPropertyName("id1");
        baseRequest.addQuery(query);
        query = new Query();
        query.setTypeName("rail2");
        query.addFilter(filter2);
        query.addPropertyName("loc2");
        baseRequest.addQuery(query);
        query = new Query();

        // run test      
        assertTrue(runKvpTest(baseRequest, testRequest, true));
    }
View Full Code Here

    public void test19() throws Exception {
        String testRequest = "VERSION=1.0.0&" + "SERVICE=WFS&"
            + "REQUEST=GETFEATURE&" + "TYPENAME=rail,roads&"
            + "FILTER=(<Filter xmlns:gml='http://www.opengis.net/gml'><Within><PropertyName>location</PropertyName><gml:Box><gml:coordinates>10,10 20,20</gml:coordinates></gml:Box></Within></Filter>)(<Filter xmlns:gml='http://www.opengis.net/gml'><Within><PropertyName>location</PropertyName><gml:Box><gml:coordinates>10,10 20,20</gml:coordinates></gml:Box></Within></Filter>)";

        FeatureRequest baseRequest = new FeatureRequest();
        baseRequest.setVersion("1.0.0");

        // make base comparison objects
        org.geotools.filter.GeometryFilter filter = factory
            .createGeometryFilter(AbstractFilter.GEOMETRY_WITHIN);
        AttributeExpression leftExpression = factory.createAttributeExpression((FeatureType)null,"location");
        //leftExpression.setAttributePath("location");

        // Creates coordinates for the linear ring
        Coordinate[] coords = new Coordinate[5];
        coords[0] = new Coordinate(10, 10);
        coords[1] = new Coordinate(10, 20);
        coords[2] = new Coordinate(20, 20);
        coords[3] = new Coordinate(20, 10);
        coords[4] = new Coordinate(10, 10);

        LinearRing outerShell = new LinearRing(coords, new PrecisionModel(), 0);
        Polygon polygon = new Polygon(outerShell, new PrecisionModel(), 0);
        LiteralExpression rightExpression = factory.createLiteralExpression(polygon);
        filter.addLeftGeometry(leftExpression);
        filter.addRightGeometry(rightExpression);

        Query query = new Query();
        query.setTypeName("rail");
        query.addFilter(filter);
        baseRequest.addQuery(query);

        query = new Query();
        query.setTypeName("roads");
        query.addFilter(filter);
        baseRequest.addQuery(query);

        // run test      
        assertTrue(runKvpTest(baseRequest, testRequest, true));
    }
View Full Code Here

        String testRequest = "VERSION=1.0.0&" + "SERVICE=WFS&"
            + "REQUEST=GETFEATURE&" + "TYPENAME=rail,roads&"
            + "PROPERTYNAME=(loc1,id1,cat1)(loc2)&"
            + "FILTER=(<Filter xmlns:gml='http://www.opengis.net/gml'><Within><PropertyName>location</PropertyName><gml:Box><gml:coordinates>10,10 20,20</gml:coordinates></gml:Box></Within></Filter>)(<Filter xmlns:gml='http://www.opengis.net/gml'><Within><PropertyName>location</PropertyName><gml:Box><gml:coordinates>10,10 20,20</gml:coordinates></gml:Box></Within></Filter>)";

        FeatureRequest baseRequest = new FeatureRequest();
        baseRequest.setVersion("1.0.0");

        // make base comparison objects
        org.geotools.filter.GeometryFilter filter = factory
            .createGeometryFilter(AbstractFilter.GEOMETRY_WITHIN);
        AttributeExpression leftExpression = factory.createAttributeExpression((FeatureType)null,"location");
       // leftExpression.setAttributePath("location");

        // Creates coordinates for the linear ring
        Coordinate[] coords = new Coordinate[5];
        coords[0] = new Coordinate(10, 10);
        coords[1] = new Coordinate(10, 20);
        coords[2] = new Coordinate(20, 20);
        coords[3] = new Coordinate(20, 10);
        coords[4] = new Coordinate(10, 10);

        LinearRing outerShell = new LinearRing(coords, new PrecisionModel(), 0);
        Polygon polygon = new Polygon(outerShell, new PrecisionModel(), 0);
        LiteralExpression rightExpression = factory.createLiteralExpression(polygon);
        filter.addLeftGeometry(leftExpression);
        filter.addRightGeometry(rightExpression);

        Query query = new Query();
        query.setTypeName("rail");
        query.addFilter(filter);
        query.addPropertyName("loc1");
        query.addPropertyName("id1");
        query.addPropertyName("cat1");
        baseRequest.addQuery(query);

        query = new Query();
        query.setTypeName("roads");
        query.addPropertyName("loc2");
        query.addFilter(filter);
        baseRequest.addQuery(query);

        // run test      
        assertTrue(runKvpTest(baseRequest, testRequest, true));
    }
View Full Code Here

TOP

Related Classes of org.vfny.geoserver.wfs.requests.FeatureRequest

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.