1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * niupepadocaction.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) 1999 The New Zealand Digital Library Project
|
---|
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: niupepadocaction.cpp 1932 2001-02-08 02:40:23Z None $
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 | /*
|
---|
29 | $Log$
|
---|
30 | Revision 1.3 2000/09/20 05:18:31 nzdl
|
---|
31 | *** empty log message ***
|
---|
32 |
|
---|
33 | Revision 1.2 2000/09/08 03:17:08 nzdl
|
---|
34 | updated niupepa collection
|
---|
35 |
|
---|
36 | Revision 1.1.1.1 2000/03/08 20:44:50 sjboddie
|
---|
37 | added niupepa to CVS
|
---|
38 |
|
---|
39 | Revision 1.2 1999/09/07 22:19:50 sjboddie
|
---|
40 | added GPL header
|
---|
41 |
|
---|
42 | Revision 1.1 1999/08/29 23:35:07 sjboddie
|
---|
43 | niupepa receptionist
|
---|
44 |
|
---|
45 | */
|
---|
46 |
|
---|
47 |
|
---|
48 | #include <string.h>
|
---|
49 | #include "niupepadocaction.h"
|
---|
50 | #include "niupepabrowsetools.h"
|
---|
51 | #include "OIDtools.h"
|
---|
52 | #include "gsdltools.h"
|
---|
53 | #include "querytools.h"
|
---|
54 | #include "unitool.h"
|
---|
55 |
|
---|
56 | niupepadocaction::niupepadocaction () {
|
---|
57 | // this action uses cgi variable "gg" as well as
|
---|
58 | // those used by the standard documentaction
|
---|
59 |
|
---|
60 | cgiarginfo arg_ainfo;
|
---|
61 |
|
---|
62 | // in this action "gg" is the format of the
|
---|
63 | // document to view (i.e. "text", "prev" or "full")
|
---|
64 | arg_ainfo.shortname = "gg";
|
---|
65 | arg_ainfo.longname = "document format";
|
---|
66 | arg_ainfo.multiplechar = true;
|
---|
67 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
68 | arg_ainfo.argdefault = "text";
|
---|
69 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
70 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
71 | }
|
---|
72 |
|
---|
73 | niupepadocaction::~niupepadocaction () {
|
---|
74 | }
|
---|
75 |
|
---|
76 | void niupepadocaction::set_java_macros (cgiargsclass &args, displayclass &disp) {
|
---|
77 |
|
---|
78 | text_t javaimagescontent = "_javaextras__javacommentary__javaviewabstract__javaviewpaper__javaabstractintro_";
|
---|
79 |
|
---|
80 | text_t &arg_gg = args["gg"];
|
---|
81 |
|
---|
82 | if (arg_gg == "full")
|
---|
83 | javaimagescontent += "_javaprevimage__javaviewtext_";
|
---|
84 | else if (arg_gg == "prev")
|
---|
85 | javaimagescontent += "_javafullimage__javaviewtext_";
|
---|
86 | else
|
---|
87 | javaimagescontent += "_javafullimage__javaprevimage_";
|
---|
88 |
|
---|
89 |
|
---|
90 | int arg_gt = args.getintarg("gt");
|
---|
91 | int arg_hl = args.getintarg("hl");
|
---|
92 |
|
---|
93 | text_tarray::const_iterator button_here = formatinfo.DocumentButtons.begin();
|
---|
94 | text_tarray::const_iterator button_end = formatinfo.DocumentButtons.end();
|
---|
95 |
|
---|
96 | while (button_here != button_end) {
|
---|
97 | if (*button_here == "Detach")
|
---|
98 | javaimagescontent += "_javadetach_";
|
---|
99 | else if (*button_here == "Expand Text" && arg_gg == "text") {
|
---|
100 | if (arg_gt == 1)
|
---|
101 | javaimagescontent += "_javacontracttext__javacontinue_";
|
---|
102 | else if (arg_gt == 2)
|
---|
103 | javaimagescontent += "_javacontracttext_";
|
---|
104 | else
|
---|
105 | javaimagescontent += "_javaexpandtext_";
|
---|
106 | } else if (*button_here == "Highlight" && arg_gg == "text") {
|
---|
107 | if (arg_hl == 1)
|
---|
108 | javaimagescontent += "_javanohighlighting_";
|
---|
109 | else
|
---|
110 | javaimagescontent += "_javahighlighting_";
|
---|
111 | }
|
---|
112 | button_here ++;
|
---|
113 | }
|
---|
114 | disp.setmacro ("javaimagescontent", "document", javaimagescontent);
|
---|
115 | }
|
---|
116 |
|
---|
117 | // define all the macros which are related to pages generated
|
---|
118 | // by this action. we also load up the formatinfo structure
|
---|
119 | // here (it's used in do_action as well as here)
|
---|
120 | void niupepadocaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
121 | recptprotolistclass *protos, ostream &logout) {
|
---|
122 |
|
---|
123 |
|
---|
124 | // define_internal_macros sets the following macros (as well as those defined
|
---|
125 | // by documentaction::define_internal_macros)
|
---|
126 |
|
---|
127 | // _httpthiscommentary_ the link to the papers commentary
|
---|
128 |
|
---|
129 | // _httpiconthispaper_ the http address of the cover image
|
---|
130 |
|
---|
131 | // _headerextra_ set to _abstract_ if current document is an abstract
|
---|
132 |
|
---|
133 | // _toplink_ _endtoplink_ link to the first page of the current document
|
---|
134 |
|
---|
135 | documentaction::define_internal_macros (disp, args, protos, logout);
|
---|
136 |
|
---|
137 | text_t &arg_d = args["d"];
|
---|
138 | text_t &collection = args["c"];
|
---|
139 | text_tset metadata;
|
---|
140 | FilterResponse_t response;
|
---|
141 | text_t toplink, endtoplink;
|
---|
142 |
|
---|
143 | recptproto *collectproto = protos->getrecptproto (collection, logout);
|
---|
144 | if (collectproto == NULL) return;
|
---|
145 |
|
---|
146 | if (!arg_d.empty()) {
|
---|
147 | // we're at document level
|
---|
148 |
|
---|
149 | text_t series = substr (arg_d.begin(), findchar (arg_d.begin(), arg_d.end(), '_'));
|
---|
150 | if ((series.size() > 10) && (substr ((series.end()-10), series.end()) == "commentary")) {
|
---|
151 | series = substr (series.begin(), (series.end()-10));
|
---|
152 | } else {
|
---|
153 | text_t commentaryOID = series + "commentary";
|
---|
154 |
|
---|
155 | // set _httpthiscommentary_ if commentary exists
|
---|
156 | if (get_info (commentaryOID, collection, metadata, false, collectproto, response, logout))
|
---|
157 | disp.setmacro ("httpthiscommentary", "document", "_httpdocument_&gg=text&d=" + commentaryOID);
|
---|
158 | }
|
---|
159 | // _httpiconthispaper_
|
---|
160 | disp.setmacro ("httpiconthispaper", "document", "_httpcollimg_/" + series + "/cover");
|
---|
161 |
|
---|
162 | // _headerextra_, _toplink_, _endtoplink_
|
---|
163 | metadata.insert ("doctype");
|
---|
164 | text_t headerextra;
|
---|
165 | if (get_info (arg_d, collection, metadata, false, collectproto, response, logout)) {
|
---|
166 | if (response.docInfo[0].metadata["doctype"].values[0] == "Description") {
|
---|
167 | headerextra = "_abstract_";
|
---|
168 | toplink = substr (arg_d.begin(), arg_d.end()-8);
|
---|
169 | toplink = "<a href=\"_httpdocument_&gg=prev&cl=_cgiargcl_&d=" + dm_safe (toplink) + "\">";
|
---|
170 | endtoplink = "</a>";
|
---|
171 | } else if (response.docInfo[0].metadata["doctype"].values[0] != "Commentary") {
|
---|
172 | get_top (arg_d, toplink);
|
---|
173 | toplink = "<a href=\"_httpdocument_&gg=prev&cl=_cgiargcl_&d=" + dm_safe (toplink) + "\">";
|
---|
174 | endtoplink = "</a>";
|
---|
175 | }
|
---|
176 | }
|
---|
177 | disp.setmacro ("headerextra", "Global", headerextra);
|
---|
178 | disp.setmacro ("toplink", "Global", toplink);
|
---|
179 | disp.setmacro ("endtoplink", "Global", endtoplink);
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | void niupepadocaction::output_document (const text_t &OID, cgiargsclass &args,
|
---|
184 | recptproto *collectproto, displayclass &disp,
|
---|
185 | outconvertclass &outconvert, ostream &textout,
|
---|
186 | ostream &logout) {
|
---|
187 | FilterResponse_t response;
|
---|
188 | text_tset metadata;
|
---|
189 | text_t &arg_gg = args["gg"];
|
---|
190 | text_t &collection = args["c"];
|
---|
191 |
|
---|
192 | if (arg_gg == "full") {
|
---|
193 |
|
---|
194 | // fullsize image
|
---|
195 |
|
---|
196 | metadata.insert ("hasimg");
|
---|
197 | metadata.insert ("Source");
|
---|
198 | if (!get_info (OID, collection, metadata, false, collectproto, response, logout))
|
---|
199 | return;
|
---|
200 | if (response.docInfo[0].metadata["hasimg"].values[0] == "1") {
|
---|
201 | textout << outconvert << disp
|
---|
202 | << "<p><img src=\"_httpcollimg_/_thisOID_/"
|
---|
203 | << response.docInfo[0].metadata["Source"].values[0] << ".gif\">\n";
|
---|
204 | } else {
|
---|
205 | textout << outconvert << disp << "_missingimage_\n";
|
---|
206 | }
|
---|
207 |
|
---|
208 | } else if (arg_gg == "prev") {
|
---|
209 |
|
---|
210 | // preview image
|
---|
211 |
|
---|
212 | metadata.insert ("hasprevimg");
|
---|
213 | metadata.insert ("Source");
|
---|
214 | if (!get_info (OID, collection, metadata, false, collectproto, response, logout))
|
---|
215 | return;
|
---|
216 | if (response.docInfo[0].metadata["hasprevimg"].values[0] == "1") {
|
---|
217 | textout << outconvert << disp
|
---|
218 | << "<center>\n"
|
---|
219 | << "<p><img src=\"_httpcollimg_/_thisOID_/"
|
---|
220 | << response.docInfo[0].metadata["Source"].values[0] << "_p.gif\">\n"
|
---|
221 | << "</center>\n";
|
---|
222 | } else {
|
---|
223 | textout << outconvert << disp << "_missingimage_\n";
|
---|
224 | }
|
---|
225 | } else {
|
---|
226 |
|
---|
227 | // text
|
---|
228 | metadata.insert ("hastxt");
|
---|
229 | if (!get_info (OID, collection, metadata, false, collectproto, response, logout))
|
---|
230 | return;
|
---|
231 | if (response.docInfo[0].metadata["hastxt"].values[0] == "1") {
|
---|
232 | documentaction::output_document (OID, args, collectproto, disp,
|
---|
233 | outconvert, textout, logout);
|
---|
234 | } else {
|
---|
235 | textout << outconvert << disp << "_missingtext_\n";
|
---|
236 | }
|
---|
237 | }
|
---|
238 | }
|
---|
239 |
|
---|
240 |
|
---|
241 | // this is only overridden so we can call output_niupepa_toc instead
|
---|
242 | // of output_toc -- we should find a tidier way to do this both here
|
---|
243 | // and in the cstr collection
|
---|
244 | bool niupepadocaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
|
---|
245 | browsermapclass *browsers, displayclass &disp,
|
---|
246 | outconvertclass &outconvert, ostream &textout,
|
---|
247 | ostream &logout) {
|
---|
248 |
|
---|
249 |
|
---|
250 | // must have a valid collection server
|
---|
251 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
252 | if (collectproto == NULL) {
|
---|
253 | logout << "documentaction::do_action called with NULL collectproto\n";
|
---|
254 | textout << outconvert << disp << "_document:header_\n"
|
---|
255 | << "Error: Attempt to get document without setting collection\n"
|
---|
256 | << "_document:footer_\n";
|
---|
257 | } else {
|
---|
258 |
|
---|
259 | text_t OID = args["d"];
|
---|
260 | if (OID.empty()) OID = args["cl"];
|
---|
261 | if (OID.empty()) {
|
---|
262 | textout << outconvert << disp << "Document contains no data_document:footer_\n";
|
---|
263 | return true;
|
---|
264 | }
|
---|
265 |
|
---|
266 | if (formatinfo.DocumentUseHTML) {
|
---|
267 |
|
---|
268 | if (!args["d"].empty()) {
|
---|
269 | if (args["f"] == "1") {
|
---|
270 | textout << outconvert << disp
|
---|
271 | << "<html><head></head>\n"
|
---|
272 | << "<frameset rows=\"68,*\" noresize border=0>\n"
|
---|
273 | << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?e=_compressedoptions_&a=p&p=nav\">\n"
|
---|
274 | << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?e=_compressedoptions_&a=d&d="
|
---|
275 | << args["d"] << "\">"
|
---|
276 | << "<noframes>\n"
|
---|
277 | << "<p>You must have a frame enabled browser to view this.</p>\n"
|
---|
278 | << "</noframes>\n"
|
---|
279 | << "</frameset>\n"
|
---|
280 | << "</html>\n";
|
---|
281 | } else {
|
---|
282 | output_document (OID, args, collectproto, disp, outconvert, textout, logout);
|
---|
283 | }
|
---|
284 | return true;
|
---|
285 | }
|
---|
286 | }
|
---|
287 |
|
---|
288 | textout << outconvert << disp << "_document:header_\n"
|
---|
289 | << "_document:content_\n";
|
---|
290 |
|
---|
291 | // output the table of contents
|
---|
292 | output_niupepa_toc (args, browsers, formatinfo, collectproto,
|
---|
293 | disp, outconvert, textout, logout);
|
---|
294 |
|
---|
295 | // output the document text
|
---|
296 | if (!args["d"].empty()) {
|
---|
297 | textout << "<p>\n";
|
---|
298 | output_document (OID, args, collectproto, disp, outconvert, textout, logout);
|
---|
299 | }
|
---|
300 |
|
---|
301 | textout << outconvert << disp << "_document:footer_\n";
|
---|
302 | }
|
---|
303 | return true;
|
---|
304 | }
|
---|