/********************************************************************** * * dynamicclassifieraction.cpp -- * Copyright (C) 2008 DL Consulting Ltd * * 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. * *********************************************************************/ #include "dynamicclassifieraction.h" #include "recptprototools.h" dynamicclassifieraction::dynamicclassifieraction () { recpt = NULL; cgiarginfo arg_ainfo; arg_ainfo.shortname = "dcl"; arg_ainfo.longname = "dynamic classifier ID"; arg_ainfo.multiplechar = true; arg_ainfo.defaultstatus = cgiarginfo::weak; arg_ainfo.argdefault = ""; arg_ainfo.savedarginfo = cgiarginfo::must; argsinfo.addarginfo (NULL, arg_ainfo); } dynamicclassifieraction::~dynamicclassifieraction() { } bool dynamicclassifieraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, recptprotolistclass *protos, ostream &logout) { return true; } void dynamicclassifieraction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos, response_t &response,text_t &response_data, ostream &logout) { response = content; response_data = "text/html"; } // define all the macros which might be used by other actions // to produce pages. void dynamicclassifieraction::define_external_macros (displayclass &disp, cgiargsclass &args, recptprotolistclass *protos, ostream &logout) { // define_external_macros sets the following macros: } // 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 dynamicclassifieraction::define_internal_macros (displayclass &disp, cgiargsclass &args, recptprotolistclass *protos, ostream &logout) { // define_internal_macros sets the following macros: } bool dynamicclassifieraction::do_action(cgiargsclass &args, recptprotolistclass *protos, browsermapclass *browsers, displayclass &disp, outconvertclass &outconvert, ostream &textout, ostream &logout) { // A valid collection server is vital recptproto *collectproto = protos->getrecptproto (args["c"], logout); if (collectproto == NULL) { logout << "dynamicclassifieraction::do_action called with NULL collectproto\n"; return false; } textout << outconvert << disp << "_document:header_\n"; textout << outconvert << disp << "_document:content_\n"; // Check a dynamic classifier ID has been specified text_t arg_dcl = args["dcl"]; if (arg_dcl.empty()) { textout << outconvert << disp << "Error: Missing \"dcl\" value.\n"; textout << outconvert << disp << "_document:footer_\n"; return true; } // Check the dynamic classifier ID is valid (ie. there is an entry in the collect.cfg file for it) ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout); if (cinfo->dynamic_classifiers.find(arg_dcl) == cinfo->dynamic_classifiers.end()) { textout << outconvert << disp << "Error: Invalid \"dcl\" value " << arg_dcl << ".\n"; textout << outconvert << disp << "_document:footer_\n"; return true; } text_t classifier_type = "VList"; browserclass *bptr = browsers->getbrowser (classifier_type); // Get the formatstring if there is one, or use the browser's default otherwise text_t formatstring; if (!get_formatstring (arg_dcl, classifier_type, cinfo->format, formatstring)) { formatstring = bptr->get_default_formatstring(); } format_t *formatlistptr = new format_t(); text_tset metadata; bool getParents = false; parse_formatstring (formatstring, formatlistptr, metadata, getParents); text_t metadata_element_name = cinfo->dynamic_classifiers[arg_dcl]; FilterResponse_t metadata_values_response; get_metadata_values (metadata_element_name, args["c"], collectproto, metadata_values_response, logout); ResultDocInfo_tarray::iterator metadata_value_iterator = metadata_values_response.docInfo.begin(); while (metadata_value_iterator != metadata_values_response.docInfo.end()) { (*metadata_value_iterator).metadata["doctype"].values.push_back("classify"); (*metadata_value_iterator).metadata["haschildren"].values.push_back("1"); (*metadata_value_iterator).metadata["numleafdocs"].values.push_back((*metadata_value_iterator).result_num); (*metadata_value_iterator).metadata["Title"].values.push_back((*metadata_value_iterator).OID); metadata_value_iterator++; } // Display the nodes bool use_table = is_table_content (formatlistptr); bptr->output_section_group (metadata_values_response, args, args["c"], 0, formatlistptr, use_table, metadata, getParents, collectproto, disp, outconvert, textout, logout); textout << outconvert << disp << "_document:footer_\n"; return true; }