/********************************************************************** * * cstrdocaction.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * 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: cstrdocaction.cpp 911 2000-02-06 21:27:04Z sjboddie $ * *********************************************************************/ /* $Log$ Revision 1.2 2000/02/06 21:25:21 sjboddie updated cstr Revision 1.1 1999/09/07 21:49:42 sjboddie new cstr receptionist */ #include #include "cstrdocaction.h" #include "cstrbrowsetools.h" #include "browsetools.h" #include "OIDtools.h" #include "querytools.h" #include "unitool.h" cstrdocaction::cstrdocaction () { // this action uses cgi variable "gg" and "gga" 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", "postscript", "abstract", "figures", or "facsimiles") 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::can; argsinfo.addarginfo (NULL, arg_ainfo); // in this action "gga" is the path to the postscript // when "gg" == "postscript arg_ainfo.shortname = "gga"; arg_ainfo.longname = "postscript path"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::none; arg_ainfo.argdefault = ""; arg_ainfo.savedarginfo = cgiarginfo::mustnot; argsinfo.addarginfo (NULL, arg_ainfo); } cstrdocaction::~cstrdocaction () { } void cstrdocaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass * /*protos*/, response_t &response,text_t &response_data, ostream &/*logout*/) { if (args["gg"] == "postscript") { response = location; response_data = args["gga"]; } else { response = content; response_data = "text/html"; } } void cstrdocaction::set_java_macros (cgiargsclass &args, displayclass &disp) { text_t javaimagescontent = "\n_javaextras__javapostscript_"; text_t &arg_gg = args["gg"]; if (arg_gg == "text") javaimagescontent += "_javaabstract__javafigures_"; else if (arg_gg == "abstract") javaimagescontent += "_javafigures__javaviewtext_"; else if (arg_gg == "figures") javaimagescontent += "_javaabstract__javaviewtext_"; else if (arg_gg == "facsimiles") javaimagescontent += "_javaabstract__javaviewtext__javafigures_"; int arg_gt = args.getintarg("gt"); // int arg_gc = args.getintarg("gc"); 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 == "Expand Contents") { // if (arg_gc == 1) // javaimagescontent += "_javacontractcontents_"; // else // javaimagescontent += "_javaexpandcontents_"; } else if (*button_here == "Highlight" && arg_gg == "text") { if (arg_hl == 1) javaimagescontent += "_javanohighlighting_"; else javaimagescontent += "_javahighlighting_"; } button_here ++; } javaimagescontent += "\n"; 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 cstrdocaction::define_internal_macros (const ColInfoResponse_t &collectinfo, displayclass &disp, cgiargsclass &args, recptproto *collectproto, ostream &logout) { // define_internal_macros sets the following macros: // _pagetitle_ the title to be displayed at the top of the browser window // _imagethispage_ the title image to be displayed at top right of page // _classificationlinks_ the links between classifications to be displayed // at top of list or datelist classifications // _httpprevarrow_ these are set if next or previous arrows // _httpnextarrow_ are to be used - (i.e. if it's an AZList or a DateList // classifytype at a top level or if it's a Book or a // Hierarchy classifytype at document level // _navarrows_ this may be overridden to "" when format option // DocumentArrowsBottom is false // _header_ the header macro is overridden if we're not at a top level // classification to remove the title block // _javaimagescontent_ this is the javascript code to shove in to make the // flashy buttons work // _thisOID_ the OID (directory) of the current document - this corresponds // to the archivedir metadata element // can't do anything if collectproto is null (i.e. no collection was specified) if (collectproto == NULL) return; text_tarray metadata; FilterResponse_t response; text_t &arg_d = args["d"]; text_t &arg_cl = args["cl"]; text_t &collection = args["c"]; int gt = args.getintarg("gt"); load_formatinfo (collectinfo.format, gt); // don't want arrows or goto if we're in figures or facsimiles if (args["gg"] != "text") { formatinfo.DocumentArrowsBottom = false; formatinfo.DocumentArrowsTop = false; formatinfo.DocumentGoTo = false; } if (!formatinfo.DocumentArrowsBottom) disp.setmacro("navarrows", "document", ""); metadata.push_back ("Title"); metadata.push_back ("classifytype"); metadata.push_back ("archivedir"); if (!arg_d.empty()) { // we're at document level // get metadata for this document and it's parents if (get_info (arg_d, collection, metadata, true, collectproto, response, logout)) { disp.setmacro ("header", "document", "_textheader_"); disp.setmacro ("thisOID", "Global", response.docInfo[0].metadata["archivedir"].values[0]); text_t &classifytype = response.docInfo[0].metadata["classifytype"].values[0]; if (classifytype.empty()) classifytype = "Book"; // defaults to Book // set arrow macros if required if (((classifytype == "Book") && (formatinfo.DocumentArrowsTop || formatinfo.DocumentArrowsBottom)) || ((classifytype == "Hierarchy") && formatinfo.DocumentArrowsBottom)) set_arrow_macros (arg_d, classifytype, formatinfo.DocumentTopPages, disp, collectproto, collection, logout); if (args["u"] != "1") set_java_macros (args, disp); } } else { if (!arg_cl.empty()) { // get metadata for top level classification text_t classtop; get_top (arg_cl, classtop); if (get_info (classtop, collection, metadata, false, collectproto, response, logout)) { text_t &title = response.docInfo[0].metadata["Title"].values[0]; text_t &classifytype = response.docInfo[0].metadata["classifytype"].values[0]; disp.setmacro ("pagetitle", "document", "_text" + title + "page_"); disp.setmacro ("imagethispage", "document", "_icon" + title + "page_"); // now get the metadata for each child of top level // so we can generate the _classificationlinks_ and arrow macros // (if they're required by the current classification type) if ((classifytype == "AZList") || (classifytype == "DateList")) get_classificationlinks (arg_cl, collection, collectproto, disp, logout); } } } } */ void cstrdocaction::output_document (const text_t &OID, cgiargsclass &args, recptproto *collectproto, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { FilterResponse_t inforesponse; text_tset metadata; bool getParents = false; text_t &collection = args["c"]; text_t &arg_gg = args["gg"]; if (arg_gg == "abstract") { metadata.insert ("Description"); text_t top; get_top (OID, top); if (get_info (top, collection, metadata, getParents, collectproto, inforesponse, logout)) { text_t &description = inforesponse.docInfo[0].metadata["Description"].values[0]; if (!description.empty()) textout << outconvert << disp << "

\n" << description << "\n"; else textout << outconvert << disp << "_textnoabstract_"; } } else if (arg_gg == "figures") { metadata.insert ("figures"); text_t top; get_top (OID, top); if (get_info (top, collection, metadata, false, collectproto, inforesponse, logout)) { text_t &figures = inforesponse.docInfo[0].metadata["figures"].values[0]; if (!figures.empty()) { text_tarray figure_array; splitchar (figures.begin(), figures.end(), ',', figure_array); text_tarray::const_iterator this_figure = figure_array.begin(); text_tarray::const_iterator end_figure = figure_array.end(); while (this_figure != end_figure) { textout << outconvert << disp << "

\n"; this_figure ++; } } else { textout << outconvert << disp << "_textnofigures_"; } } } else if (arg_gg == "facsimiles") { metadata.insert ("facsimiles"); text_t top; get_top (OID, top); if (get_info (top, collection, metadata, false, collectproto, inforesponse, logout)) { text_t &facsimiles = inforesponse.docInfo[0].metadata["facsimiles"].values[0]; if (!facsimiles.empty()) { text_tarray facs_array; splitchar (facsimiles.begin(), facsimiles.end(), ',', facs_array); text_tarray::const_iterator this_facs = facs_array.begin(); text_tarray::const_iterator end_facs = facs_array.end(); while (this_facs != end_facs) { textout << outconvert << disp << "

\n"; this_facs ++; } } else { textout << outconvert << disp << "_textnofacsimiles_"; } } } else { FilterResponse_t queryresponse; bool highlight = false; int wanttext = 0; int arg_gt = args.getintarg("gt"); // if we have a query string and highlighting is turned on we need // to redo the query to get the terms for highlighting if (!args["q"].empty() && args.getintarg("hl")) { FilterRequest_t request; request.filterResultOptions = FRmatchTerms; comerror_t err; text_t formattedstring = args["q"]; format_querystring(formattedstring, args.getintarg("b")); set_queryfilter_options (request, formattedstring, args); collectproto->filter (args["c"], request, queryresponse, err, logout); if (err != noError) { outconvertclass text_t2ascii; logout << text_t2ascii << "documentaction::output_document: call to QueryFilter failed " << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n"; highlight = false; } else { highlight = true; } } format_t *formatlistptr = new format_t(); parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents); metadata.insert ("hastxt"); metadata.insert ("haschildren"); if (formatinfo.DocumentText == "[Text]") wanttext = 1; else { char *docformat = formatinfo.DocumentText.getcstr(); if (strstr (docformat, "[Text]") != NULL) wanttext = 2; delete docformat; } if (get_info (OID, collection, metadata, getParents, collectproto, inforesponse, logout)) { int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint(); int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint(); if (arg_gt == 0) { output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo, OID, highlight, hastxt, wanttext, collection, collectproto, disp, outconvert, textout, logout); } else { ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0]; // text is to be expanded text_t exOID = OID; if (haschildren != 1) exOID = get_parent (OID); if (exOID.empty()) exOID = OID; // if we're not in a document (i.e. we're in a top level classification) // we need to pass the "classify" string to get_contents so that it // doesn't recurse all the way through each document in the classification bool is_classify = false; if (args["d"].empty()) is_classify = true; get_contents (exOID, is_classify, metadata, collection, collectproto, inforesponse, logout); ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin(); ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end(); if (arg_gt == 1) { // check if there are more than 10 sections containing text to be expanded - // if there are output warning message - this isn't a great way to do this // since the sections may be very large or very small - one day I'll fix it // -- Stefan. int seccount = 0; while (sechere != secend) { int shastxt = (*sechere).metadata["hastxt"].values[0].getint(); if (shastxt == 1) seccount ++; if (seccount > 10) break; sechere ++; } if (seccount > 10) { // more than 10 sections so output warning message and text // for current section only textout << outconvert << disp << "_document:textltwarning_"; output_text (thisdocinfo, formatlistptr, queryresponse.termInfo, OID, highlight, hastxt, wanttext, collection, collectproto, disp, outconvert, textout, logout); } else arg_gt = 2; } if (arg_gt == 2) { // get the text for each section sechere = inforesponse.docInfo.begin(); int count = 0; while (sechere != secend) { textout << outconvert << disp << "\n

\n"; int shastxt = (*sechere).metadata["hastxt"].values[0].getint(); output_text (*sechere, formatlistptr, queryresponse.termInfo, (*sechere).OID, highlight, shastxt, wanttext, collection, collectproto, disp, outconvert, textout, logout); count ++; sechere ++; } } } } delete formatlistptr; } } bool cstrdocaction::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 << "cstrdocaction::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; } textout << outconvert << disp << "_document:header_\n" << "_document:content_\n"; if (args["d"].empty()) { output_toc (args, browsers, formatinfo, collectproto, disp, outconvert, textout, logout); } else { output_cstr_toc (args, browsers, formatinfo, collectproto, disp, outconvert, textout, logout); textout << "

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