source: trunk/protemix/src/recpt/ptmxdocaction.cpp@ 3182

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

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 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 if (!args["c1"].empty() && args["c1"] != "Any") {
91 // formattedstring = "[" + args["c1"] + "]:CL";
92 formattedstring = args["c1"];
93 }
94 if (!args["c2"].empty() && args["c2"] != "Any") {
95 if (!formattedstring.empty()) formattedstring += " & ";
96 // formattedstring += "[" + args["c2"] + "]:CA";
97 formattedstring += args["c2"];
98 }
99 if (!args["c3"].empty() && args["c3"] != "Any") {
100 if (!formattedstring.empty()) formattedstring += " & ";
101 // formattedstring += "[" + args["c3"] + "]:CS";
102 formattedstring += args["c3"];
103 }
104 if (!args["q"].empty()) {
105 if (!formattedstring.empty()) formattedstring += " & ";
106 formattedstring += args["q"];
107 }
108
109 void insert_equiv_terms(text_t&); // declaration
110 insert_equiv_terms(formattedstring);
111
112 // --------------
113
114 if (!formattedstring.empty()) {
115
116 set_queryfilter_options (request, formattedstring, args);
117 collectproto->filter (args["c"], request, queryresponse, err, logout);
118 if (err != noError) {
119 outconvertclass text_t2ascii;
120 logout << text_t2ascii
121 << "documentaction::output_document: call to QueryFilter failed "
122 << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
123 highlight = false;
124 } else {
125 highlight = true;
126 }
127 }
128 }
129
130
131 format_t *formatlistptr = new format_t();
132 parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
133
134 metadata.insert ("hastxt");
135 metadata.insert ("haschildren");
136
137 if (formatinfo.DocumentText == "[Text]")
138 wanttext = 1;
139 else {
140 char *docformat = formatinfo.DocumentText.getcstr();
141 if (strstr (docformat, "[Text]") != NULL)
142 wanttext = 2;
143 delete docformat;
144 }
145
146 if (get_info (OID, collection, metadata, getParents, collectproto, inforesponse, logout)) {
147 int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
148 int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
149
150 if (arg_gt == 0) {
151 output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo,
152 OID, highlight, hastxt, wanttext, collection, collectproto,
153 disp, outconvert, textout, logout);
154
155
156 } else {
157
158 ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
159
160 // text is to be expanded
161 text_t exOID = OID;
162 if (haschildren != 1) exOID = get_parent (OID);
163 if (exOID.empty()) exOID = OID;
164
165 // if we're not in a document (i.e. we're in a top level classification)
166 // we need to pass "is_classify = true" to get_contents so that it
167 // doesn't recurse all the way through each document in the classification
168 bool is_classify = false;
169 if (args["d"].empty()) is_classify = true;
170
171 get_contents (exOID, is_classify, metadata, collection,
172 collectproto, inforesponse, logout);
173
174 ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
175 ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
176
177 if (arg_gt == 1) {
178 // check if there are more than 10 sections containing text to be expanded -
179 // if there are output warning message - this isn't a great way to do this
180 // since the sections may be very large or very small - one day I'll fix it
181 // -- Stefan.
182 int seccount = 0;
183 while (sechere != secend) {
184 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
185 if (shastxt == 1) seccount ++;
186 if (seccount > 10) break;
187 sechere ++;
188 }
189 if (seccount > 10) {
190 // more than 10 sections so output warning message and text
191 // for current section only
192 textout << outconvert << disp << "_document:textltwarning_";
193
194 output_text (thisdocinfo, formatlistptr, queryresponse.termInfo,
195 OID, highlight, hastxt, wanttext, collection,
196 collectproto, disp, outconvert, textout, logout);
197
198 }
199 else arg_gt = 2;
200 }
201
202 if (arg_gt == 2) {
203 // get the text for each section
204 sechere = inforesponse.docInfo.begin();
205 int count = 0;
206 while (sechere != secend) {
207 textout << outconvert << disp << "\n<p><a name=" << (*sechere).OID << "></a>\n";
208
209 int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
210
211 output_text (*sechere, formatlistptr, queryresponse.termInfo,
212 (*sechere).OID, highlight, shastxt, wanttext, collection,
213 collectproto, disp, outconvert, textout, logout);
214 count ++;
215 sechere ++;
216 }
217 }
218 }
219 }
220 delete formatlistptr;
221}
Note: See TracBrowser for help on using the repository browser.