source: trunk/niupepa/src/recpt/niupepadocaction.cpp@ 1945

Last change on this file since 1945 was 1945, checked in by nzdl, 23 years ago

updated niupepa collection

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