📄 globals.java
字号:
/**
* $RCSfile: JiveGlobals.java,v $
* $Revision: 1.1.1.1 $
* $Date: 2002/09/09 13:50:45 $
*
* New Jive from Jdon.com. Modified by Frank Chu
*
* This software is the proprietary information of CoolServlets, Inc.
* Use is subject to license terms.
*/
package com.airinbox.member.forum;
import com.airinbox.member.forum.util.XMLProperties;
import java.util.*;
import java.io.*;
import java.text.*;
import org.apache.avalon.framework.configuration.*;
/**
* Contains constant values representing various objects in Jive as well as
* other settings such as the global locale and Jive version number.<p>
*
* The class also controls Jive properties. Jive properties are only meant to
* be set and retrevied by core Jive classes.
* <p>
* All properties are stored in the file <tt>member_config.xml</tt> which is
* located in the <tt>memberHome</tt> directory. The location of that
* directory should be specified one of two ways:<ol>
* <li>Indicate its value in the <tt>member_init.properties</tt> file. This
* is a standard properties file so the property should be something
* like:<br>
* <tt>memberHome=c:\\some\\directory\\memberHome</tt> (Windows) <br>
* or <br>
* <tt>memberHome=/home/some/directory/memberHome</tt> (Unix)
* <p>
* The file must be in your classpath so that it can be loaded by Java's
* classloader.
* <li>Use another class in your VM to set the
* <tt>PropertyManager.memberHome</tt> variable. This must be done before
* the rest of Jive starts up, for example: in a servlet that is set to run
* as soon as the appserver starts up.
* </ol>
* <p>
* All Jive property names must be in the form <code>prop.name</code> - parts of
* the name must be seperated by ".". The value can be any valid String,
* including Strings with line breaks.
*/
public class Globals {
// Constant values
public static final int FORUM = 0;
public static final int THREAD = 1;
public static final int MESSAGE = 2;
public static final int USER = 3;
public static final int GROUP = 4;
public static final int THREAD_NAME = 5;
public static final int MESSAGE_SUBJECT = 6;
public static final int MESSAGE_BODY = 7;
public static final int CREATION_DATE = 8;
public static final int MODIFIED_DATE = 9;
public static final int EXTENDED_PROPERTY = 10;
public static final int ANONYMOUS = 11;
public static final int REGISTERED_USERS = 12;
// Time values in milliseconds
public static final long SECOND = 1000;
public static final long MINUTE = 60 * SECOND;
public static final long HOUR = 60 * MINUTE;
public static final long DAY = 24 * HOUR;
public static final long WEEK = 7 * DAY;
/**
* The Major version number of Member. i.e. 1.x.x
*/
public static final int MEMBER_MAJOR_VERSION = 2;
/**
* The Minor version number of Member. i.e. x.1.x.
*/
public static final int MEMBER_MINOR_VERSION = 1;
/**
* The revision version number of Member. i.e. x.x.1.
*/
public static final int MEMBER_REVISION_VERSION = 1;
/**
* Location of the memberHome directory. All configuration files should be
* located here. This value can be set explicitly by an outside class or
* this class will attempt to load it from the <tt>member_init.properties</tt>
* file.
*/
public static String memberHome = null;
/**
* XML properties to actually get and set the Member properties.
*/
private static XMLProperties properties = null;
private static Locale locale = null;
private static TimeZone timeZone = null;
private static DateFormat dateFormat = null;
private static DateFormat dateTimeFormat = null;
public static Hashtable dbConfig = null;
public static String _TABLE_MESSAGE = "TABLE_MESSAGE";
public static String _TABLE_MESSAGE_PROP = "TABLE_MESSAGE_PROP";
public static String _TABLE_GROUP = "TABLE_GROUP";
public static String _TABLE_GROUP_USER = "TABLE_GROUP_USER";
public static String _TABLE_GROUP_PERM = "TABLE_GROUP_PERM";
public static String _TABLE_GROUP_PROP = "TABLE_GROUP_PROP";
public static String _TABLE_USER = "TABLE_USER";
public static String _TABLE_USER_PERM = "TABLE_USER_PERM";
public static String _TABLE_USER_PROP = "TABLE_USER_PROP";
public static String _TABLE_THREAD = "TABLE_THREAD";
public static String _TABLE_THREAD_PROP = "TABLE_THREAD_PROP";
public static String _TABLE_FORUM = "TABLE_FORUM";
public static String _TABLE_FORUM_PROP = "TABLE_FORUM_PROP";
public static String _TABLE_MODERATION = "TABLE_MODERATION";
public static String _TABLE_WATCH = "TABLE_WATCH";
public static String _TABLE_REWARD = "TABLE_REWARD";
public static String _TABLE_ID = "TABLE_ID";
public static String SYSTEM_DECRIPTION = System.getProperty("MEMBER_SYSTEM_DECRIPTION");
public static String MEMBER_HOME = System.getProperty("MEMBER_HOME");
public static String MEMBER_CONFIG_FILE = System.getProperty("MEMBER_CONFIG_FILE");
public static String getConfig(String name) {
return getMemberProperty("database.table."+name);
}
/**
* Returns the version number of Member as a String. i.e. major.minor.revision
*/
public static String getMemberVersion() {
return SYSTEM_DECRIPTION;
}
/**
* Returns the global Locale used by Member. A locale specifies language
* and country codes, and is used for internationalization. The default
* locale is Locale.US
*
* @return the global locale used by Member.
*/
public static Locale getLocale() {
if (locale == null) {
loadLocale();
}
return locale;
}
/**
* Sets the global locale used by Member. A locale specifies language
* and country codes, and is used for internationalization. The default
* locale is Locale.US
*
* @param locale the global Locale for Member.
*/
public static void setLocale(Locale newLocale) {
locale = newLocale;
// Save values to Member properties.
setMemberProperty("locale.country", locale.getCountry());
setMemberProperty("locale.language", locale.getLanguage());
// Reset the date formatter objects
dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM, locale);
dateFormat.setTimeZone(timeZone);
dateTimeFormat.setTimeZone(timeZone);
}
/**
* Returns the global TimeZone used by Member. The default is the VM's
* default time zone.
*
* @return the global time zone used by Member.
*/
public static TimeZone getTimeZone() {
if (timeZone == null) {
loadLocale();
}
return timeZone;
}
/**
* Sets the global time zone used by Member. The default time zone is the VM's
* time zone.
*/
public static void setTimeZone(TimeZone newTimeZone) {
timeZone = newTimeZone;
dateFormat.setTimeZone(timeZone);
dateTimeFormat.setTimeZone(timeZone);
setMemberProperty("locale.timeZone", timeZone.getID());
}
/**
* Formats a Date object to return a date using the global locale.
*/
public static String formatDate(Date date) {
if (dateFormat == null) {
loadLocale();
}
return dateFormat.format(date);
}
/**
* Formats a Date object to return a date and time using the global locale.
*/
public static String formatDateTime(Date date) {
if (dateTimeFormat == null) {
loadLocale();
}
return dateTimeFormat.format(date);
}
/**
* Returns the location of the <code>memberHome</code> directory.
*
* @return the location of the memberHome dir.
*/
public static String getMemberHome() {
if (memberHome == null) {
memberHome = MEMBER_HOME;
}
return memberHome;
}
/**
* Indicates whether or not we have read access to the <code>memberHome</code>
* directory.
*
* @return true if we have read access to memberHome, false otherwise.
*/
public static boolean isMemberHomeReadable() {
return (new File(getMemberHome())).canRead();
}
/**
* Indicates whether or not we have write access to the
* <code>memberHome</code> directory.
*
* @return true if we have write access to memberHome, false otherwise.
*/
public static boolean isMemberHomeWritable() {
return (new File(getMemberHome())).canWrite();
}
/**
* Returns a Member property.
*
* @param name the name of the property to return.
* @return the property value specified by name.
*/
public static String getMemberProperty(String name) {
loadProperties();
return properties.getProperty(name);
}
/**
* Sets a Member property. If the property doesn't already exists, a new
* one will be created.
*
* @param name the name of the property being set.
* @param value the value of the property being set.
*/
public static void setMemberProperty(String name, String value) {
loadProperties();
properties.setProperty(name, value);
}
/**
* Deletes a Member property. If the property doesn't exist, the method
* does nothing.
*
* @param name the name of the property to delete.
*/
public static void deleteMemberProperty(String name) {
loadProperties();
properties.deleteProperty(name);
}
/**
* Loads properties if necessary. Property loading must be done lazily so
* that we give outside classes a chance to set <tt>memberHome</tt>.
*/
private synchronized static void loadProperties() {
//Create a manager with the full path to the xml config file.
properties = new XMLProperties(MEMBER_CONFIG_FILE);
}
/**
* Load locale and timezone information.
*/
private synchronized static void loadLocale() {
String language = getMemberProperty("locale.language");
if (language == null) {
language = "";
}
String country = getMemberProperty("locale.country");
if (country == null) {
country = "";
}
// If no locale info is specified, default to Locale.US
if (language.equals("") && country.equals("")) {
locale = Locale.US;
}
else {
locale = new Locale(language, country);
}
String timeZoneID = getMemberProperty("locale.timeZone");
if (timeZoneID == null) {
timeZone = TimeZone.getDefault();
}
else {
timeZone = TimeZone.getTimeZone(timeZoneID);
}
dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM, locale);
dateFormat.setTimeZone(timeZone);
dateTimeFormat.setTimeZone(timeZone);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -