001: /*
002: * CVS information:
003: * $RCSfile$
004: * $Source$
005: * $Date: 2005-04-15 10:47:04 +0200 (Fr, 15 Apr 2005) $
006: * $Author: til132 $
007: * $Revision: 132 $
008: */
009: package net.sf.regain.search.config;
010:
011: import java.util.Properties;
012:
013: import net.sf.regain.RegainException;
014: import net.sf.regain.RegainToolkit;
015: import net.sf.regain.search.access.SearchAccessController;
016:
017: /**
018: * The configuration for one index.
019: *
020: * @author Tilman Schneider, STZ-IDA an der FH Karlsruhe
021: */
022: public class IndexConfig {
023:
024: /** Default list of index fields to search in. */
025: protected static final String[] DEFAULT_SEARCH_FIELD_LIST = {
026: "content", "title", "headlines" };
027:
028: /** The name of the index. */
029: private String mName;
030:
031: /** The directory where the index is located. */
032: private String mDirectory;
033:
034: /**
035: * The regular expression that identifies URLs that should be opened in a new
036: * window.
037: */
038: private String mOpenInNewWindowRegex;
039:
040: /** Whether the file-to-http-bridge should be used. */
041: private boolean mUseFileToHttpBridge;
042:
043: /**
044: * The index fields to search by default.
045: * <p>
046: * NOTE: The user may search in other fields also using the "field:"-operator.
047: * Read the
048: * <a href="http://jakarta.apache.org/lucene/docs/queryparsersyntax.html">lucene query syntax</a>
049: * for details.
050: */
051: private String[] mSearchFieldList;
052:
053: /**
054: * The URL rewrite rules.
055: * <p>
056: * Contains pairs of URL prefixes: The first prefix will be replaced by the
057: * second.
058: * <p>
059: * E.g.:
060: * <pre>
061: * new String[][] {
062: * { "file://c:/webcontent", "http://www.mydomain.de" },
063: * { "file://n:/docs", "file://///fileserver/public/docs" },
064: * };
065: * </pre>
066: */
067: private String[][] mRewriteRules;
068:
069: /** The SearchAccessController to use. May be <code>null</code>. */
070: private SearchAccessController mSearchAccessController;
071:
072: /**
073: * Creates a new instance of IndexConfig.
074: *
075: * @param name The name of the index.
076: * @param directory The directory where the index is located.
077: * @param openInNewWindowRegex The regular expression that identifies URLs
078: * that should be opened in a new window.
079: * @param useFileToHttpBridge Whether the file-to-http-bridge should be used.
080: * See {@link #getUseFileToHttpBridge()} for details.
081: * @param searchFieldList The index fields to search by default.
082: * @param rewriteRules The URL rewrite rules. Contains pairs of URL prefixes:
083: * The first prefix will be replaced by the second.
084: * @param searchAccessControllerClass The class name of the
085: * {@link SearchAccessController} to use.
086: * @param searchAccessControllerJar The name of jar file to load the
087: * {@link SearchAccessController} from.
088: * @param searchAccessControllerConfig The configuration for the
089: * {@link SearchAccessController}.
090: * @throws RegainException If loading the SearchAccessController failed.
091: */
092: public IndexConfig(String name, String directory,
093: String openInNewWindowRegex, boolean useFileToHttpBridge,
094: String[] searchFieldList, String[][] rewriteRules,
095: String searchAccessControllerClass,
096: String searchAccessControllerJar,
097: Properties searchAccessControllerConfig)
098: throws RegainException {
099: mName = name;
100: mDirectory = directory;
101: mOpenInNewWindowRegex = openInNewWindowRegex;
102: mUseFileToHttpBridge = useFileToHttpBridge;
103: mSearchFieldList = searchFieldList;
104: mRewriteRules = rewriteRules;
105:
106: if (searchAccessControllerClass != null) {
107: mSearchAccessController = (SearchAccessController) RegainToolkit
108: .createClassInstance(searchAccessControllerClass,
109: SearchAccessController.class,
110: searchAccessControllerJar);
111:
112: if (searchAccessControllerConfig == null) {
113: searchAccessControllerConfig = new Properties();
114: }
115: mSearchAccessController.init(searchAccessControllerConfig);
116: }
117: }
118:
119: /**
120: * Gets the name of the index.
121: *
122: * @return The name of the index.
123: */
124: public String getName() {
125: return mName;
126: }
127:
128: /**
129: * Gets the directory where the index is located.
130: *
131: * @return The directory where the index is located.
132: */
133: public String getDirectory() {
134: return mDirectory;
135: }
136:
137: /**
138: * Gets the regular expression that identifies URLs that should be opened in
139: * a new window.
140: *
141: * @return The regular expression that identifies URLs that should be opened
142: * in a new window.
143: */
144: public String getOpenInNewWindowRegex() {
145: return mOpenInNewWindowRegex;
146: }
147:
148: /**
149: * Gets whether the file-to-http-bridge should be used for file-URLs.
150: * <p>
151: * Mozilla browsers have a security mechanism that blocks loading file-URLs
152: * from pages loaded via http. To be able to load files from the search
153: * results, regain offers the file-to-http-bridge that provides all files that
154: * are listed in the index via http.
155: *
156: * @return Whether the file-to-http-bridge should be used.
157: */
158: public boolean getUseFileToHttpBridge() {
159: return mUseFileToHttpBridge;
160: }
161:
162: /**
163: * Gets the index fields to search by default.
164: * <p>
165: * NOTE: The user may search in other fields also using the "field:"-operator.
166: * Read the
167: * <a href="http://jakarta.apache.org/lucene/docs/queryparsersyntax.html">lucene query syntax</a>
168: * for details.
169: *
170: * @return The index fields to search by default.
171: */
172: public String[] getSearchFieldList() {
173: return mSearchFieldList;
174: }
175:
176: /**
177: * Gets the URL rewrite rules.
178: * <p>
179: * The returned array contains pairs of URL prefixes: The first prefix will be
180: * replaced by the second.
181: * <p>
182: * E.g.:
183: * <pre>
184: * new String[][] {
185: * { "file://c:/webcontent", "http://www.mydomain.de" },
186: * { "file://n:/docs", "file://///fileserver/public/docs" },
187: * };
188: * </pre>
189: *
190: * @return The URL rewrite rules. May be null;
191: */
192: public String[][] getRewriteRules() {
193: return mRewriteRules;
194: }
195:
196: /**
197: * Gets the SearchAccessController to use. Returns <code>null</code> if no
198: * SearchAccessController should be used.
199: *
200: * @return The SearchAccessController.
201: */
202: public SearchAccessController getSearchAccessController() {
203: return mSearchAccessController;
204: }
205:
206: }
|