Package org.geoserver.wfs.kvp

Source Code of org.geoserver.wfs.kvp.SortByKvpParser

/* Copyright (c) 2001 - 2007 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.geoserver.wfs.kvp;

import org.geoserver.ows.NestedKvpParser;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.sort.SortBy;
import org.opengis.filter.sort.SortOrder;


/**
* Parses kvp of the form 'sortBy=Field1 {A|D},Field2 {A|D}...' into a
* list of {@link org.opengis.filter.sort.SortBy}.
*
* @author Justin Deoliveira, The Open Planning Project
*
*/
public class SortByKvpParser extends NestedKvpParser {
    FilterFactory filterFactory;

    public SortByKvpParser(FilterFactory filterFactory) {
        super("sortBy", SortBy.class);
        this.filterFactory = filterFactory;
    }

    /**
     * Parses a token of the form 'Field1 {A|D}' into an instnace of
     * {@link SortBy}.
     */
    protected Object parseToken(String token) throws Exception {
        String[] nameOrder = token.split(" ");
        String propertyName = nameOrder[0];

        SortOrder order = SortOrder.ASCENDING;

        if (nameOrder.length > 1) {
            if ("D".equalsIgnoreCase(nameOrder[1])) {
                order = SortOrder.DESCENDING;
            }
        }

        return filterFactory.sort(propertyName, order);
    }
}
TOP

Related Classes of org.geoserver.wfs.kvp.SortByKvpParser

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.