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

📄 jwmakernel.java

📁 java windows mda and reveus
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*** * jwma Java WebMail * Copyright (c) 2000-2003 jwma team * * jwma is free software; you can distribute and use this source * under the terms of the BSD-style license received along with * the distribution. ***/package dtw.webmail;import java.util.*;import java.io.*;import java.net.*;import org.apache.log4j.Logger;import org.apache.log4j.PropertyConfigurator;import org.apache.log4j.BasicConfigurator;import dtw.webmail.util.*;import dtw.webmail.util.config.*;import dtw.webmail.model.*;import dtw.webmail.admin.*;import dtw.webmail.plugin.*;import dtw.webmail.plugin.std.CastorHelper;import net.wimpi.text.*;import javax.mail.Transport;/** * A kernel that represents a hub for internal "globally" used * jwma functions & data (system settings). * * This class implements the singleton pattern, which means there is * only one instance throughout run-time. * * @author Dieter Wimberger * @version 0.9.7 07/02/2003 */public class JwmaKernel {  //class attributes  private static JwmaKernel c_Self = null;		//Singleton instance  //logging  private static Logger log = Logger.getLogger(JwmaKernel.class);  //instance attributes  private int m_Diag = 0;             //diagnostic counter  private String m_ConfigurationFile;  private JwmaConfiguration m_Configuration; //configuration  //i18n  private URLClassLoader m_i18nLoader;		//class loader for resource bundles  private ResourceBundle m_LogMessages;		//Log message resource bundle  private ResourceBundle m_ErrorMessages;   //Error message resource bundle  //Admin related  private boolean m_StatusEnabled;  //Status enabled  private String[] m_Admins;        //administrator usernames  //Text processing  private Processor m_MessageProcessor;         //default message processor  private ProcessingKernel m_ProcessingKernel;  //processing kernel  private String m_TextProcFile;                //jTextproc properties  //Directories  private String m_RootDir;   //root directory  private String m_EtcDir;    //etc dir  private String m_DataDir;   //data dir  private String m_LogDir;    //log dir  private String m_i18nDir;   //i18n bundle dir  //Logging  private String m_LogProperties;   //log4j properties file  //Plugin references  private PreferencesPersistencePlugin m_PrefsPersistencePlugin;  private RandomAppendPlugin m_RandomAppendPlugin;  private ContactManagementPlugin m_ContactManagementPlugin;  //Controller Urls  private String m_MainController;  private String m_MailingController;  private String m_AdminController;  private String m_ContactsController;  //View urls  private Properties m_Views;  /**   * Constructs a JwmaKernel instance.   * Private to prevent construction from outside of   * this class.   */  private JwmaKernel() {    c_Self = this;    m_Views = new Properties();  }//constructor  /**   * Prepares the kernel for service.   *   * @param path representing the root directory where jwma's   *        files reside, as <tt>String</tt>.   *   * @throws Exception when it fails to load the properties or   *         set up system functionality according to the settings   *         in the properties.   */  public void setup(String path)      throws Exception {    //Configure to log to standard out at least.    BasicConfigurator.configure();    //1.setup directories    setupDirectories(path);    m_Diag++;    //2.setup filenames    setupFiles();    m_Diag++;    //3.load configuration    loadConfiguration();    m_Diag++;    //4.setup i18n    prepareI18N();    m_Diag++;    //5.prepare log files    prepareLogging();    m_Diag++;    //From here on we write to the own log    try {      //6.prepare plugins      preparePlugins();      m_Diag++;      //7.prepare processing      prepareProcessing();      m_Diag++;      //8.prepare postoffice and transport settings      prepareMailServices();      m_Diag++;      //9.prepare controller urls      prepareControllerUrls();      m_Diag++;      //10.prepare view urls      prepareViewUrls();      m_Diag++;    } catch (JwmaException err) {      //log exception with description and trace if inlined exception      //available, else with stacktrace.      if (err.hasException()) {        log.error(err.getMessage(), err.getException());      } else {        log.error(err.getMessage(), err);      }      throw err;    } catch (Exception ex) {      log.error(ex.getMessage(), ex);      throw ex;    } finally {      //JwmaStatus.createJwmaStatus();    }  }//setup  /**   * Sets up all necessary directory paths.   *   * @param path the root path pointing to the directory where   *        the jwma data resides.   */  private void setupDirectories(String path) {    //Directories    m_RootDir = path;    m_EtcDir = m_RootDir + File.separator + JwmaSettings.ETC_DIR + File.separator;    m_LogDir = m_RootDir + File.separator + JwmaSettings.LOG_DIR + File.separator;    m_DataDir = m_RootDir + File.separator + JwmaSettings.DATA_DIR + File.separator;    m_i18nDir = StringUtil.repairPath(        m_RootDir + File.separator + JwmaSettings.I18N_DIR + File.separator    );  }//setupDirectories  /**   * Sets up all necessary file paths.   */  private void setupFiles() {    m_ConfigurationFile = m_EtcDir + JwmaConfiguration.CONFIG_FILENAME;    m_LogProperties = m_EtcDir + JwmaConfiguration.LOG4J_CONFIG;    m_TextProcFile = m_EtcDir + JwmaConfiguration.JTEXTPROC_CONFIG;  }//setupFiles  private void loadConfiguration()      throws Exception {    CastorXMLConfiguration cxmlconf =        new CastorXMLConfiguration(new File (m_ConfigurationFile));    m_Configuration = cxmlconf.load();    log.info("Loaded configuration.");  }//loadConfiguration  /**   * Prepares i18n for jwma   */  private void prepareI18N()      throws Exception {    //1. setup classloader for bundles    URL[] urls = {new File(m_i18nDir).toURL()};    log.debug(urls[0].toString());    m_i18nLoader = new URLClassLoader(urls);    //2. retrieve instance from configuration    Internationalization i18n = m_Configuration.getI18N();    log.debug("Loading logmessage bundle:" + i18n.getSystemLanguage());    //3. load log messages bundle for system locale    m_LogMessages = ResourceBundle.getBundle(        "logmessages", i18n.getSystemLocale(), m_i18nLoader    );    log.debug("Loading logmessage bundle:" + i18n.getSystemLanguage());    //4. load error messages for system locale    m_ErrorMessages = ResourceBundle.getBundle(        "errormessages", i18n.getSystemLocale(), m_i18nLoader    );    log.info(getLogMessage("jwma.kernel.prepared.i18n"));  }//prepareI18N  /**   * Prepares jwma log files.   */  private void prepareLogging()      throws Exception {    //1.load the properties    Properties props = new Properties();    props.load(new FileInputStream(m_LogProperties));    //2. fix relative paths    for (Enumeration enum = props.propertyNames(); enum.hasMoreElements();) {      String property = (String) enum.nextElement();      if (property.indexOf(".File") > 0) {        File file = new File(props.getProperty(property));        if (!file.isAbsolute()) {          props.setProperty(property, m_LogDir + file.getPath());        }      }    }    //configure log4j    PropertyConfigurator.configure(props);    log.info(getLogMessage("jwma.kernel.prepared.logging"));  }//prepareLogging  /**   * Prepare contact management.   */  private void preparePlugins()      throws Exception {    log.debug("Loading and activating plugins.");    //1. Load & activate preferences persistence plugin    m_PrefsPersistencePlugin = (PreferencesPersistencePlugin)        Class.forName(m_Configuration.getPreferencePersistencePlugin()).newInstance();    m_PrefsPersistencePlugin.activate();    //2. Load & activate contact management plugin    m_ContactManagementPlugin = (ContactManagementPlugin)        Class.forName(m_Configuration.getContactManagementPlugin()).newInstance();    m_ContactManagementPlugin.activate();    //3. Load & activate random append plugin    String rndapp = m_Configuration.getRandomAppendPlugin();    if (rndapp != null && rndapp.length() != 0) {      m_RandomAppendPlugin = (RandomAppendPlugin)          Class.forName(rndapp).newInstance();      m_RandomAppendPlugin.activate();    }  }//preparePlugins  /**   * Prepares the processing.   */  private void prepareProcessing()      throws Exception {    Properties procprops = new Properties();    FileInputStream in = new FileInputStream(m_TextProcFile);    procprops.load(in);    //create processing kernel    m_ProcessingKernel =        ProcessingKernel.createProcessingKernel(procprops);    //lookup default message processing pipe    m_MessageProcessor = getMessageProcessor(        m_Configuration.getDefaultMessageProcessor()    );    if (m_MessageProcessor == null) {      throw new Exception("Failed to load default message processing pipe.");    }    log.info(getLogMessage("jwma.kernel.prepared.processing"));  }//prepareProcessing  /**   * Prepares the mail service related settings.   */  private void prepareMailServices()      throws Exception {    //1. setup transport agent    MailTransportAgent mta = m_Configuration.getMTA();    //set system properties    //TODO: Check if really required    System.getProperties().put(        "mail." + mta.getProtocol() + ".auth",        new Boolean(mta.isAuthenticated()).toString()    );    System.getProperties().put("mail.smtp.host", mta.getAddress());    if(mta.isSecure()) {      m_Configuration.getSecurity().addSocketProperties(mta.getProtocol(),mta.getPort());    }    //2. post office security setup    for(Iterator iter = m_Configuration.getPostOffices(); iter.hasNext();) {      PostOffice po = (PostOffice) iter.next();      if(po.isSecure()) {        m_Configuration.getSecurity().addSocketProperties(po.getProtocol(),po.getPort());      }    }    log.info(getLogMessage("jwma.kernel.prepared.mailservices"));  }//prepareMailServices  /**   * Prepares the controller url's   */  private void prepareControllerUrls() {    Properties ctrls = new Properties();    try {      ctrls.load(        Thread.currentThread().getContextClassLoader()            .getResourceAsStream("dtw/webmail/resources/controllers.properties")      );      m_MainController = ctrls.getProperty("jwma.controller.main");      m_MailingController = ctrls.getProperty("jwma.controller.mailing");      m_ContactsController = ctrls.getProperty("jwma.controller.contacts");      m_AdminController = ctrls.getProperty("jwma.controller.admin");    } catch (IOException ex) {      log.error("prepareControllerUrls()",ex);      return;    }    for(Iterator iter = ctrls.keySet().iterator(); iter.hasNext();) {      String key= (String) iter.next();      log.debug(key + "=" + ctrls.get(key));    }    log.info(getLogMessage("jwma.kernel.prepared.curls"));  }//prepareControllerUrls  /**   * Prepares the view url's.   */  private void prepareViewUrls() {    m_Views = new Properties();    try {      m_Views.load(         Thread.currentThread().getContextClassLoader()             .getResourceAsStream("dtw/webmail/resources/views.properties")      );     for(Iterator iter = m_Views.keySet().iterator(); iter.hasNext();) {      String key= (String) iter.next();      log.debug(key + "=" + m_Views.get(key));     }    } catch (IOException ex) {      log.error("prepareViewUrls()",ex);      return;    }    log.info(getLogMessage("jwma.kernel.prepared.vurls"));  }//prepareViewUrls  /**   * Returns the active <tt>JwmaConfiguration</tt>   * instance.   *   * @return a <tt>JwmaConfiguration</tt> instance.   */  public JwmaConfiguration getConfiguration() {    return m_Configuration;  }//getConfiguration  /**   * Returns the controller URL setting of the local   * jwma installation.   *   * @return local controller's URL as <tt>String</tt>.   */  public String getMainControllerUrl() {    return m_MainController;  }//getMainControllerUrl  /**   * Returns the sendmail controller URL setting of the local   * jwma installation.   *   * @return local sendmail controller's URL as <tt>String</tt>.   */  public String getSendMailControllerUrl() {    return m_MailingController;  }//getSendMailControllerUrl  /**   * Returns the admin controller URL setting of the local   * jwma installation.   *   * @return local admin controller's URL as <tt>String</tt>.   */  public String getAdminControllerUrl() {

⌨️ 快捷键说明

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