01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.wfs.kvp;
06:
07: import org.geoserver.ows.NestedKvpParser;
08: import org.opengis.filter.FilterFactory;
09: import org.opengis.filter.sort.SortBy;
10: import org.opengis.filter.sort.SortOrder;
11:
12: /**
13: * Parses kvp of the form 'sortBy=Field1 {A|D},Field2 {A|D}...' into a
14: * list of {@link org.opengis.filter.sort.SortBy}.
15: *
16: * @author Justin Deoliveira, The Open Planning Project
17: *
18: */
19: public class SortByKvpParser extends NestedKvpParser {
20: FilterFactory filterFactory;
21:
22: public SortByKvpParser(FilterFactory filterFactory) {
23: super ("sortBy", SortBy.class);
24: this .filterFactory = filterFactory;
25: }
26:
27: /**
28: * Parses a token of the form 'Field1 {A|D}' into an instnace of
29: * {@link SortBy}.
30: */
31: protected Object parseToken(String token) throws Exception {
32: String[] nameOrder = token.split(" ");
33: String propertyName = nameOrder[0];
34:
35: SortOrder order = SortOrder.ASCENDING;
36:
37: if (nameOrder.length > 1) {
38: if ("D".equalsIgnoreCase(nameOrder[1])) {
39: order = SortOrder.DESCENDING;
40: }
41: }
42:
43: return filterFactory.sort(propertyName, order);
44: }
45: }
|