KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > databinding > datagrid > runtime > util > JspFunctions


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.databinding.datagrid.runtime.util;
19
20 import java.util.List JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Map JavaDoc;
23 import javax.servlet.jsp.JspContext JavaDoc;
24
25 import org.apache.beehive.netui.databinding.datagrid.api.DataGridConfigFactory;
26 import org.apache.beehive.netui.databinding.datagrid.api.DataGridURLBuilder;
27 import org.apache.beehive.netui.databinding.datagrid.api.filter.Filter;
28 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel;
29 import org.apache.beehive.netui.databinding.datagrid.api.sort.Sort;
30 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortDirection;
31
32 /**
33  * <p>
34  * This class contains utility methods that are callable as JSP functions by page authors. These are used
35  * to provide utility methods that can be accessed via JSP EL for invoking methods on various data grid
36  * state objects.
37  * </p>
38  * @netui:jspfunctions
39  */

40 public final class JspFunctions {
41
42     private JspFunctions() {}
43
44     /**
45      * Given a sort expression, check to see if the sort expression is sorted ascending in a data grid's
46      * {@link SortModel}.
47      * @param sortModel a grid's sort model
48      * @param sortExpression the sort expression
49      * @return return <code>true</code> if a {@link Sort} is found whose sort expression
50      * matches the sort expression given here and whose direction is {@link SortDirection#ASCENDING}.
51      * @netui:jspfunction name="isSortedAscending"
52      * signature="boolean isSortedAscending(org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel,java.lang.String)"
53      */

54     public static boolean isSortedAscending(SortModel sortModel, String JavaDoc sortExpression) {
55         if(sortModel == null || sortExpression == null)
56             return false;
57
58         Sort sort = sortModel.lookupSort(sortExpression);
59         if(sort != null && sort.getDirection() == SortDirection.ASCENDING)
60             return true;
61         else return false;
62     }
63
64     /**
65      * Given a sort expression, check to see if the sort expression is sorted descending in a data grid's
66      * {@link SortModel}.
67      * @param sortModel a grid's sort model
68      * @param sortExpression the sort expression
69      * @return return <code>true</code> if a {@link Sort} is found whose sort expression
70      * matches the sort expression given here and whose direction is {@link SortDirection#DESCENDING}.
71      * @netui:jspfunction name="isSortedDescending"
72      * signature="boolean isSortedDescending(org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel,java.lang.String)"
73      */

74     public static boolean isSortedDescending(SortModel sortModel, String JavaDoc sortExpression) {
75         if(sortModel == null || sortExpression == null)
76             return false;
77
78         Sort sort = sortModel.lookupSort(sortExpression);
79         if(sort != null && sort.getDirection() == SortDirection.DESCENDING)
80             return true;
81         else return false;
82     }
83
84     /**
85      * <p>
86      * Utility method used to build a query parameter map which includes the list of parameters needed to change the
87      * direction of a sort related to the given sort expression. This method uses a {@link DataGridURLBuilder}
88      * instance to call its {@link DataGridURLBuilder#buildSortQueryParamsMap(String)} method from JSP EL.
89      * </p>
90      * @param urlBuilder the data grid URL builder associated with a
91      * {@link org.apache.beehive.netui.databinding.datagrid.api.DataGridState} object that is used to
92      * build lists of query parameters
93      * @param sortExpression the sort expression whose direction to change
94      * @return a {@link Map} of key / value pairs for query parameters
95      * @netui:jspfunction name="buildQueryParamsMapForSortExpression"
96      * signature="java.util.Map buildQueryParamsMapForSortExpression(org.apache.beehive.netui.databinding.datagrid.api.DataGridURLBuilder,java.lang.String)"
97      */

98     public static Map JavaDoc buildQueryParamsMapForSortExpression(DataGridURLBuilder urlBuilder, String JavaDoc sortExpression) {
99         if(urlBuilder == null || sortExpression == null)
100             return null;
101
102         return urlBuilder.buildSortQueryParamsMap(sortExpression);
103     }
104 }
105
Popular Tags