⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 limitfactory.java

📁 exTreme taglib的使用
💻 JAVA
字号:
/* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *    http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.extremecomponents.table.limit;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;import javax.servlet.ServletRequest;import org.apache.commons.lang.StringUtils;import org.extremecomponents.table.core.TableConstants;/** * @author Jeff Johnston */public final class LimitFactory {    public static Limit createInstanceOfLimit(ServletRequest request, String tableId) {        return new RequestLimit(request, tableId);    }    public static void setLimitFilterAndSortAttr(Limit limit) {        limit.setFilterSet(getFilterSet((RequestLimit)limit));        limit.setSort(getSort((RequestLimit)limit));    }        public static void setLimitPageAndRowAttr(Limit limit, int defaultRowsDisplayed, int totalRows) {        int currentRowsDisplayed = resolveCurrentRowsDisplayed((RequestLimit)limit, defaultRowsDisplayed);        int page = getPage((RequestLimit)limit);        int rowStart = (page - 1) * currentRowsDisplayed;        int rowEnd = rowStart + currentRowsDisplayed;        if (rowEnd > totalRows) {            rowEnd = totalRows;        }        limit.setPage(page);        limit.setCurrentRowsDisplayed(currentRowsDisplayed);        limit.setTotalRows(totalRows);        limit.setRowStart(rowStart);        limit.setRowEnd(rowEnd);    }    private static int resolveCurrentRowsDisplayed(RequestLimit limit, int defaultRowsDisplayed) {        String currentRowsDisplayed = limit.getRequest().getParameter(limit.getTableId() + "_" + TableConstants.CURRENT_ROWS_DISPLAYED);        if (StringUtils.isNotEmpty(currentRowsDisplayed)) {            return Integer.parseInt(currentRowsDisplayed);        }        return defaultRowsDisplayed;    }    private static int getPage(RequestLimit limit) {        String pagination = limit.getRequest().getParameter(limit.getTableId() + "_" + TableConstants.PAGE);        if (!StringUtils.isEmpty(pagination)) {            return Integer.parseInt(pagination);        }        return 1;    }    private static Sort getSort(RequestLimit limit) {        Map sortedParameters = getSortedOrFilteredParameters(limit, TableConstants.SORT);        return LimitFactoryUtils.getSort(sortedParameters);    }    private static FilterSet getFilterSet(RequestLimit limit) {        Map filteredParameters = getSortedOrFilteredParameters(limit, TableConstants.FILTER);        return LimitFactoryUtils.getFilterSet(filteredParameters);    }    private static Map getSortedOrFilteredParameters(RequestLimit limit, String parameter) {        Map subset = new HashMap();        Set set = limit.getRequest().getParameterMap().keySet();        String find = limit.getTableId() + "_" + parameter;        for (Iterator iter = set.iterator(); iter.hasNext();) {            String key = (String) iter.next();            if (key.startsWith(find)) {                String value = limit.getRequest().getParameter(key);                if (StringUtils.isNotBlank(value)) {                    subset.put(StringUtils.substringAfter(key, find), value);                }            }        }        return subset;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -