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

Last change on this file since 10590 was 2874, checked in by sjboddie, 23 years ago

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 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
55// define all the macros which are related to pages generated
56// by this action. we also load up the formatinfo structure
57// here (it's used in do_action as well as here)
58void niupepadocaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
59 recptprotolistclass *protos, ostream &logout) {
60
61
62 // define_internal_macros sets the following macros (as well as those defined
63 // by documentaction::define_internal_macros)
64
65 // _httpthiscommentary_ the link to the papers commentary
66
67 // _httpiconthispaper_ the http address of the cover image
68
69 // _headerextra_ set to _abstract_ if current document is an abstract
70
71 // _toplink_ _endtoplink_ link to the first page of the current document
72
73 documentaction::define_internal_macros (disp, args, protos, logout);
74
75 text_t &arg_d = args["d"];
76 text_t &collection = args["c"];
77 text_tset metadata;
78 FilterResponse_t response;
79 text_t toplink, endtoplink;
80
81 recptproto *collectproto = protos->getrecptproto (collection, logout);
82 if (collectproto == NULL) return;
83
84 if (!arg_d.empty()) {
85 // we're at document level
86
87 text_t series = substr (arg_d.begin(), findchar (arg_d.begin(), arg_d.end(), '_'));
88 if ((series.size() > 10) && (substr ((series.end()-10), series.end()) == "commentary")) {
89 series = substr (series.begin(), (series.end()-10));
90 } else {
91 text_t commentaryOID = series + "commentary";
92
93 // set _httpthiscommentary_ if commentary exists
94 if (get_info (commentaryOID, collection, metadata, false, collectproto, response, logout))
95 disp.setmacro ("httpthiscommentary", "document", "_httpdocument_&gg=text&d=" + commentaryOID);
96 }
97 // _httpiconthispaper_
98 disp.setmacro ("httpiconthispaper", "document", "_httpprefix_/collect/niupepa/index/assoc/" + series + "/cover");
99
100 // _headerextra_, _toplink_, _endtoplink_
101 metadata.insert ("doctype");
102 text_t headerextra;
103 if (get_info (arg_d, collection, metadata, false, collectproto, response, logout)) {
104 if (response.docInfo[0].metadata["doctype"].values[0] == "Description") {
105 headerextra = "_abstract_";
106 toplink = substr (arg_d.begin(), arg_d.end()-8);
107 toplink = "<a href=\"_httpdocument_&gg=prev&cl=_cgiargcl_&d=" + dm_safe (toplink) + "\">";
108 endtoplink = "</a>";
109 } else if (response.docInfo[0].metadata["doctype"].values[0] != "Commentary") {
110 get_top (arg_d, toplink);
111 toplink = "<a href=\"_httpdocument_&gg=prev&cl=_cgiargcl_&d=" + dm_safe (toplink) + "\">";
112 endtoplink = "</a>";
113 }
114 }
115 disp.setmacro ("headerextra", "Global", headerextra);
116 disp.setmacro ("toplink", "Global", toplink);
117 disp.setmacro ("endtoplink", "Global", endtoplink);
118 }
119}
120
121void niupepadocaction::output_document (const text_t &OID, cgiargsclass &args,
122 recptproto *collectproto, displayclass &disp,
123 outconvertclass &outconvert, ostream &textout,
124 ostream &logout) {
125 FilterResponse_t response;
126 text_tset metadata;
127 text_t &arg_gg = args["gg"];
128 text_t &collection = args["c"];
129
130 if (arg_gg == "full") {
131
132 // fullsize image
133
134 metadata.insert ("hasimg");
135 metadata.insert ("Source");
136 if (!get_info (OID, collection, metadata, false, collectproto, response, logout))
137 return;
138 if (response.docInfo[0].metadata["hasimg"].values[0] == "1") {
139 textout << outconvert << disp
140 << "<p><img src=\"_httpprefix_/collect/niupepa/index/assoc/_thisOID_/"
141 << response.docInfo[0].metadata["Source"].values[0] << ".gif\">\n";
142 } else {
143 textout << outconvert << disp << "_missingimage_\n";
144 }
145
146 } else if (arg_gg == "prev") {
147
148 // preview image
149
150 metadata.insert ("hasprevimg");
151 metadata.insert ("Source");
152 if (!get_info (OID, collection, metadata, false, collectproto, response, logout))
153 return;
154 if (response.docInfo[0].metadata["hasprevimg"].values[0] == "1") {
155 textout << outconvert << disp
156 << "<center>\n"
157 << "<p><img src=\"_httpprefix_/collect/niupepa/index/assoc/_thisOID_/"
158 << response.docInfo[0].metadata["Source"].values[0] << "_p.gif\">\n"
159 << "</center>\n";
160 } else {
161 textout << outconvert << disp << "_missingimage_\n";
162 }
163 } else {
164
165 // text
166 metadata.insert ("hastxt");
167 if (!get_info (OID, collection, metadata, false, collectproto, response, logout))
168 return;
169 if (response.docInfo[0].metadata["hastxt"].values[0] == "1") {
170 documentaction::output_document (OID, args, collectproto, disp,
171 outconvert, textout, logout);
172 } else {
173 textout << outconvert << disp << "_missingtext_\n";
174 }
175 }
176}
177
178
179// this is only overridden so we can call output_niupepa_toc instead
180// of output_toc -- we should find a tidier way to do this both here
181// and in the cstr collection
182bool niupepadocaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
183 browsermapclass *browsers, displayclass &disp,
184 outconvertclass &outconvert, ostream &textout,
185 ostream &logout) {
186
187
188 // must have a valid collection server
189 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
190 if (collectproto == NULL) {
191 logout << "documentaction::do_action called with NULL collectproto\n";
192 textout << outconvert << disp << "_document:header_\n"
193 << "Error: Attempt to get document without setting collection\n"
194 << "_document:footer_\n";
195 } else {
196
197 text_t OID = args["d"];
198 if (OID.empty()) OID = args["cl"];
199 if (OID.empty()) {
200 textout << outconvert << disp << "Document contains no data_document:footer_\n";
201 return true;
202 }
203
204 if (formatinfo.DocumentUseHTML) {
205
206 if (!args["d"].empty()) {
207 if (args["f"] == "1") {
208 textout << outconvert << disp
209 << "<html><head></head>\n"
210 << "<frameset rows=\"68,*\" noresize border=0>\n"
211 << "<frame scrolling=no frameborder=0 src=\"_gwcgi_?e=_compressedoptions_&a=p&p=nav\">\n"
212 << "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?e=_compressedoptions_&a=d&d="
213 << args["d"] << "\">"
214 << "<noframes>\n"
215 << "<p>You must have a frame enabled browser to view this.</p>\n"
216 << "</noframes>\n"
217 << "</frameset>\n"
218 << "</html>\n";
219 } else {
220 output_document (OID, args, collectproto, disp, outconvert, textout, logout);
221 }
222 return true;
223 }
224 }
225
226 textout << outconvert << disp << "_document:header_\n"
227 << "_document:content_\n";
228
229 // output the table of contents
230 output_niupepa_toc (args, browsers, formatinfo, collectproto,
231 disp, outconvert, textout, logout);
232
233 // output the document text
234 if (!args["d"].empty()) {
235 textout << "<p>\n";
236 output_document (OID, args, collectproto, disp, outconvert, textout, logout);
237 }
238
239 textout << outconvert << disp << "_document:footer_\n";
240 }
241 return true;
242}
Note: See TracBrowser for help on using the repository browser.