source: gsdl/trunk/src/recpt/dynamicclassifieraction.cpp@ 15795

Last change on this file since 15795 was 15795, checked in by mdewsnip, 16 years ago

(Adding dynamic classifiers) Changing "dcn" argument to "dcl", and added support for specifying format statements in the collect.cfg file for dynamic classifiers.

  • Property svn:executable set to *
File size: 5.5 KB
Line 
1/**********************************************************************
2 *
3 * dynamicclassifieraction.cpp --
4 * Copyright (C) 2008 DL Consulting Ltd
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
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#include "dynamicclassifieraction.h"
27#include "recptprototools.h"
28
29
30dynamicclassifieraction::dynamicclassifieraction ()
31{
32 recpt = NULL;
33
34 cgiarginfo arg_ainfo;
35 arg_ainfo.shortname = "dcl";
36 arg_ainfo.longname = "dynamic classifier ID";
37 arg_ainfo.multiplechar = true;
38 arg_ainfo.defaultstatus = cgiarginfo::weak;
39 arg_ainfo.argdefault = "";
40 arg_ainfo.savedarginfo = cgiarginfo::must;
41 argsinfo.addarginfo (NULL, arg_ainfo);
42}
43
44
45dynamicclassifieraction::~dynamicclassifieraction()
46{
47}
48
49
50bool dynamicclassifieraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
51 recptprotolistclass *protos, ostream &logout)
52{
53 return true;
54}
55
56
57void dynamicclassifieraction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
58 response_t &response,text_t &response_data,
59 ostream &logout)
60{
61 response = content;
62 response_data = "text/html";
63}
64
65
66// define all the macros which might be used by other actions
67// to produce pages.
68void dynamicclassifieraction::define_external_macros (displayclass &disp, cgiargsclass &args,
69 recptprotolistclass *protos, ostream &logout)
70{
71 // define_external_macros sets the following macros:
72}
73
74
75// define all the macros which are related to pages generated
76// by this action. we also load up the formatinfo structure
77// here (it's used in do_action as well as here)
78void dynamicclassifieraction::define_internal_macros (displayclass &disp, cgiargsclass &args,
79 recptprotolistclass *protos, ostream &logout)
80{
81 // define_internal_macros sets the following macros:
82}
83
84
85bool dynamicclassifieraction::do_action(cgiargsclass &args, recptprotolistclass *protos,
86 browsermapclass *browsers, displayclass &disp,
87 outconvertclass &outconvert, ostream &textout,
88 ostream &logout)
89{
90 // A valid collection server is vital
91 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
92 if (collectproto == NULL)
93 {
94 logout << "dynamicclassifieraction::do_action called with NULL collectproto\n";
95 return false;
96 }
97
98 textout << outconvert << disp << "_document:header_\n";
99 textout << outconvert << disp << "_document:content_\n";
100
101 // Check a dynamic classifier ID has been specified
102 text_t arg_dcl = args["dcl"];
103 if (arg_dcl.empty())
104 {
105 textout << outconvert << disp << "Error: Missing \"dcl\" value.\n";
106 textout << outconvert << disp << "_document:footer_\n";
107 return true;
108 }
109
110 // Check the dynamic classifier ID is valid (ie. there is an entry in the collect.cfg file for it)
111 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
112 if (cinfo->dynamic_classifiers.find(arg_dcl) == cinfo->dynamic_classifiers.end())
113 {
114 textout << outconvert << disp << "Error: Invalid \"dcl\" value " << arg_dcl << ".\n";
115 textout << outconvert << disp << "_document:footer_\n";
116 return true;
117 }
118
119 text_t classifier_type = "VList";
120 browserclass *bptr = browsers->getbrowser (classifier_type);
121
122 // Get the formatstring if there is one, or use the browser's default otherwise
123 text_t formatstring;
124 if (!get_formatstring (arg_dcl, classifier_type, cinfo->format, formatstring))
125 {
126 formatstring = bptr->get_default_formatstring();
127 }
128 format_t *formatlistptr = new format_t();
129 text_tset metadata;
130 bool getParents = false;
131 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
132
133 text_t metadata_element_name = cinfo->dynamic_classifiers[arg_dcl];
134 FilterResponse_t metadata_values_response;
135 get_metadata_values (metadata_element_name, args["c"], collectproto, metadata_values_response, logout);
136
137 ResultDocInfo_tarray::iterator metadata_value_iterator = metadata_values_response.docInfo.begin();
138 while (metadata_value_iterator != metadata_values_response.docInfo.end())
139 {
140 (*metadata_value_iterator).metadata["doctype"].values.push_back("classify");
141 (*metadata_value_iterator).metadata["haschildren"].values.push_back("1");
142 (*metadata_value_iterator).metadata["numleafdocs"].values.push_back((*metadata_value_iterator).result_num);
143 (*metadata_value_iterator).metadata["Title"].values.push_back((*metadata_value_iterator).OID);
144 metadata_value_iterator++;
145 }
146
147 // Display the nodes
148 bool use_table = is_table_content (formatlistptr);
149 bptr->output_section_group (metadata_values_response, args, args["c"], 0, formatlistptr, use_table,
150 metadata, getParents, collectproto, disp, outconvert, textout, logout);
151
152 textout << outconvert << disp << "_document:footer_\n";
153 return true;
154}
Note: See TracBrowser for help on using the repository browser.