001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kns.util;
017
018import org.apache.commons.lang.NumberUtils;
019import org.apache.commons.lang.StringUtils;
020import org.kuali.rice.core.api.util.collect.CollectionUtils;
021
022import java.util.Enumeration;
023
024/**
025 * Utility for that is used along with the tableRenderPagingBanner.tag.
026 * 
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 *
029 */
030public final class PagingBannerUtils {
031
032        /** do not call. */
033        private PagingBannerUtils() {
034                throw new UnsupportedOperationException("do not call");
035        }
036        
037    /**
038     * find the number string in a method to call parameter with the following format parameterPrefix.1 or
039     * parameterPrefix.1.bleh
040     * 
041     * @param paramPrefix the 
042     * @param parameterNames the parameter names.
043     * @return the numerical value or -1
044     */
045    public static int getNumbericalValueAfterPrefix(String paramPrefix, Enumeration<String> parameterNames) {
046                
047        for (String parameterName : CollectionUtils.toIterable(parameterNames)) {
048                if (parameterName.startsWith(paramPrefix)) {
049                parameterName = WebUtils.endsWithCoordinates(parameterName) ? parameterName : parameterName + ".x";
050                String numberStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
051                if (NumberUtils.isDigits(numberStr)) {
052                        return Integer.parseInt(numberStr);
053                }
054            }
055        }
056
057        return -1;
058    }
059
060    /**
061     * same as method above except for use when it is not feasible to use ordinals to identify columns -- for example,
062     * if dynamic attributes may be used
063     */
064    public static String getStringValueAfterPrefix(String paramPrefix, Enumeration<String> parameterNames) {
065        for (String parameterName : CollectionUtils.toIterable(parameterNames)) {
066            if (parameterName.startsWith(paramPrefix)) {
067                parameterName = WebUtils.endsWithCoordinates(parameterName) ? parameterName : parameterName + ".x";
068                return StringUtils.substringBetween(parameterName, paramPrefix, ".");
069            }
070        }
071
072        return "";
073    }
074}