/************************************************************************** /* GUI application for document search. /* /* Copyright (c) 2003-2004 by Bernhard Bablok (mail@bablokb.de) /* /* This library is free software; you can redistribute it and/or modify /* it under the terms of the GNU Lesser General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This library is distributed in the hope that it will be useful, but /* WITHOUT ANY WARRANTY; without even the implied warranty of /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /* GNU Lesser General Public License for more details. /* /* You should have received a copy of the GNU Lesser General Public License /* along with this library; see the file COPYING.LESSER. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ package de.bablokb.luala.app; import java.util.*; import java.io.*; import java.net.*; import java.awt.*; import javax.swing.*; import gnu.getopt.*; import org.apache.lucene.document.*; import de.bablokb.luala.lib.*; import de.bablokb.luala.lib.event.*; import de.bablokb.luala.lib.gui.*; /** GUI application for document search.
TODO:Add options using getopt. @version $Revision: 1.15 $ @author $Author: bablokb $ */ public class GuiSearcher implements SearchEventListener, ShowDocumentEventListener { //////////////////////////////////////////////////////////////////////////// /** String-constant for the properties-file. */ private static final String GUI_SEARCHER_PROPERTIES = "/GuiSearcher.properties"; //////////////////////////////////////////////////////////////////////////// /** The index directory. */ private String iIndexDir; //////////////////////////////////////////////////////////////////////////// /** The browser to use for hyperlinks. */ private String iBrowser; //////////////////////////////////////////////////////////////////////////// /** The path-prefix. */ private String iPathPrefix = ""; //////////////////////////////////////////////////////////////////////////// /** The start-page. */ private String iStartPage = ""; //////////////////////////////////////////////////////////////////////////// /** The debug-mode. */ private boolean iDebug = false; //////////////////////////////////////////////////////////////////////////// /** The singleton-object of this class. */ private static GuiSearcher iSearcher = new GuiSearcher(); //////////////////////////////////////////////////////////////////////////// /** The {@link SearchPanel} for this application. */ private SearchPanel iSearchPanel; //////////////////////////////////////////////////////////////////////////// /** The {@link ResultView} for this application. */ private ResultView iResultView; //////////////////////////////////////////////////////////////////////////// /** The {@link MessageLine} for this application. */ private MessageLine iMessageLine; ///////////////////////////////////////////////////////////////////////////// /** A private constructor, since we use the singleton-design pattern. Use {@link #getInstance()} to access the singleton. */ private GuiSearcher() { } ///////////////////////////////////////////////////////////////////////////// /** Query the singleton-instance. @return The singleton instance. */ public static GuiSearcher getInstance() { return iSearcher; } //////////////////////////////////////////////////////////////////////////// /** Display Usage information and exit. */ private void usage() { System.out.println("\nusage: java " + GuiSearcher.class.getName() + " -i indexDir -b browser [-p path-prefix] [-dh] start-page\n\n" + "valid options:\n" + "\t-i indexDir directory with the index-files (required)\n" + "\t-b browser browser to use for results (required)\n" + "\t-p path-prefix a prefix to prepend to the results\n" + "\t-d display debug-output\n" + "\t-h display usage-information and exit\n" ); System.exit(1); } //////////////////////////////////////////////////////////////////////////// /** Parse commandline arguments. @param args The cmd-line arguments. */ private void parseArguments(String[] args) { Getopt g = new Getopt(GuiSearcher.class.getName(),args, ":i:b:p:dh"); int c; while ((c = g.getopt()) != -1) { switch(c) { case 'i': iIndexDir = g.getOptarg(); break; case 'b': iBrowser = g.getOptarg(); break; case 'p': iPathPrefix = g.getOptarg(); break; case 'd': iDebug = true; break; case 'h': case ':': case '?': usage(); break; default: break; } } if (g.getOptind() == args.length-1) iStartPage = args[g.getOptind()]; else usage(); } //////////////////////////////////////////////////////////////////////////// /** Check arguments. */ private void checkArguments() { if (iIndexDir == null || iBrowser == null || iStartPage == null) usage(); if (! new File(iIndexDir).isDirectory()) { System.err.println("error: " + iIndexDir + " does not exist!"); usage(); } } //////////////////////////////////////////////////////////////////////////// /** Main-program. Currently, the program just supports three command-line arguments: