01: /*
02: * regain - A file search engine providing plenty of formats
03: * Copyright (C) 2004 Til Schneider
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * Contact: Til Schneider, info@murfman.de
20: *
21: * CVS information:
22: * $RCSfile$
23: * $Source$
24: * $Date: 2005-08-15 23:50:09 +0200 (Mo, 15 Aug 2005) $
25: * $Author: til132 $
26: * $Revision: 165 $
27: */
28: package net.sf.regain.search.sharedlib;
29:
30: import java.io.File;
31:
32: import net.sf.regain.RegainException;
33: import net.sf.regain.search.SearchToolkit;
34: import net.sf.regain.search.config.IndexConfig;
35: import net.sf.regain.util.sharedtag.PageRequest;
36: import net.sf.regain.util.sharedtag.PageResponse;
37: import net.sf.regain.util.sharedtag.SharedTag;
38:
39: /**
40: * Checks whether there is a index and whether a query was given. If one of
41: * these conditions is not fulfilled, a redirect to another page is sent.
42: * <p>
43: * Tag Parameters:
44: * <ul>
45: * <li><code>noIndexUrl</code>: The URL to redirect to if there is no index.</li>
46: * <li><code>noQueryUrl</code>: The URL to redirect to if there is no query.</li>
47: * </ul>
48: *
49: * @author Til Schneider, www.murfman.de
50: */
51: public class CheckTag extends SharedTag {
52:
53: /**
54: * Called when the parser reaches the end tag.
55: *
56: * @param request The page request.
57: * @param response The page response.
58: * @throws RegainException If there was an exception.
59: */
60: public void printEndTag(PageRequest request, PageResponse response)
61: throws RegainException {
62: // Check whether the indexes exist
63: IndexConfig[] indexConfigArr = SearchToolkit
64: .getIndexConfigArr(request);
65: for (int i = 0; i < indexConfigArr.length; i++) {
66: File indexdir = new File(indexConfigArr[i].getDirectory());
67: File newFile = new File(indexdir, "new");
68: File indexFile = new File(indexdir, "index");
69:
70: if (indexdir.exists() && !indexFile.exists()
71: && !newFile.exists()) {
72: // There is no index -> Forward to the noIndexUrl
73: String noIndexUrl = getParameter("noIndexUrl", true);
74: response.sendRedirect(noIndexUrl);
75: return;
76: }
77: }
78:
79: // Check whether there is a query
80: String query = SearchToolkit.getSearchQuery(request);
81: if ((query == null) || (query.length() == 0)) {
82: // There was no query specified -> Forward to the noQueryUrl
83: String noQueryUrl = getParameter("noQueryUrl", false);
84: if (noQueryUrl != null) {
85: response.sendRedirect(noQueryUrl);
86: return;
87: }
88: }
89: }
90:
91: }
|