001: /*
002: * regain - A file search engine providing plenty of formats
003: * Copyright (C) 2004 Til Schneider
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Contact: Til Schneider, info@murfman.de
020: *
021: * CVS information:
022: * $RCSfile$
023: * $Source$
024: * $Date: 2005-08-13 11:22:50 +0200 (Sa, 13 Aug 2005) $
025: * $Author: til132 $
026: * $Revision: 156 $
027: */
028: package net.sf.regain.ui.desktop;
029:
030: import java.io.File;
031: import java.net.MalformedURLException;
032: import java.net.URL;
033:
034: import net.sf.regain.RegainException;
035: import net.sf.regain.RegainToolkit;
036: import net.sf.regain.util.sharedtag.simple.ExecuterParser;
037: import net.sf.regain.util.sharedtag.simple.SimplePageRequest;
038:
039: import org.apache.log4j.Logger;
040: import org.apache.log4j.PropertyConfigurator;
041:
042: /**
043: * Starts the desktop search.
044: *
045: * @author Til Schneider, www.murfman.de
046: */
047: public class Main implements DesktopConstants {
048:
049: /** The logger for this class */
050: private static Logger mLog = Logger.getLogger(Main.class);
051:
052: /**
053: * The main entry point.
054: *
055: * @param args The command line arguments.
056: */
057: public static void main(String[] args) {
058: // Initialize the configuration
059: // (Copy all files from the default dir that don't exist in the config dir)
060: String[] defaultFileArr = DEFAULT_CONFIG_DIR.list();
061: for (int i = 0; i < defaultFileArr.length; i++) {
062: File confFile = new File(CONFIG_DIR, defaultFileArr[i]);
063: if (!confFile.exists()) {
064: // This config file does not exist -> Copy the default file
065: File defaultConfFile = new File(DEFAULT_CONFIG_DIR,
066: defaultFileArr[i]);
067: try {
068: RegainToolkit.copyFile(defaultConfFile, confFile);
069: } catch (RegainException exc) {
070: System.out
071: .println("Copying default config file failed: "
072: + defaultConfFile.getAbsolutePath());
073: exc.printStackTrace();
074: System.exit(1); // Abort
075: }
076: }
077: }
078:
079: // Initialize Logging
080: File logConfigFile = new File("conf/log4j.properties");
081: if (!logConfigFile.exists()) {
082: System.out
083: .println("ERROR: Logging configuration file not found: "
084: + logConfigFile.getAbsolutePath());
085: System.exit(1); // Abort
086: }
087:
088: LOG_DIR.mkdir();
089: PropertyConfigurator.configure(logConfigFile.getAbsolutePath());
090: mLog.info("Logging initialized");
091:
092: // Initialize the search mask
093: URL baseurl;
094: try {
095: baseurl = new File("web").toURL();
096: } catch (MalformedURLException exc) {
097: exc.printStackTrace();
098: System.exit(1); // Abort
099: return;
100: }
101: SimplePageRequest.setResourceBaseUrl(baseurl);
102: SimplePageRequest.setWorkingDir(new File("."));
103: SimplePageRequest.setInitParameter("searchConfigFile",
104: "conf/SearchConfiguration.xml");
105: ExecuterParser.registerNamespace("search",
106: "net.sf.regain.search.sharedlib");
107: ExecuterParser.registerNamespace("config",
108: "net.sf.regain.ui.desktop.config.sharedlib");
109: ExecuterParser.registerNamespace("status",
110: "net.sf.regain.ui.desktop.status.sharedlib");
111:
112: // Start the Tray icon
113: TrayIconManager.getInstance().init();
114:
115: // Start the webserver
116: try {
117: DesktopToolkit.checkWebserver();
118: } catch (RegainException exc) {
119: exc.printStackTrace();
120: System.exit(1); // Abort
121: }
122:
123: // Start the index update manager
124: INDEX_DIR.mkdir();
125: IndexUpdateManager.getInstance().init();
126: }
127:
128: /**
129: * Quits the desktop search.
130: */
131: public static void quit() {
132: System.exit(0);
133: }
134:
135: }
|