source: other-projects/trunk/protemix/src/recpt/ptmxdocaction.cpp@ 14162

Last change on this file since 14162 was 3207, checked in by sjboddie, 22 years ago

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1/**********************************************************************
2 *
3 * ptmxdocaction.cpp --
4 * A component of the Greenstone digital library software
5 * from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Copyright (C) 2002 Stefan Boddie
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
27#include "ptmxdocaction.h"
28#include "OIDtools.h"
29#include "querytools.h"
30
31ptmxdocaction::ptmxdocaction () {
32}
33
34ptmxdocaction::~ptmxdocaction () {
35}
36
37void ptmxdocaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
38 recptprotolistclass *protos, ostream &logout) {
39
40 documentaction::define_internal_macros(disp, args, protos, logout);
41
42 // don't want header overridden for protemix collection
43 disp.setmacro ("header", "document", "_Global:header_");
44
45 // set _pagepdf_ metadata
46
47 if (!args["d"].empty()) {
48 text_t &collection = args["c"];
49 if (collection.empty()) return;
50 recptproto *collectproto = protos->getrecptproto (collection, logout);
51 if (collectproto == NULL) return;
52
53 FilterResponse_t response;
54 text_tset metadata;
55 metadata.insert("pdf");
56 if (get_info (args["d"], collection, metadata, false, collectproto, response, logout)) {
57 text_t &pdf = response.docInfo[0].metadata["pdf"].values[0];
58 if (!pdf.empty()) {
59 disp.setmacro ("pagepdf", "Global", pdf);
60 }
61 }
62 }
63}
64
65// overridden to format the querystring when highlighting text
66void ptmxdocaction::output_document (const text_t &OID, cgiargsclass &args,
67 recptproto *collectproto, displayclass &disp,
68 outconvertclass &outconvert, ostream &textout,
69 ostream &logout) {
70 FilterResponse_t inforesponse;
71 FilterResponse_t queryresponse;
72 text_tset metadata;
73 bool getParents = false;
74 bool highlight = false;
75 int wanttext = 0;
76 int arg_gt = args.getintarg("gt");
77 text_t &collection = args["c"];
78
79 // if we have a query string and highlighting is turned on we need
80 // to redo the query to get the terms for highlighting
81 if (args.getintarg("hl")) {
82 FilterRequest_t request;
83 comerror_t err;
84 request.filterResultOptions = FRmatchTerms;
85 text_t formattedstring = args["q"];
86 format_querystring (formattedstring, args.getintarg("b"));
87
88 // ------ for ptmx collection
89
90 void insert_equiv_terms(text_t&); // declaration
91 insert_equiv_terms(formattedstring);
92
93 // --------------
94
95 if (!formattedstring.empty()) {
96
97 set_queryfilter_options (request, formattedstring, args);
98 collectproto->filter (args["c"], request, queryresponse, err, logout);
99 if (err != noError) {
100 outconvertclass text_t2ascii;
101 logout << text_t2ascii
102 << "documentaction::output_document: call to QueryFilter failed "
103 << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
104 highlight = false;
105 } else {
106 highlight = true;
107 }
108 }
109 }
110
111
112 format_t *formatlistptr = new format_t();
113 parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
114
115 metadata.insert ("hastxt");
116 metadata.insert ("haschildren");
117
118 if (formatinfo.DocumentText == "[Text]")
119 wanttext = 1;
120 else {
121 char *docformat = formatinfo.DocumentText.getcstr();
122 if (strstr (docformat, "[Text]") != NULL)
123 wanttext = 2;
124 delete docformat;
125 }
126
127 if (get_info (OID, collection, metadata, getParents, collectproto, inforesponse, logout)) {
128 int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
129 int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
130
131 if (arg_gt == 0) {
132 output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
133 OID, highlight, hastxt, wanttext, collection, collectproto,
134 disp, outconvert, textout, logout);
135
136
137 } else {
138
139 ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
140
141 // text is to be expanded
142 text_t exOID = OID;
143 if (haschildren != 1) exOID = get_parent (OID);
144 if (exOID.empty()) exOID = OID;
145
146 // if we're not in a document (i.e. we're in a top level classification)
147 // we need to pass "is_classify = true" to get_contents so that it
148 // doesn't recurse all the way through each document in the classification
149 bool is_classify = false;
150 if (args["d"].empty()) is_classify = true;
151
152 get_contents (exOID, is_classify, metadata, collection,
153 collectproto, inforesponse, logout);
154
155 ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
156 ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
157
158 if (arg_gt == 1) {
159 // check if there are more than 10 sections containing text to be expanded -
160 // if there are output warning message - this isn't a great way to do this
161 // since the sections may be very large or very small - one day I'll fix it
162 // -- Stefan.
163 int seccount = 0;
164 while (sechere != secend) {
165 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
166 if (shastxt == 1) seccount ++;
167 if (seccount > 10) break;
168 sechere ++;
169 }
170 if (seccount > 10) {
171 // more than 10 sections so output warning message and text
172 // for current section only
173 textout << outconvert << disp << "_document:textltwarning_";
174
175 output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
176 OID, highlight, hastxt, wanttext, collection,
177 collectproto, disp, outconvert, textout, logout);
178
179 }
180 else arg_gt = 2;
181 }
182
183 if (arg_gt == 2) {
184 // get the text for each section
185 sechere = inforesponse.docInfo.begin();
186 int count = 0;
187 while (sechere != secend) {
188 textout << outconvert << disp << "\n<p><a name=" << (*sechere).OID << "></a>\n";
189
190 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
191
192 output_text (*sechere, formatlistptr, queryresponse.termInfo,
193 (*sechere).OID, highlight, shastxt, wanttext, collection,
194 collectproto, disp, outconvert, textout, logout);
195 count ++;
196 sechere ++;
197 }
198 }
199 }
200 }
201 delete formatlistptr;
202}
Note: See TracBrowser for help on using the repository browser.