source: trunk/gsdl/src/recpt/librarymain.cpp@ 1327

Last change on this file since 1327 was 1327, checked in by kjm18, 24 years ago

incorporated support for mgpp collections. searchclass and queryfilter type (mg/mgpp)
for a collection are determined on basis of buildtype field in build.cfg.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/**********************************************************************
2 *
3 * librarymain.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#include "receptionist.h"
27#include "cgiwrapper.h"
28#include "nullproto.h"
29#include "collectserver.h"
30#include "filter.h"
31#include "browsefilter.h"
32#include "mgqueryfilter.h"
33#include "mgppqueryfilter.h"
34#include "infodbclass.h"
35#include "mggdbmsource.h"
36#include "mgsearch.h"
37#include "mgppsearch.h"
38#include "fileutil.h"
39#include <assert.h>
40
41#include "action.h"
42#include "statusaction.h"
43#include "pageaction.h"
44#include "pingaction.h"
45#include "queryaction.h"
46#include "documentaction.h"
47#include "authenaction.h"
48#include "usersaction.h"
49#include "extlinkaction.h"
50#include "buildaction.h"
51#include "delhistoryaction.h"
52
53#include "browserclass.h"
54#include "vlistbrowserclass.h"
55#include "hlistbrowserclass.h"
56#include "datelistbrowserclass.h"
57#include "invbrowserclass.h"
58#include "pagedbrowserclass.h"
59#include "htmlbrowserclass.h"
60
61#include "recptconfig.h"
62
63int main () {
64 receptionist recpt;
65 nullproto nproto;
66
67 text_tarray collections;
68
69 // get gsdlhome
70 text_t gsdlhome;
71 site_cfg_read (gsdlhome);
72 text_t collectdir = filename_cat (gsdlhome, "collect");
73 read_dir (collectdir, collections);
74
75 text_tarray::const_iterator thiscol = collections.begin();
76 text_tarray::const_iterator endcol = collections.end();
77
78 while (thiscol != endcol) {
79
80 // ignore the modelcol
81
82 if (*thiscol == "modelcol") {
83 thiscol ++;
84 continue;
85 }
86
87 // read config file to see if built with mg or mgpp
88 text_t buildtype = "mg"; // mg is default
89 text_tarray cfgline;
90 text_t key;
91 text_t filename = filename_cat(collectdir, *thiscol, "index/build.cfg");
92 ifstream confin(filename.getcstr());
93
94 if (confin) {
95 while (read_cfg_line(confin, cfgline) >= 0) {
96 if (cfgline.size() ==2 ) {
97 key = cfgline[0];
98 cfgline.erase(cfgline.begin());
99 if (key =="buildtype") {
100 buildtype = cfgline[0];
101 break;
102 }
103 }
104 }
105 }
106
107 confin.close();
108
109 // this memory is created but never destroyed
110 // we're also not doing any error checking to make sure we didn't
111 // run out of memory
112 collectserver *cserver = new collectserver();
113 gdbmclass *gdbmhandler = new gdbmclass();
114
115 // add a null filter
116 filterclass *filter = new filterclass ();
117 cserver->add_filter (filter);
118
119 // add a browse filter
120 browsefilterclass *browsefilter = new browsefilterclass();
121 browsefilter->set_gdbmptr (gdbmhandler);
122 cserver->add_filter (browsefilter);
123
124 if (buildtype == "mg") {
125 mgsearchclass *mgsearch = new mgsearchclass();
126
127 // add a query filter
128 mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
129 queryfilter->set_gdbmptr (gdbmhandler);
130 queryfilter->set_mgsearchptr (mgsearch);
131 cserver->add_filter (queryfilter);
132
133 // add a mg and gdbm source
134 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
135 mggdbmsource->set_gdbmptr (gdbmhandler);
136 mggdbmsource->set_mgsearchptr (mgsearch);
137 cserver->add_source (mggdbmsource);
138
139 }
140 else if (buildtype == "mgpp") {
141
142 mgppsearchclass *mgsearch = new mgppsearchclass();
143
144 // add a query filter
145 mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
146 queryfilter->set_gdbmptr (gdbmhandler);
147 queryfilter->set_mgsearchptr (mgsearch);
148 cserver->add_filter (queryfilter);
149
150 // add a mg and gdbm source
151 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
152 mggdbmsource->set_gdbmptr (gdbmhandler);
153 mggdbmsource->set_mgsearchptr (mgsearch);
154 cserver->add_source (mggdbmsource);
155
156 }
157
158 // inform collection server and everything it contains about its
159 // collection name
160 cserver->configure ("collection", *thiscol);
161
162 // configure receptionist's collectinfo structure
163 text_tarray colinfo;
164 colinfo.push_back (*thiscol);
165 colinfo.push_back (gsdlhome);
166 colinfo.push_back (gsdlhome);
167 recpt.configure ("collectinfo", colinfo);
168
169 nproto.add_collectserver (cserver);
170 thiscol ++;
171 }
172
173 // add the protocol to the receptionist
174 recpt.add_protocol (&nproto);
175
176 // add other converters
177 utf8inconvertclass utf8inconvert;
178 utf8outconvertclass utf8outconvert;
179 recpt.add_converter ("u", &utf8inconvert, &utf8outconvert);
180
181 mapinconvertclass gbinconvert;
182 gbinconvert.setmapfile (gsdlhome, "gbku", 0x25a1);
183 mapoutconvertclass gboutconvert;
184 gboutconvert.setmapfile (gsdlhome, "ugbk", 0xa1f5);
185 recpt.add_converter ("g", &gbinconvert, &gboutconvert);
186
187 text_t armapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
188 armapfile = filename_cat (armapfile, "WINDOWS", "1256.TXT");
189 simplemapinconvertclass arinconvert;
190 arinconvert.setmapfile (armapfile);
191 simplemapoutconvertclass aroutconvert;
192 aroutconvert.setmapfile (armapfile);
193 recpt.add_converter ("a", &arinconvert, &aroutconvert);
194
195
196 // the list of actions. Note: these actions will become invalid
197 // at the end of this function.
198 statusaction astatusaction;
199 astatusaction.set_receptionist (&recpt);
200 recpt.add_action (&astatusaction);
201
202 pageaction apageaction;
203 apageaction.set_receptionist (&recpt);
204 recpt.add_action (&apageaction);
205
206 pingaction apingaction;
207 recpt.add_action (&apingaction);
208
209 queryaction aqueryaction;
210 aqueryaction.set_receptionist (&recpt);
211 recpt.add_action (&aqueryaction);
212
213 documentaction adocumentaction;
214 adocumentaction.set_receptionist (&recpt);
215 recpt.add_action (&adocumentaction);
216
217 usersaction ausersaction;
218 recpt.add_action (&ausersaction);
219
220 extlinkaction anextlinkaction;
221 recpt.add_action (&anextlinkaction);
222
223 buildaction abuildaction;
224 abuildaction.set_receptionist (&recpt);
225 recpt.add_action (&abuildaction);
226
227 authenaction aauthenaction;
228 aauthenaction.set_receptionist(&recpt);
229 recpt.add_action (&aauthenaction);
230
231 delhistoryaction adelhistoryaction;
232 recpt.add_action(&adelhistoryaction);
233
234 // list of browsers
235 vlistbrowserclass avlistbrowserclass;
236 recpt.add_browser (&avlistbrowserclass);
237 recpt.setdefaultbrowser ("VList");
238
239 hlistbrowserclass ahlistbrowserclass;
240 recpt.add_browser (&ahlistbrowserclass);
241
242 datelistbrowserclass adatelistbrowserclass;
243 recpt.add_browser (&adatelistbrowserclass);
244
245 invbrowserclass ainvbrowserclass;
246 recpt.add_browser (&ainvbrowserclass);
247
248 pagedbrowserclass apagedbrowserclass;
249 recpt.add_browser (&apagedbrowserclass);
250
251 htmlbrowserclass ahtmlbrowserclass;
252 recpt.add_browser (&ahtmlbrowserclass);
253
254 cgiwrapper (recpt, "");
255 return 0;
256}
Note: See TracBrowser for help on using the repository browser.