/**********************************************************************
*
* pageaction.cpp --
* Copyright (C) 1999 The New Zealand Digital Library Project
*
* PUT COPYRIGHT NOTICE HERE
*
* $Id: pageaction.cpp 172 1999-02-25 21:59:02Z rjmcnab $
*
*********************************************************************/
/*
$Log$
Revision 1.3 1999/02/25 21:58:58 rjmcnab
Merged sources.
Revision 1.2 1999/02/21 22:33:54 rjmcnab
Lots of stuff :-)
Revision 1.1 1999/02/12 02:40:17 sjboddie
Added page action
*/
#include "pageaction.h"
#include "receptionist.h"
pageaction::pageaction () {
// this action uses cgi variables "a" and "p"
cgiarginfo arg_ainfo;
arg_ainfo.shortname = "a";
arg_ainfo.longname = "action";
arg_ainfo.multiplechar = true;
arg_ainfo.defaultstatus = cgiarginfo::weak;
arg_ainfo.argdefault = "p";
arg_ainfo.savedarginfo = cgiarginfo::must;
argsinfo.addarginfo (NULL, arg_ainfo);
arg_ainfo.shortname = "p";
arg_ainfo.longname = "page";
arg_ainfo.multiplechar = true;
arg_ainfo.defaultstatus = cgiarginfo::weak;
arg_ainfo.argdefault = "about";
arg_ainfo.savedarginfo = cgiarginfo::can;
argsinfo.addarginfo (NULL, arg_ainfo);
}
pageaction::~pageaction () {
}
bool pageaction::check_cgiargs (cgiargsclass &/*args*/, ostream &/*logout*/) {
// don't want to check anything yet.
return true;
}
void pageaction::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
text_t &response_data, ostream &/*logout*/) {
response = content;
response_data = "text/html";
}
bool pageaction::do_action (cgiargsclass &args, recptproto */*collectproto*/,
displayclass &disp, outconvertclass &outconvert,
ostream &textout, ostream &logout) {
text_t pageparams;
text_t &arg_p = args["p"];
bool first = true;
if (!args["c"].empty()) {
pageparams += "collection=" + args["c"]; first = false;}
if (args.getintarg("u") == 1)
if (first) {pageparams += "style=htmlonly"; first = false;}
else pageparams += ",style=htmlonly";
if (args.getintarg("v") == 1)
if (first) {pageparams += "version=text"; first = false;}
else pageparams += ",version=text";
if (args.getintarg("f") == 1)
if (first) {pageparams += ",queryversion=big"; first = false;}
else pageparams += ",queryversion=big";
if (args["l"] != "en")
if (first) pageparams += ",language=" + args["l"];
else pageparams += ",language=" + args["l"];
disp.openpage(pageparams, MACROPRECEDENCE);
define_internal_macros (disp, args, logout);
textout << outconvert << disp << ("_" + arg_p + ":header_\n")
<< ("_" + arg_p + ":imagestandardbar_\n") << ("_" + arg_p + ":content_\n")
<< ("_" + arg_p + ":footer_\n");
return true;
}
// define all the macros which are related to pages generated
// by this action
void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args,
ostream &logout) {
// not sure which macros should be defined where - what is difference between
// define_internal_macros and define_external_macros
// urlsafequerystring and querystring macros need some kind of cgisafe and
// htmlsafe functions (maybe to be defined in htmlutils.cpp?)
// the following macros are also defined in libinterface, some of them I'm not
// sure how to define from here and some I don't think are required anymore
// httpprefix
// numdocs
// collection
// istitle and pagedest -- these don't occur anywhere in the macro files
// I don't know what structure has replaced what used to be cfg_info
// so haven't defined the selection macros _hselection_, _jselection_
// and _nselection_ (these should be set in define_query_macros)
// _imagethispage_ needs to be set for any browse pages but I guess
// browse pages will be generated by a different action
// not sure what to do with any collection specific macros - these
// used to be defined in define_collection_macros although there
// wasn't much collection specific stuff left I don't think
// disp.setmacro ("gwcgi", "Global", recpt->get_gwcgi());
// disp.setmacro ("httpimg", "Global", recpt->get_httpimg());
// disp.setmacro("compressedoptions", "Global", recpt->get_compressed_arg(args));
// disp.setmacro("urlsafequerystring", "Global", cgisafe(outconvert.convert(args["q"])));
// disp.setmacro("querystring", "Global", htmlsafe(outconvert.convert(args["q"]))));
// define the macro for the "g" argument
disp.setmacro("g", "Global", args["g"]);
// this gets set unless page has been detached by the 'detach' button.
if (args.getintarg("x") == 0) disp.setmacro("notdetached", "Global", "1");
// not sure if home and about pages will both need query macros defined
if ((args["p"] == "query") || (args["p"] == "home") || (args["p"] == "about"))
define_query_macros (disp, args, logout);
if (args["p"] == "preferences")
define_pref_macros (disp, args, logout);
}
void pageaction::define_query_macros (displayclass &disp, cgiargsclass &args,
ostream &/*logout*/) {
// some/all query type selection
text_t qtselect = "\n";
disp.setmacro("querytypeselection", "query", qtselect);
}
void pageaction::define_pref_macros (displayclass &disp, cgiargsclass &args,
ostream &/*logout*/) {
// the caseoption macro
text_t caseoption;
int arg_k = args.getintarg("k");
caseoption += "\n_textignorecase_ \n";
caseoption += "_textmatchcase_\n";
disp.setmacro ("caseoption", "preferences", caseoption);
// the stemoption macro
text_t stemoption;
int arg_s = args.getintarg("s");
stemoption += "\n_textstem_ \n";
stemoption += "_textnostem_\n";
disp.setmacro ("stemoption", "preferences", stemoption);
// the encodingoption
text_t encodingoption;
const text_t &arg_w = args["w"];
encodingoption += "\n\n";
disp.setmacro ("encodingoption", "preferences", encodingoption);
// the maxdocoption
text_t maxdocoption;
int arg_m = args.getintarg("m");
maxdocoption += "\n\n";
disp.setmacro ("maxdocoption", "preferences", maxdocoption);
// the hitsperpageoption
text_t hitsoption;
int arg_o = args.getintarg("o");
hitsoption += "\n\n";
disp.setmacro ("hitsperpageoption", "preferences", hitsoption);
}