source: gsdl/tags/gsdl-2_22-distribution/niupepa/src/recpt/niupepadocaction.cpp@ 14121

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

Initial revision

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