001/**
002 * Copyright 2005-2018 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 * @deprecated Only used in KNS classes, use KRAD.
030 */
031@Deprecated
032public final class PagingBannerUtils {
033
034        /** do not call. */
035        private PagingBannerUtils() {
036                throw new UnsupportedOperationException("do not call");
037        }
038        
039    /**
040     * find the number string in a method to call parameter with the following format parameterPrefix.1 or
041     * parameterPrefix.1.bleh
042     * 
043     * @param paramPrefix the 
044     * @param parameterNames the parameter names.
045     * @return the numerical value or -1
046     */
047    public static int getNumbericalValueAfterPrefix(String paramPrefix, Enumeration<String> parameterNames) {
048                
049        for (String parameterName : CollectionUtils.toIterable(parameterNames)) {
050                if (parameterName.startsWith(paramPrefix)) {
051                parameterName = WebUtils.endsWithCoordinates(parameterName) ? parameterName : parameterName + ".x";
052                String numberStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
053                if (NumberUtils.isDigits(numberStr)) {
054                        return Integer.parseInt(numberStr);
055                }
056            }
057        }
058
059        return -1;
060    }
061
062    /**
063     * same as method above except for use when it is not feasible to use ordinals to identify columns -- for example,
064     * if dynamic attributes may be used
065     */
066    public static String getStringValueAfterPrefix(String paramPrefix, Enumeration<String> parameterNames) {
067        for (String parameterName : CollectionUtils.toIterable(parameterNames)) {
068            if (parameterName.startsWith(paramPrefix)) {
069                parameterName = WebUtils.endsWithCoordinates(parameterName) ? parameterName : parameterName + ".x";
070                return StringUtils.substringBetween(parameterName, paramPrefix, ".");
071            }
072        }
073
074        return "";
075    }
076}