View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.kns.util;
17  
18  import org.apache.commons.lang.NumberUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.core.api.util.collect.CollectionUtils;
21  
22  import java.util.Enumeration;
23  
24  /**
25   * Utility for that is used along with the tableRenderPagingBanner.tag.
26   * 
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   *
29   */
30  public final class PagingBannerUtils {
31  
32  	/** do not call. */
33  	private PagingBannerUtils() {
34  		throw new UnsupportedOperationException("do not call");
35  	}
36  	
37      /**
38       * find the number string in a method to call parameter with the following format parameterPrefix.1 or
39       * parameterPrefix.1.bleh
40       * 
41       * @param paramPrefix the 
42       * @param parameterNames the parameter names.
43       * @return the numerical value or -1
44       */
45      public static int getNumbericalValueAfterPrefix(String paramPrefix, Enumeration<String> parameterNames) {
46              	
47      	for (String parameterName : CollectionUtils.toIterable(parameterNames)) {
48      		if (parameterName.startsWith(paramPrefix)) {
49              	parameterName = WebUtils.endsWithCoordinates(parameterName) ? parameterName : parameterName + ".x";
50              	String numberStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
51              	if (NumberUtils.isDigits(numberStr)) {
52              		return Integer.parseInt(numberStr);
53              	}
54              }
55          }
56  
57      	return -1;
58      }
59  
60      /**
61       * same as method above except for use when it is not feasible to use ordinals to identify columns -- for example,
62       * if dynamic attributes may be used
63       */
64      public static String getStringValueAfterPrefix(String paramPrefix, Enumeration<String> parameterNames) {
65          for (String parameterName : CollectionUtils.toIterable(parameterNames)) {
66              if (parameterName.startsWith(paramPrefix)) {
67                  parameterName = WebUtils.endsWithCoordinates(parameterName) ? parameterName : parameterName + ".x";
68                  return StringUtils.substringBetween(parameterName, paramPrefix, ".");
69              }
70          }
71  
72          return "";
73      }
74  }