📄 tableproperties.java
字号:
/**
* Licensed under the Artistic License; you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://displaytag.sourceforge.net/license.html
*
* THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
package org.displaytag.properties;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
import org.apache.commons.lang.ClassUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.UnhandledException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.displaytag.Messages;
import org.displaytag.decorator.DecoratorFactory;
import org.displaytag.decorator.DefaultDecoratorFactory;
import org.displaytag.exception.FactoryInstantiationException;
import org.displaytag.exception.TablePropertiesLoadException;
import org.displaytag.localization.I18nResourceProvider;
import org.displaytag.localization.LocaleResolver;
import org.displaytag.util.DefaultRequestHelperFactory;
import org.displaytag.util.ReflectHelper;
import org.displaytag.util.RequestHelperFactory;
/**
* The properties used by the Table tags. The properties are loaded in the following order, in increasing order of
* priority. The locale of getInstance() is used to determine the locale of the property file to use; if the key
* required does not exist in the specified file, the key will be loaded from a more general property file.
* <ol>
* <li>First, from the TableTag.properties included with the DisplayTag distribution.</li>
* <li>Then, from the file displaytag.properties, if it is present; these properties are intended to be set by the user
* for sitewide application. Messages are gathered according to the Locale of the property file.</li>
* <li>Finally, if this class has a userProperties defined, all of the properties from that Properties object are
* copied in as well.</li>
* </ol>
* @author Fabrizio Giustina
* @author rapruitt
* @version $Revision: 987 $ ($Author: fgiust $)
*/
public final class TableProperties implements Cloneable
{
/**
* name of the default properties file name ("displaytag.properties").
*/
public static final String DEFAULT_FILENAME = "displaytag.properties"; //$NON-NLS-1$
/**
* The name of the local properties file that is searched for on the classpath. Settings in this file will override
* the defaults loaded from TableTag.properties.
*/
public static final String LOCAL_PROPERTIES = "displaytag"; //$NON-NLS-1$
/**
* property <code>export.banner</code>.
*/
public static final String PROPERTY_STRING_EXPORTBANNER = "export.banner"; //$NON-NLS-1$
/**
* property <code>export.banner.sepchar</code>.
*/
public static final String PROPERTY_STRING_EXPORTBANNER_SEPARATOR = "export.banner.sepchar"; //$NON-NLS-1$
/**
* property <code>export.decorated</code>.
*/
public static final String PROPERTY_BOOLEAN_EXPORTDECORATED = "export.decorated"; //$NON-NLS-1$
/**
* property <code>export.amount</code>.
*/
public static final String PROPERTY_STRING_EXPORTAMOUNT = "export.amount"; //$NON-NLS-1$
/**
* property <code>sort.amount</code>.
*/
public static final String PROPERTY_STRING_SORTAMOUNT = "sort.amount"; //$NON-NLS-1$
/**
* property <code>basic.show.header</code>.
*/
public static final String PROPERTY_BOOLEAN_SHOWHEADER = "basic.show.header"; //$NON-NLS-1$
/**
* property <code>basic.msg.empty_list</code>.
*/
public static final String PROPERTY_STRING_EMPTYLIST_MESSAGE = "basic.msg.empty_list"; //$NON-NLS-1$
/**
* property <code>basic.msg.empty_list_row</code>.
*/
public static final String PROPERTY_STRING_EMPTYLISTROW_MESSAGE = "basic.msg.empty_list_row"; //$NON-NLS-1$
/**
* property <code>basic.empty.showtable</code>.
*/
public static final String PROPERTY_BOOLEAN_EMPTYLIST_SHOWTABLE = "basic.empty.showtable"; //$NON-NLS-1$
/**
* property <code>paging.banner.placement</code>.
*/
public static final String PROPERTY_STRING_BANNER_PLACEMENT = "paging.banner.placement"; //$NON-NLS-1$
/**
* property <code>error.msg.invalid_page</code>.
*/
public static final String PROPERTY_STRING_PAGING_INVALIDPAGE = "error.msg.invalid_page"; //$NON-NLS-1$
/**
* property <code>paging.banner.item_name</code>.
*/
public static final String PROPERTY_STRING_PAGING_ITEM_NAME = "paging.banner.item_name"; //$NON-NLS-1$
/**
* property <code>paging.banner.items_name</code>.
*/
public static final String PROPERTY_STRING_PAGING_ITEMS_NAME = "paging.banner.items_name"; //$NON-NLS-1$
/**
* property <code>paging.banner.no_items_found</code>.
*/
public static final String PROPERTY_STRING_PAGING_NOITEMS = "paging.banner.no_items_found"; //$NON-NLS-1$
/**
* property <code>paging.banner.one_item_found</code>.
*/
public static final String PROPERTY_STRING_PAGING_FOUND_ONEITEM = "paging.banner.one_item_found"; //$NON-NLS-1$
/**
* property <code>paging.banner.all_items_found</code>.
*/
public static final String PROPERTY_STRING_PAGING_FOUND_ALLITEMS = "paging.banner.all_items_found"; //$NON-NLS-1$
/**
* property <code>paging.banner.some_items_found</code>.
*/
public static final String PROPERTY_STRING_PAGING_FOUND_SOMEITEMS = "paging.banner.some_items_found"; //$NON-NLS-1$
/**
* property <code>paging.banner.group_size</code>.
*/
public static final String PROPERTY_INT_PAGING_GROUPSIZE = "paging.banner.group_size"; //$NON-NLS-1$
/**
* property <code>paging.banner.onepage</code>.
*/
public static final String PROPERTY_STRING_PAGING_BANNER_ONEPAGE = "paging.banner.onepage"; //$NON-NLS-1$
/**
* property <code>paging.banner.first</code>.
*/
public static final String PROPERTY_STRING_PAGING_BANNER_FIRST = "paging.banner.first"; //$NON-NLS-1$
/**
* property <code>paging.banner.last</code>.
*/
public static final String PROPERTY_STRING_PAGING_BANNER_LAST = "paging.banner.last"; //$NON-NLS-1$
/**
* property <code>paging.banner.full</code>.
*/
public static final String PROPERTY_STRING_PAGING_BANNER_FULL = "paging.banner.full"; //$NON-NLS-1$
/**
* property <code>paging.banner.page.link</code>.
*/
public static final String PROPERTY_STRING_PAGING_PAGE_LINK = "paging.banner.page.link"; //$NON-NLS-1$
/**
* property <code>paging.banner.page.selected</code>.
*/
public static final String PROPERTY_STRING_PAGING_PAGE_SELECTED = "paging.banner.page.selected"; //$NON-NLS-1$
/**
* property <code>paging.banner.page.separator</code>.
*/
public static final String PROPERTY_STRING_PAGING_PAGE_SPARATOR = "paging.banner.page.separator"; //$NON-NLS-1$
/**
* property <code>factory.requestHelper</code>.
*/
public static final String PROPERTY_CLASS_REQUESTHELPERFACTORY = "factory.requestHelper"; //$NON-NLS-1$
/**
* property <code>factory.decorators</code>.
*/
public static final String PROPERTY_CLASS_DECORATORFACTORY = "factory.decorator"; //$NON-NLS-1$
/**
* property <code>locale.provider</code>.
*/
public static final String PROPERTY_CLASS_LOCALEPROVIDER = "locale.provider"; //$NON-NLS-1$
/**
* property <code>locale.resolver</code>.
*/
public static final String PROPERTY_CLASS_LOCALERESOLVER = "locale.resolver"; //$NON-NLS-1$
/**
* property <code>css.tr.even</code>: holds the name of the css class for even rows. Defaults to
* <code>even</code>.
*/
public static final String PROPERTY_CSS_TR_EVEN = "css.tr.even"; //$NON-NLS-1$
/**
* property <code>css.tr.odd</code>: holds the name of the css class for odd rows. Defaults to <code>odd</code>.
*/
public static final String PROPERTY_CSS_TR_ODD = "css.tr.odd"; //$NON-NLS-1$
/**
* property <code>css.table</code>: holds the name of the css class added to the main table tag. By default no
* css class is added.
*/
public static final String PROPERTY_CSS_TABLE = "css.table"; //$NON-NLS-1$
/**
* property <code>css.th.sortable</code>: holds the name of the css class added to the the header of a sortable
* column. By default no css class is added.
*/
public static final String PROPERTY_CSS_TH_SORTABLE = "css.th.sortable"; //$NON-NLS-1$
/**
* property <code>css.th.sorted</code>: holds the name of the css class added to the the header of a sorted
* column. Defaults to <code>sorted</code>.
*/
public static final String PROPERTY_CSS_TH_SORTED = "css.th.sorted"; //$NON-NLS-1$
/**
* property <code>css.th.ascending</code>: holds the name of the css class added to the the header of a column
* sorted in ascending order. Defaults to <code>order1</code>.
*/
public static final String PROPERTY_CSS_TH_SORTED_ASCENDING = "css.th.ascending"; //$NON-NLS-1$
/**
* property <code>css.th.descending</code>: holds the name of the css class added to the the header of a column
* sorted in descending order. Defaults to <code>order2</code>.
*/
public static final String PROPERTY_CSS_TH_SORTED_DESCENDING = "css.th.descending"; //$NON-NLS-1$
/**
* prefix used for all the properties related to export ("export"). The full property name is <code>export.</code>
* <em>[export type]</em><code>.</code><em>[property name]</em>
*/
public static final String PROPERTY_EXPORT_PREFIX = "export"; //$NON-NLS-1$
/**
* suffix used to set the export decorator property name. The full property name is <code>export.</code>
* <em>[export type]</em><code>.</code><em>decorator</em>
*/
public static final String PROPERTY_EXPORT_DECORATOR_SUFFIX = "decorator"; //$NON-NLS-1$
/**
* property <code>export.types</code>: holds the list of export available export types.
*/
public static final String PROPERTY_EXPORTTYPES = "export.types"; //$NON-NLS-1$
/**
* export property <code>label</code>.
*/
public static final String EXPORTPROPERTY_STRING_LABEL = "label"; //$NON-NLS-1$
/**
* export property <code>class</code>.
*/
public static final String EXPORTPROPERTY_STRING_CLASS = "class"; //$NON-NLS-1$
/**
* export property <code>include_header</code>.
*/
public static final String EXPORTPROPERTY_BOOLEAN_EXPORTHEADER = "include_header"; //$NON-NLS-1$
/**
* export property <code>filename</code>.
*/
public static final String EXPORTPROPERTY_STRING_FILENAME = "filename"; //$NON-NLS-1$
/**
* Property <code>pagination.sort.param</code>. If external pagination and sorting is used, it holds the name of
* the parameter used to hold the sort criterion in generated links
*/
public static final String PROPERTY_STRING_PAGINATION_SORT_PARAM = "pagination.sort.param"; //$NON-NLS-1$
/**
* Property <code>pagination.sortdirection.param</code>. If external pagination and sorting is used, it holds the
* name of the parameter used to hold the sort direction in generated links (asc or desc)
*/
public static final String PROPERTY_STRING_PAGINATION_SORT_DIRECTION_PARAM = "pagination.sortdirection.param"; //$NON-NLS-1$
/**
* Property <code>pagination.pagenumber.param</code>. If external pagination and sorting is used, it holds the
* name of the parameter used to hold the page number in generated links
*/
public static final String PROPERTY_STRING_PAGINATION_PAGE_NUMBER_PARAM = "pagination.pagenumber.param"; //$NON-NLS-1$
/**
* Property <code>pagination.searchid.param</code>. If external pagination and sorting is used, it holds the name
* of the parameter used to hold the search ID in generated links
*/
public static final String PROPERTY_STRING_PAGINATION_SEARCH_ID_PARAM = "pagination.searchid.param"; //$NON-NLS-1$
/**
* Property <code>pagination.sort.asc.value</code>. If external pagination and sorting is used, it holds the
* value of the parameter of the sort direction parameter for "ascending"
*/
public static final String PROPERTY_STRING_PAGINATION_ASC_VALUE = "pagination.sort.asc.value"; //$NON-NLS-1$
/**
* Property <code>pagination.sort.desc.value</code>. If external pagination and sorting is used, it holds the
* value of the parameter of the sort direction parameter for "descending"
*/
public static final String PROPERTY_STRING_PAGINATION_DESC_VALUE = "pagination.sort.desc.value"; //$NON-NLS-1$
/**
* Property <code>pagination.sort.skippagenumber</code>. If external pagination and sorting is used, it
* determines if the current page number must be added in sort links or not. If this property is true, it means that
* each click on a generated sort link will re-sort the list, and go back to the default page number. If it is
* false, each click on a generated sort link will re-sort the list, and ask the current page number.
*/
public static final String PROPERTY_BOOLEAN_PAGINATION_SKIP_PAGE_NUMBER_IN_SORT = "pagination.sort.skippagenumber"; //$NON-NLS-1$
// </JBN>
/**
* Separator char used in property names.
*/
private static final char SEP = '.';
/**
* logger.
*/
private static Log log = LogFactory.getLog(TableProperties.class);
/**
* The userProperties are local, non-default properties; these settings override the defaults from
* displaytag.properties and TableTag.properties.
*/
private static Properties userProperties = new Properties();
/**
* Configured resource provider. If no ResourceProvider is configured, an no-op one is used. This instance is
* initialized at first use and shared.
*/
private static I18nResourceProvider resourceProvider;
/**
* Configured locale resolver.
*/
private static LocaleResolver localeResolver;
/**
* TableProperties for each locale are loaded as needed, and cloned for public usage.
*/
private static Map prototypes = new HashMap();
/**
* Loaded properties (defaults from defaultProperties + custom from bundle).
*/
private Properties properties;
/**
* The locale for these properties.
*/
private Locale locale;
/**
* Cache for dinamically instantiated object (request factory, decorator factory).
*/
private Map objectCache = new HashMap();
/**
* Setter for I18nResourceProvider. A resource provider is usually set using displaytag properties, this accessor is
* needed for tests.
* @param provider I18nResourceProvider instance
*/
protected static void setResourceProvider(I18nResourceProvider provider)
{
resourceProvider = provider;
}
/**
* Setter for LocaleResolver. A locale resolver is usually set using displaytag properties, this accessor is needed
* for tests.
* @param resolver LocaleResolver instance
*/
protected static void setLocaleResolver(LocaleResolver resolver)
{
localeResolver = resolver;
}
/**
* Loads default properties (TableTag.properties).
* @return loaded properties
* @throws TablePropertiesLoadException if default properties file can't be found
*/
private static Properties loadBuiltInProperties() throws TablePropertiesLoadException
{
Properties defaultProperties = new Properties();
try
{
defaultProperties.load(TableProperties.class.getResourceAsStream(DEFAULT_FILENAME));
}
catch (IOException e)
{
throw new TablePropertiesLoadException(TableProperties.class, DEFAULT_FILENAME, e);
}
return defaultProperties;
}
/**
* Loads user properties (displaytag.properties) according to the given locale. User properties are not guarantee to
* exist, so the method can return <code>null</code> (no exception will be thrown).
* @param locale requested Locale
* @return loaded properties
*/
private static ResourceBundle loadUserProperties(Locale locale)
{
ResourceBundle bundle = null;
try
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -