/********************************************************************** * * niupepadocaction.cpp -- * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Copyright (C) 1999 The New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: niupepadocaction.cpp 1556 2000-09-20 05:18:31Z nzdl $ * *********************************************************************/ /* $Log$ Revision 1.3 2000/09/20 05:18:31 nzdl *** empty log message *** Revision 1.2 2000/09/08 03:17:08 nzdl updated niupepa collection Revision 1.1.1.1 2000/03/08 20:44:50 sjboddie added niupepa to CVS Revision 1.2 1999/09/07 22:19:50 sjboddie added GPL header Revision 1.1 1999/08/29 23:35:07 sjboddie niupepa receptionist */ #include #include "niupepadocaction.h" #include "niupepabrowsetools.h" #include "OIDtools.h" #include "gsdltools.h" #include "querytools.h" #include "unitool.h" niupepadocaction::niupepadocaction () { // this action uses cgi variable "gg" as well as // those used by the standard documentaction cgiarginfo arg_ainfo; // in this action "gg" is the format of the // document to view (i.e. "text", "prev" or "full") arg_ainfo.shortname = "gg"; arg_ainfo.longname = "document format"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = "text"; arg_ainfo.savedarginfo = cgiarginfo::must; argsinfo.addarginfo (NULL, arg_ainfo); } niupepadocaction::~niupepadocaction () { } void niupepadocaction::set_java_macros (cgiargsclass &args, displayclass &disp) { text_t javaimagescontent = "_javaextras__javacommentary__javaviewabstract__javaviewpaper__javaabstractintro_"; text_t &arg_gg = args["gg"]; if (arg_gg == "full") javaimagescontent += "_javaprevimage__javaviewtext_"; else if (arg_gg == "prev") javaimagescontent += "_javafullimage__javaviewtext_"; else javaimagescontent += "_javafullimage__javaprevimage_"; int arg_gt = args.getintarg("gt"); int arg_hl = args.getintarg("hl"); text_tarray::const_iterator button_here = formatinfo.DocumentButtons.begin(); text_tarray::const_iterator button_end = formatinfo.DocumentButtons.end(); while (button_here != button_end) { if (*button_here == "Detach") javaimagescontent += "_javadetach_"; else if (*button_here == "Expand Text" && arg_gg == "text") { if (arg_gt == 1) javaimagescontent += "_javacontracttext__javacontinue_"; else if (arg_gt == 2) javaimagescontent += "_javacontracttext_"; else javaimagescontent += "_javaexpandtext_"; } else if (*button_here == "Highlight" && arg_gg == "text") { if (arg_hl == 1) javaimagescontent += "_javanohighlighting_"; else javaimagescontent += "_javahighlighting_"; } button_here ++; } disp.setmacro ("javaimagescontent", "document", javaimagescontent); } // define all the macros which are related to pages generated // by this action. we also load up the formatinfo structure // here (it's used in do_action as well as here) void niupepadocaction::define_internal_macros (displayclass &disp, cgiargsclass &args, recptprotolistclass *protos, ostream &logout) { // define_internal_macros sets the following macros (as well as those defined // by documentaction::define_internal_macros) // _httpthiscommentary_ the link to the papers commentary // _httpiconthispaper_ the http address of the cover image // _headerextra_ set to _abstract_ if current document is an abstract // _toplink_ _endtoplink_ link to the first page of the current document documentaction::define_internal_macros (disp, args, protos, logout); text_t &arg_d = args["d"]; text_t &collection = args["c"]; text_tset metadata; FilterResponse_t response; text_t toplink, endtoplink; recptproto *collectproto = protos->getrecptproto (collection, logout); if (collectproto == NULL) return; if (!arg_d.empty()) { // we're at document level text_t series = substr (arg_d.begin(), findchar (arg_d.begin(), arg_d.end(), '_')); if ((series.size() > 10) && (substr ((series.end()-10), series.end()) == "commentary")) { series = substr (series.begin(), (series.end()-10)); } else { text_t commentaryOID = series + "commentary"; // set _httpthiscommentary_ if commentary exists if (get_info (commentaryOID, collection, metadata, false, collectproto, response, logout)) disp.setmacro ("httpthiscommentary", "document", "_httpdocument_&gg=text&d=" + commentaryOID); } // _httpiconthispaper_ disp.setmacro ("httpiconthispaper", "document", "_httpcollimg_/" + series + "/cover"); // _headerextra_, _toplink_, _endtoplink_ metadata.insert ("doctype"); text_t headerextra; if (get_info (arg_d, collection, metadata, false, collectproto, response, logout)) { if (response.docInfo[0].metadata["doctype"].values[0] == "Description") { headerextra = "_abstract_"; toplink = substr (arg_d.begin(), arg_d.end()-8); toplink = ""; endtoplink = ""; } else if (response.docInfo[0].metadata["doctype"].values[0] != "Commentary") { get_top (arg_d, toplink); toplink = ""; endtoplink = ""; } } disp.setmacro ("headerextra", "Global", headerextra); disp.setmacro ("toplink", "Global", toplink); disp.setmacro ("endtoplink", "Global", endtoplink); } } void niupepadocaction::output_document (const text_t &OID, cgiargsclass &args, recptproto *collectproto, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { FilterResponse_t response; text_tset metadata; text_t &arg_gg = args["gg"]; text_t &collection = args["c"]; if (arg_gg == "full") { // fullsize image metadata.insert ("hasimg"); metadata.insert ("Source"); if (!get_info (OID, collection, metadata, false, collectproto, response, logout)) return; if (response.docInfo[0].metadata["hasimg"].values[0] == "1") { textout << outconvert << disp << "

\n"; } else { textout << outconvert << disp << "_missingimage_\n"; } } else if (arg_gg == "prev") { // preview image metadata.insert ("hasprevimg"); metadata.insert ("Source"); if (!get_info (OID, collection, metadata, false, collectproto, response, logout)) return; if (response.docInfo[0].metadata["hasprevimg"].values[0] == "1") { textout << outconvert << disp << "

\n" << "

\n" << "

\n"; } else { textout << outconvert << disp << "_missingimage_\n"; } } else { // text metadata.insert ("hastxt"); if (!get_info (OID, collection, metadata, false, collectproto, response, logout)) return; if (response.docInfo[0].metadata["hastxt"].values[0] == "1") { documentaction::output_document (OID, args, collectproto, disp, outconvert, textout, logout); } else { textout << outconvert << disp << "_missingtext_\n"; } } } // this is only overridden so we can call output_niupepa_toc instead // of output_toc -- we should find a tidier way to do this both here // and in the cstr collection bool niupepadocaction::do_action (cgiargsclass &args, recptprotolistclass *protos, browsermapclass *browsers, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { // must have a valid collection server recptproto *collectproto = protos->getrecptproto (args["c"], logout); if (collectproto == NULL) { logout << "documentaction::do_action called with NULL collectproto\n"; textout << outconvert << disp << "_document:header_\n" << "Error: Attempt to get document without setting collection\n" << "_document:footer_\n"; } else { text_t OID = args["d"]; if (OID.empty()) OID = args["cl"]; if (OID.empty()) { textout << outconvert << disp << "Document contains no data_document:footer_\n"; return true; } if (formatinfo.DocumentUseHTML) { if (!args["d"].empty()) { if (args["f"] == "1") { textout << outconvert << disp << "\n" << "\n" << "\n" << "" << "\n" << "<p>You must have a frame enabled browser to view this.</p>\n" << "\n" << "\n" << "\n"; } else { output_document (OID, args, collectproto, disp, outconvert, textout, logout); } return true; } } textout << outconvert << disp << "_document:header_\n" << "_document:content_\n"; // output the table of contents output_niupepa_toc (args, browsers, formatinfo, collectproto, disp, outconvert, textout, logout); // output the document text if (!args["d"].empty()) { textout << "

\n"; output_document (OID, args, collectproto, disp, outconvert, textout, logout); } textout << outconvert << disp << "_document:footer_\n"; } return true; }