001: /**
002: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003: *
004: * This program is free software; you can redistribute it and/or modify
005: * it under the terms of the latest version of the GNU Lesser General
006: * Public License as published by the Free Software Foundation;
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public License
014: * along with this program (LICENSE.txt); if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: */package org.jamwiki;
017:
018: import java.util.Locale;
019: import org.jamwiki.model.WikiUser;
020: import org.jamwiki.utils.WikiUtil;
021: import org.jamwiki.utils.WikiCache;
022: import org.jamwiki.utils.WikiLogger;
023:
024: /**
025: * <code>WikiBase</code> is loaded as a singleton class and provides access
026: * to all core wiki structures. In addition this class provides utility methods
027: * for resetting core structures including caches and permissions.
028: *
029: * @see org.jamwiki.DataHandler
030: * @see org.jamwiki.UserHandler
031: * @see org.jamwiki.search.SearchEngine
032: */
033: public class WikiBase {
034:
035: /** Standard logger. */
036: private static final WikiLogger logger = WikiLogger
037: .getLogger(WikiBase.class.getName());
038: /** The singleton instance of this class. */
039: private static WikiBase instance = null;
040: /** The data handler that looks after read/write operations. */
041: private static DataHandler dataHandler = null;
042: /** The handler for user login/authentication. */
043: private static UserHandler userHandler = null;
044: /** The search engine instance. */
045: private static SearchEngine searchEngine = null;
046:
047: /** Cache name for the cache of parsed topic content. */
048: public static final String CACHE_PARSED_TOPIC_CONTENT = "org.jamwiki.WikiBase.CACHE_PARSED_TOPIC_CONTENT";
049: /** Ansi data handler class */
050: public static final String DATA_HANDLER_ANSI = "org.jamwiki.db.AnsiDataHandler";
051: /** DB2 data handler class */
052: public static final String DATA_HANDLER_DB2 = "org.jamwiki.db.DB2DataHandler";
053: /** DB2/400 data handler class */
054: public static final String DATA_HANDLER_DB2400 = "org.jamwiki.db.DB2400DataHandler";
055: /** HSql data handler class */
056: public static final String DATA_HANDLER_HSQL = "org.jamwiki.db.HSqlDataHandler";
057: /** MSSql data handler class */
058: public static final String DATA_HANDLER_MSSQL = "org.jamwiki.db.MSSqlDataHandler";
059: /** MySql data handler class */
060: public static final String DATA_HANDLER_MYSQL = "org.jamwiki.db.MySqlDataHandler";
061: /** Oracle data handler class */
062: public static final String DATA_HANDLER_ORACLE = "org.jamwiki.db.OracleDataHandler";
063: /** Postgres data handler class */
064: public static final String DATA_HANDLER_POSTGRES = "org.jamwiki.db.PostgresDataHandler";
065: /** Sybase ASA data handler class */
066: public static final String DATA_HANDLER_ASA = "org.jamwiki.db.SybaseASADataHandler";
067: /** Name of the default wiki */
068: // FIXME - make this configurable
069: public static final String DEFAULT_VWIKI = "en";
070: /** Data stored using an external database */
071: public static final String PERSISTENCE_EXTERNAL = "DATABASE";
072: /** Data stored using an internal copy of the HSQL database */
073: public static final String PERSISTENCE_INTERNAL = "INTERNAL";
074: /** Lucene search engine class */
075: public static final String SEARCH_ENGINE_LUCENE = "org.jamwiki.search.LuceneSearchEngine";
076: /** Root directory within the WAR distribution that contains the default topic pages. */
077: public static final String SPECIAL_PAGE_DIR = "pages";
078: /** Name of the default starting points topic. */
079: public static final String SPECIAL_PAGE_STARTING_POINTS = "StartingPoints";
080: /** Name of the default left menu topic. */
081: public static final String SPECIAL_PAGE_LEFT_MENU = "LeftMenu";
082: /** Name of the default footer topic. */
083: public static final String SPECIAL_PAGE_BOTTOM_AREA = "BottomArea";
084: /** Name of the default jamwiki.css topic. */
085: public static final String SPECIAL_PAGE_SPECIAL_PAGES = "SpecialPages";
086: /** Name of the default jamwiki.css topic. */
087: public static final String SPECIAL_PAGE_STYLESHEET = "StyleSheet";
088: /** Allow file uploads of any file type. */
089: public static final int UPLOAD_ALL = 0;
090: /** Use a blacklist to determine what file types can be uploaded. */
091: public static final int UPLOAD_BLACKLIST = 2;
092: /** Disable all file uploads. */
093: public static final int UPLOAD_NONE = 1;
094: /** Use a whitelist to determine what file types can be uploaded. */
095: public static final int UPLOAD_WHITELIST = 3;
096: /** Database user handler class */
097: public static final String USER_HANDLER_DATABASE = "org.jamwiki.db.DatabaseUserHandler";
098: /** LDAP user handler class */
099: public static final String USER_HANDLER_LDAP = "org.jamwiki.ldap.LdapUserHandler";
100:
101: static {
102: try {
103: WikiBase.instance = new WikiBase();
104: } catch (Exception e) {
105: logger.severe("Failure while initializing WikiBase", e);
106: }
107: }
108:
109: /**
110: * Creates an instance of <code>WikiBase</code>, initializing the default
111: * data handler instance and search engine instance.
112: *
113: * @throws Exception If the instance cannot be instantiated.
114: */
115: private WikiBase() throws Exception {
116: this .reload();
117: }
118:
119: /**
120: * Get an instance of the current data handler.
121: *
122: * @return The current data handler instance, or <code>null</code>
123: * if the handler has not yet been initialized.
124: */
125: public static DataHandler getDataHandler() {
126: return WikiBase.dataHandler;
127: }
128:
129: /**
130: * Get an instance of the current search engine.
131: *
132: * @return The current search engine instance.
133: */
134: public static SearchEngine getSearchEngine() {
135: return WikiBase.searchEngine;
136: }
137:
138: /**
139: *
140: */
141: public static UserHandler getUserHandler() {
142: return WikiBase.userHandler;
143: }
144:
145: /**
146: * Reload the data handler, user handler, and other basic wiki
147: * data structures.
148: */
149: public static void reload() throws Exception {
150: WikiBase.dataHandler = WikiUtil.dataHandlerInstance();
151: WikiBase.userHandler = WikiUtil.userHandlerInstance();
152: WikiBase.searchEngine = WikiUtil.searchEngineInstance();
153: }
154:
155: /**
156: * Reset the WikiBase object, re-initializing the data handler and
157: * other values.
158: *
159: * @param locale The locale to be used if any system pages need to be set up
160: * as a part of the initialization process.
161: * @param user A sysadmin user to be used in case any system pages need to
162: * be created as a part of the initialization process.
163: * @throws Exception Thrown if an error occurs during re-initialization.
164: */
165: public static void reset(Locale locale, WikiUser user)
166: throws Exception {
167: WikiBase.instance = new WikiBase();
168: WikiCache.initialize();
169: WikiBase.dataHandler.setup(locale, user);
170: }
171: }
|