📄 tableproperties.java
字号:
{
bundle = ResourceBundle.getBundle(LOCAL_PROPERTIES, locale);
}
catch (MissingResourceException e)
{
// if no resource bundle is found, try using the context classloader
try
{
bundle = ResourceBundle.getBundle(LOCAL_PROPERTIES, locale, Thread
.currentThread()
.getContextClassLoader());
}
catch (MissingResourceException mre)
{
if (log.isDebugEnabled())
{
log.debug(Messages.getString("TableProperties.propertiesnotfound", //$NON-NLS-1$
new Object[]{mre.getMessage()}));
}
}
}
return bundle;
}
/**
* Returns the configured Locale Resolver. This method is called before the loading of localized properties.
* @return LocaleResolver instance.
* @throws TablePropertiesLoadException if the default <code>TableTag.properties</code> file is not found.
*/
public static LocaleResolver getLocaleResolverInstance() throws TablePropertiesLoadException
{
if (localeResolver == null)
{
// special handling, table properties is not yet instantiated
String className = null;
ResourceBundle defaultUserProperties = loadUserProperties(Locale.getDefault());
// if available, user properties have higher precedence
if (defaultUserProperties != null)
{
try
{
className = defaultUserProperties.getString(PROPERTY_CLASS_LOCALERESOLVER);
}
catch (MissingResourceException e)
{
// no problem
}
}
// still null? load defaults
if (className == null)
{
Properties defaults = loadBuiltInProperties();
className = defaults.getProperty(PROPERTY_CLASS_LOCALERESOLVER);
}
if (className != null)
{
try
{
Class classProperty = ReflectHelper.classForName(className);
localeResolver = (LocaleResolver) classProperty.newInstance();
log.info(Messages.getString("TableProperties.classinitializedto", //$NON-NLS-1$
new Object[]{ClassUtils.getShortClassName(LocaleResolver.class), className}));
}
catch (Throwable e)
{
log.warn(Messages.getString("TableProperties.errorloading", //$NON-NLS-1$
new Object[]{
ClassUtils.getShortClassName(LocaleResolver.class),
e.getClass().getName(),
e.getMessage()}));
}
}
else
{
log.info(Messages.getString("TableProperties.noconfigured", //$NON-NLS-1$
new Object[]{ClassUtils.getShortClassName(LocaleResolver.class)}));
}
// still null?
if (localeResolver == null)
{
// fallback locale resolver
localeResolver = new LocaleResolver()
{
public Locale resolveLocale(HttpServletRequest request)
{
return request.getLocale();
}
};
}
}
return localeResolver;
}
/**
* Initialize a new TableProperties loading the default properties file and the user defined one. There is no
* caching used here, caching is assumed to occur in the getInstance factory method.
* @param myLocale the locale we are in
* @throws TablePropertiesLoadException for errors during loading of properties files
*/
private TableProperties(Locale myLocale) throws TablePropertiesLoadException
{
this.locale = myLocale;
// default properties will not change unless this class is reloaded
Properties defaultProperties = loadBuiltInProperties();
properties = new Properties(defaultProperties);
addProperties(myLocale);
// Now copy in the user properties (properties file set by calling setUserProperties()).
// note setUserProperties() MUST BE CALLED before the first TableProperties instantation
Enumeration keys = userProperties.keys();
while (keys.hasMoreElements())
{
String key = (String) keys.nextElement();
if (key != null)
{
properties.setProperty(key, (String) userProperties.get(key));
}
}
}
/**
* Try to load the properties from the local properties file, displaytag.properties, and merge them into the
* existing properties.
* @param userLocale the locale from which the properties are to be loaded
*/
private void addProperties(Locale userLocale)
{
ResourceBundle bundle = loadUserProperties(userLocale);
if (bundle != null)
{
Enumeration keys = bundle.getKeys();
while (keys.hasMoreElements())
{
String key = (String) keys.nextElement();
properties.setProperty(key, bundle.getString(key));
}
}
}
/**
* Clones the properties as well.
* @return a new clone of oneself
*/
protected Object clone()
{
TableProperties twin;
try
{
twin = (TableProperties) super.clone();
}
catch (CloneNotSupportedException e)
{
// should never happen
throw new UnhandledException(e);
}
twin.properties = (Properties) this.properties.clone();
return twin;
}
/**
* Returns a new TableProperties instance for the given locale.
* @param request HttpServletRequest needed to extract the locale to use. If null the default locale will be used.
* @return TableProperties instance
*/
public static TableProperties getInstance(HttpServletRequest request)
{
Locale locale;
if (request != null)
{
locale = getLocaleResolverInstance().resolveLocale(request);
}
else
{
// for some configuration parameters locale doesn't matter
locale = Locale.getDefault();
}
TableProperties props = (TableProperties) prototypes.get(locale);
if (props == null)
{
TableProperties lprops = new TableProperties(locale);
prototypes.put(locale, lprops);
props = lprops;
}
return (TableProperties) props.clone();
}
/**
* Unload all cached properties. This will not clear properties set by by setUserProperties; you must clear those
* manually.
*/
public static void clearProperties()
{
prototypes.clear();
}
/**
* Local, non-default properties; these settings override the defaults from displaytag.properties and
* TableTag.properties. Please note that the values are copied in, so that multiple calls with non-overlapping
* properties will be merged, not overwritten. Note: setUserProperties() MUST BE CALLED before the first
* TableProperties instantation.
* @param overrideProperties - The local, non-default properties
*/
public static void setUserProperties(Properties overrideProperties)
{
// copy keys here, so that this can be invoked more than once from different sources.
// if default properties are not yet loaded they will be copied in constructor
Enumeration keys = overrideProperties.keys();
while (keys.hasMoreElements())
{
String key = (String) keys.nextElement();
if (key != null)
{
userProperties.setProperty(key, (String) overrideProperties.get(key));
}
}
}
/**
* The locale for which these properties are intended.
* @return the locale
*/
public Locale getLocale()
{
return locale;
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_INVALIDPAGE</code> property.
* @return String
*/
public String getPagingInvalidPage()
{
return getProperty(PROPERTY_STRING_PAGING_INVALIDPAGE);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_ITEM_NAME</code> property.
* @return String
*/
public String getPagingItemName()
{
return getProperty(PROPERTY_STRING_PAGING_ITEM_NAME);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_ITEMS_NAME</code> property.
* @return String
*/
public String getPagingItemsName()
{
return getProperty(PROPERTY_STRING_PAGING_ITEMS_NAME);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_NOITEMS</code> property.
* @return String
*/
public String getPagingFoundNoItems()
{
return getProperty(PROPERTY_STRING_PAGING_NOITEMS);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_FOUND_ONEITEM</code> property.
* @return String
*/
public String getPagingFoundOneItem()
{
return getProperty(PROPERTY_STRING_PAGING_FOUND_ONEITEM);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_FOUND_ALLITEMS</code> property.
* @return String
*/
public String getPagingFoundAllItems()
{
return getProperty(PROPERTY_STRING_PAGING_FOUND_ALLITEMS);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_FOUND_SOMEITEMS</code> property.
* @return String
*/
public String getPagingFoundSomeItems()
{
return getProperty(PROPERTY_STRING_PAGING_FOUND_SOMEITEMS);
}
/**
* Getter for the <code>PROPERTY_INT_PAGING_GROUPSIZE</code> property.
* @return int
*/
public int getPagingGroupSize()
{
// default size is 8
return getIntProperty(PROPERTY_INT_PAGING_GROUPSIZE, 8);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_BANNER_ONEPAGE</code> property.
* @return String
*/
public String getPagingBannerOnePage()
{
return getProperty(PROPERTY_STRING_PAGING_BANNER_ONEPAGE);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_BANNER_FIRST</code> property.
* @return String
*/
public String getPagingBannerFirst()
{
return getProperty(PROPERTY_STRING_PAGING_BANNER_FIRST);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_BANNER_LAST</code> property.
* @return String
*/
public String getPagingBannerLast()
{
return getProperty(PROPERTY_STRING_PAGING_BANNER_LAST);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_BANNER_FULL</code> property.
* @return String
*/
public String getPagingBannerFull()
{
return getProperty(PROPERTY_STRING_PAGING_BANNER_FULL);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_PAGE_LINK</code> property.
* @return String
*/
public String getPagingPageLink()
{
return getProperty(PROPERTY_STRING_PAGING_PAGE_LINK);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_PAGE_SELECTED</code> property.
* @return String
*/
public String getPagingPageSelected()
{
return getProperty(PROPERTY_STRING_PAGING_PAGE_SELECTED);
}
/**
* Getter for the <code>PROPERTY_STRING_PAGING_PAGE_SPARATOR</code> property.
* @return String
*/
public String getPagingPageSeparator()
{
return getProperty(PROPERTY_STRING_PAGING_PAGE_SPARATOR);
}
/**
* Is the given export option enabled?
* @param exportType instance of MediaTypeEnum
* @return boolean true if export is enabled
*/
public boolean getAddExport(MediaTypeEnum exportType)
{
return getBooleanProperty(PROPERTY_EXPORT_PREFIX + SEP + exportType.getName());
}
/**
* Should headers be included in given export type?
* @param exportType instance of MediaTypeEnum
* @return boolean true if export should include headers
*/
public boolean getExportHeader(MediaTypeEnum exportType)
{
return getBooleanProperty(PROPERTY_EXPORT_PREFIX
+ SEP
+ exportType.getName()
+ SEP
+ EXPORTPROPERTY_BOOLEAN_EXPORTHEADER);
}
/**
* Returns the label for the given export option.
* @param exportType instance of MediaTypeEnum
* @return String label
*/
public String getExportLabel(MediaTypeEnum exportType)
{
return getProperty(PROPERTY_EXPORT_PREFIX + SEP + exportType.getName() + SEP + EXPORTPROPERTY_STRING_LABEL);
}
/**
* Returns the file name for the given media. Can be null
* @param exportType instance of MediaTypeEnum
* @return String filename
*/
public String getExportFileName(MediaTypeEnum exportType)
{
return getProperty(PROPERTY_EXPORT_PREFIX + SEP + exportType.getName() + SEP + EXPORTPROPERTY_STRING_FILENAME);
}
/**
* Getter for the <code>PROPERTY_BOOLEAN_EXPORTDECORATED</code> property.
* @return boolean <code>true</code> if decorators should be used in exporting
*/
public boolean getExportDecorated()
{
return getBooleanProperty(PROPERTY_BOOLEAN_EXPORTDECORATED);
}
/**
* Getter for the <code>PROPERTY_STRING_EXPORTBANNER</code> property.
* @return String
*/
public String getExportBanner()
{
return getProperty(PROPERTY_STRING_EXPORTBANNER);
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -