source: trunk/cstr/src/recpt/cstrdocaction.cpp@ 891

Last change on this file since 891 was 891, checked in by sjboddie, 24 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 14.9 KB
Line 
1/**********************************************************************
2 *
3 * cstrdocaction.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 * $Id: cstrdocaction.cpp 891 2000-02-01 22:32:36Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.1 2000/02/01 22:32:37 sjboddie
31 Initial revision
32
33 Revision 1.1 1999/09/07 21:49:42 sjboddie
34 new cstr receptionist
35
36 */
37
38
39#include <string.h>
40#include "cstrdocaction.h"
41#include "cstrbrowsetools.h"
42#include "OIDtools.h"
43#include "querytools.h"
44#include "unitool.h"
45
46cstrdocaction::cstrdocaction () {
47 // this action uses cgi variable "gg" and "gga" as well as
48 // those used by the standard documentaction
49
50 cgiarginfo arg_ainfo;
51
52 // in this action "gg" is the format of the
53 // document to view (i.e. "text", "postscript", "abstract", "figures", or "facsimiles")
54 arg_ainfo.shortname = "gg";
55 arg_ainfo.longname = "document format";
56 arg_ainfo.multiplechar = true;
57 arg_ainfo.defaultstatus = cgiarginfo::weak;
58 arg_ainfo.argdefault = "text";
59 arg_ainfo.savedarginfo = cgiarginfo::can;
60 argsinfo.addarginfo (NULL, arg_ainfo);
61
62 // in this action "gga" is the path to the postscript
63 // when "gg" == "postscript
64 arg_ainfo.shortname = "gga";
65 arg_ainfo.longname = "postscript path";
66 arg_ainfo.multiplechar = true;
67 arg_ainfo.defaultstatus = cgiarginfo::none;
68 arg_ainfo.argdefault = "";
69 arg_ainfo.savedarginfo = cgiarginfo::mustnot;
70 argsinfo.addarginfo (NULL, arg_ainfo);
71
72}
73
74cstrdocaction::~cstrdocaction () {
75}
76
77
78void cstrdocaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass * /*protos*/,
79 response_t &response,text_t &response_data,
80 ostream &/*logout*/) {
81
82 if (args["gg"] == "postscript") {
83 response = location;
84 response_data = args["gga"];
85 } else {
86 response = content;
87 response_data = "text/html";
88 }
89}
90
91
92void cstrdocaction::set_java_macros (cgiargsclass &args, displayclass &disp) {
93
94 text_t javaimagescontent = "_javaextras__javapostscript_";
95
96 text_t &arg_gg = args["gg"];
97 if (arg_gg == "text")
98 javaimagescontent += "_javaabstract__javafigures_";
99 else if (arg_gg == "abstract")
100 javaimagescontent += "_javafigures__javaviewtext_";
101 else if (arg_gg == "figures")
102 javaimagescontent += "_javaabstract__javaviewtext_";
103 else if (arg_gg == "facsimiles")
104 javaimagescontent += "_javaabstract__javaviewtext__javafigures_";
105
106 int arg_gt = args.getintarg("gt");
107 // int arg_gc = args.getintarg("gc");
108 int arg_hl = args.getintarg("hl");
109
110 text_tarray::const_iterator button_here = formatinfo.DocumentButtons.begin();
111 text_tarray::const_iterator button_end = formatinfo.DocumentButtons.end();
112
113 while (button_here != button_end) {
114 if (*button_here == "Detach")
115 javaimagescontent += "_javadetach_";
116 else if (*button_here == "Expand Text" && arg_gg == "text") {
117 if (arg_gt == 1)
118 javaimagescontent += "_javacontracttext__javacontinue_";
119 else if (arg_gt == 2)
120 javaimagescontent += "_javacontracttext_";
121 else
122 javaimagescontent += "_javaexpandtext_";
123 // } else if (*button_here == "Expand Contents") {
124 // if (arg_gc == 1)
125 // javaimagescontent += "_javacontractcontents_";
126 // else
127 // javaimagescontent += "_javaexpandcontents_";
128 } else if (*button_here == "Highlight" && arg_gg == "text") {
129 if (arg_hl == 1)
130 javaimagescontent += "_javanohighlighting_";
131 else
132 javaimagescontent += "_javahighlighting_";
133 }
134 button_here ++;
135 }
136 disp.setmacro ("javaimagescontent", "document", javaimagescontent);
137}
138
139
140
141/*
142// define all the macros which are related to pages generated
143// by this action. we also load up the formatinfo structure
144// here (it's used in do_action as well as here)
145void cstrdocaction::define_internal_macros (const ColInfoResponse_t &collectinfo, displayclass &disp,
146 cgiargsclass &args, recptproto *collectproto,
147 ostream &logout) {
148
149 // define_internal_macros sets the following macros:
150
151 // _pagetitle_ the title to be displayed at the top of the browser window
152
153 // _imagethispage_ the title image to be displayed at top right of page
154
155 // _classificationlinks_ the links between classifications to be displayed
156 // at top of list or datelist classifications
157
158 // _httpprevarrow_ these are set if next or previous arrows
159 // _httpnextarrow_ are to be used - (i.e. if it's an AZList or a DateList
160 // classifytype at a top level or if it's a Book or a
161 // Hierarchy classifytype at document level
162
163 // _navarrows_ this may be overridden to "" when format option
164 // DocumentArrowsBottom is false
165
166 // _header_ the header macro is overridden if we're not at a top level
167 // classification to remove the title block
168
169 // _javaimagescontent_ this is the javascript code to shove in to make the
170 // flashy buttons work
171
172 // _thisOID_ the OID (directory) of the current document - this corresponds
173 // to the archivedir metadata element
174
175 // can't do anything if collectproto is null (i.e. no collection was specified)
176 if (collectproto == NULL) return;
177
178 text_tarray metadata;
179 FilterResponse_t response;
180 text_t &arg_d = args["d"];
181 text_t &arg_cl = args["cl"];
182 text_t &collection = args["c"];
183 int gt = args.getintarg("gt");
184 load_formatinfo (collectinfo.format, gt);
185
186 // don't want arrows or goto if we're in figures or facsimiles
187 if (args["gg"] != "text") {
188 formatinfo.DocumentArrowsBottom = false;
189 formatinfo.DocumentArrowsTop = false;
190 formatinfo.DocumentGoTo = false;
191 }
192
193 if (!formatinfo.DocumentArrowsBottom)
194 disp.setmacro("navarrows", "document", "");
195
196 metadata.push_back ("Title");
197 metadata.push_back ("classifytype");
198 metadata.push_back ("archivedir");
199
200 if (!arg_d.empty()) {
201 // we're at document level
202
203 // get metadata for this document and it's parents
204 if (get_info (arg_d, collection, metadata, true, collectproto, response, logout)) {
205 disp.setmacro ("header", "document", "_textheader_");
206
207 disp.setmacro ("thisOID", "Global", response.docInfo[0].metadata[2].values[0]);
208
209 text_t &classifytype = response.docInfo[0].metadata[1].values[0];
210 if (classifytype.empty()) classifytype = "Book"; // defaults to Book
211
212 // set arrow macros if required
213 if (((classifytype == "Book") && (formatinfo.DocumentArrowsTop || formatinfo.DocumentArrowsBottom)) ||
214 ((classifytype == "Hierarchy") && formatinfo.DocumentArrowsBottom))
215 set_arrow_macros (arg_d, classifytype, formatinfo.DocumentTopPages,
216 disp, collectproto, collection, logout);
217
218 if (args["u"] != "1")
219 set_java_macros (args, disp);
220
221 }
222 } else {
223 if (!arg_cl.empty()) {
224
225 // get metadata for top level classification
226 text_t classtop;
227 get_top (arg_cl, classtop);
228 if (get_info (classtop, collection, metadata, false, collectproto, response, logout)) {
229
230 text_t &title = response.docInfo[0].metadata[0].values[0];
231 text_t &classifytype = response.docInfo[0].metadata[1].values[0];
232
233 disp.setmacro ("pagetitle", "document", "_text" + title + "page_");
234 disp.setmacro ("imagethispage", "document", "_icon" + title + "page_");
235
236 // now get the metadata for each child of top level
237 // so we can generate the _classificationlinks_ and arrow macros
238 // (if they're required by the current classification type)
239
240 if ((classifytype == "AZList") || (classifytype == "DateList"))
241 get_classificationlinks (arg_cl, collection, collectproto, disp, logout);
242
243 }
244 }
245 }
246}
247
248*/
249
250void cstrdocaction::output_document (const text_t &OID, cgiargsclass &args,
251 recptproto *collectproto, displayclass &disp,
252 outconvertclass &outconvert, ostream &textout,
253 ostream &logout) {
254 FilterResponse_t inforesponse;
255 text_tset metadata;
256 bool getParents = false;
257 text_t &collection = args["c"];
258 text_t &arg_gg = args["gg"];
259
260 if (arg_gg == "abstract") {
261 metadata.insert ("Description");
262 text_t top;
263 get_top (OID, top);
264 if (get_info (top, collection, metadata, getParents, collectproto, inforesponse, logout)) {
265 text_t &description = inforesponse.docInfo[0].metadata["Description"].values[0];
266
267 if (!description.empty())
268 textout << outconvert << disp << "<p>\n" << description << "\n";
269 else
270 textout << outconvert << disp << "_textnoabstract_";
271 }
272 } else if (arg_gg == "figures") {
273 metadata.insert ("figures");
274 text_t top;
275 get_top (OID, top);
276 if (get_info (top, collection, metadata, false, collectproto, inforesponse, logout)) {
277 text_t &figures = inforesponse.docInfo[0].metadata["figures"].values[0];
278
279 if (!figures.empty()) {
280 text_tarray figure_array;
281 splitchar (figures.begin(), figures.end(), ',', figure_array);
282 text_tarray::const_iterator this_figure = figure_array.begin();
283 text_tarray::const_iterator end_figure = figure_array.end();
284 while (this_figure != end_figure) {
285 textout << outconvert << disp
286 << "<p><center><img border=1 src=\"_httpcollection_/archives/_thisOID_/"
287 << *this_figure << "\"></center>\n";
288 this_figure ++;
289 }
290 } else {
291 textout << outconvert << disp << "_textnofigures_";
292 }
293 }
294 } else if (arg_gg == "facsimiles") {
295 metadata.insert ("facsimiles");
296 text_t top;
297 get_top (OID, top);
298 if (get_info (top, collection, metadata, false, collectproto, inforesponse, logout)) {
299 text_t &facsimiles = inforesponse.docInfo[0].metadata["facsimiles"].values[0];
300
301 if (!facsimiles.empty()) {
302 text_tarray facs_array;
303 splitchar (facsimiles.begin(), facsimiles.end(), ',', facs_array);
304 text_tarray::const_iterator this_facs = facs_array.begin();
305 text_tarray::const_iterator end_facs = facs_array.end();
306 while (this_facs != end_facs) {
307 textout << outconvert << disp
308 << "<p><center><img border=1 src=\"_httpcollection_/archives/_thisOID_/"
309 << *this_facs << "\"></center>\n";
310 this_facs ++;
311 }
312 } else {
313 textout << outconvert << disp << "_textnofacsimiles_";
314 }
315 }
316
317 } else {
318
319 FilterResponse_t queryresponse;
320 bool highlight = false;
321 int wanttext = 0;
322 int arg_gt = args.getintarg("gt");
323
324 // if we have a query string and highlighting is turned on we need
325 // to redo the query to get the terms for highlighting
326 if (!args["q"].empty() && args.getintarg("hl")) {
327 FilterRequest_t request;
328 request.filterResultOptions = FRmatchTerms;
329 comerror_t err;
330 text_t formattedstring = args["q"];
331 format_querystring(formattedstring, args.getintarg("b"));
332 set_queryfilter_options (request, formattedstring, args);
333 collectproto->filter (args["c"], request, queryresponse, err, logout);
334 if (err != noError) {
335 outconvertclass text_t2ascii;
336 logout << text_t2ascii
337 << "documentaction::output_document: call to QueryFilter failed "
338 << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
339 highlight = false;
340 } else {
341 highlight = true;
342 }
343
344 }
345
346 format_t *formatlistptr = new format_t();
347 parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
348
349 metadata.insert ("hastxt");
350 metadata.insert ("haschildren");
351
352 if (formatinfo.DocumentText == "[Text]")
353 wanttext = 1;
354 else {
355 char *docformat = formatinfo.DocumentText.getcstr();
356 if (strstr (docformat, "[Text]") != NULL)
357 wanttext = 2;
358 delete docformat;
359 }
360
361 int metasize = metadata.size();
362
363 if (get_info (OID, collection, metadata, getParents, collectproto, inforesponse, logout)) {
364 int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
365 int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
366
367 if (arg_gt == 0) {
368 output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
369 OID, highlight, hastxt, wanttext, collection, collectproto,
370 disp, outconvert, textout, logout);
371
372
373 } else {
374
375 ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
376
377 // text is to be expanded
378 text_t exOID = OID;
379 if (haschildren != 1) exOID = get_parent (OID);
380 if (exOID.empty()) exOID = OID;
381
382 // if we're not in a document (i.e. we're in a top level classification)
383 // we need to pass the "classify" string to get_contents so that it
384 // doesn't recurse all the way through each document in the classification
385 bool is_classify = false;
386 if (args["d"].empty()) is_classify = true;
387
388 get_contents (exOID, is_classify, metadata, collection,
389 collectproto, inforesponse, logout);
390
391 ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
392 ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
393
394 if (arg_gt == 1) {
395 // check if there are more than 10 sections containing text to be expanded -
396 // if there are output warning message - this isn't a great way to do this
397 // since the sections may be very large or very small - one day I'll fix it
398 // -- Stefan.
399 int seccount = 0;
400 while (sechere != secend) {
401 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
402 if (shastxt == 1) seccount ++;
403 if (seccount > 10) break;
404 sechere ++;
405 }
406 if (seccount > 10) {
407 // more than 10 sections so output warning message and text
408 // for current section only
409 textout << outconvert << disp << "_document:textltwarning_";
410
411 output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
412 OID, highlight, hastxt, wanttext, collection,
413 collectproto, disp, outconvert, textout, logout);
414
415 }
416 else arg_gt = 2;
417 }
418
419 if (arg_gt == 2) {
420 // get the text for each section
421 sechere = inforesponse.docInfo.begin();
422 int count = 0;
423 while (sechere != secend) {
424 textout << outconvert << disp << "\n<p><a name=" << count << "></a>\n";
425
426 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
427
428 output_text (*sechere, formatlistptr, queryresponse.termInfo,
429 (*sechere).OID, highlight, shastxt, wanttext, collection,
430 collectproto, disp, outconvert, textout, logout);
431 count ++;
432 sechere ++;
433 }
434 }
435 }
436 }
437 delete formatlistptr;
438 }
439}
Note: See TracBrowser for help on using the repository browser.