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

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

(Adding dynamic classifiers) Now displays the parent classifier node as well as the documents.

  • Property svn:executable set to *
File size: 8.0 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 arg_ainfo.shortname = "dcn";
44 arg_ainfo.longname = "dynamic classifier node";
45 arg_ainfo.multiplechar = true;
46 arg_ainfo.defaultstatus = cgiarginfo::weak;
47 arg_ainfo.argdefault = "";
48 arg_ainfo.savedarginfo = cgiarginfo::must;
49 argsinfo.addarginfo (NULL, arg_ainfo);
50}
51
52
53dynamicclassifieraction::~dynamicclassifieraction()
54{
55}
56
57
58bool dynamicclassifieraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
59 recptprotolistclass *protos, ostream &logout)
60{
61 return true;
62}
63
64
65void dynamicclassifieraction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
66 response_t &response,text_t &response_data,
67 ostream &logout)
68{
69 response = content;
70 response_data = "text/html";
71}
72
73
74// define all the macros which might be used by other actions
75// to produce pages.
76void dynamicclassifieraction::define_external_macros (displayclass &disp, cgiargsclass &args,
77 recptprotolistclass *protos, ostream &logout)
78{
79 // define_external_macros sets the following macros:
80}
81
82
83// define all the macros which are related to pages generated
84// by this action. we also load up the formatinfo structure
85// here (it's used in do_action as well as here)
86void dynamicclassifieraction::define_internal_macros (displayclass &disp, cgiargsclass &args,
87 recptprotolistclass *protos, ostream &logout)
88{
89 // define_internal_macros sets the following macros:
90}
91
92
93bool dynamicclassifieraction::do_action(cgiargsclass &args, recptprotolistclass *protos,
94 browsermapclass *browsers, displayclass &disp,
95 outconvertclass &outconvert, ostream &textout,
96 ostream &logout)
97{
98 // A valid collection server is vital
99 recptproto *collectproto = protos->getrecptproto (args["c"], logout);
100 if (collectproto == NULL)
101 {
102 logout << "dynamicclassifieraction::do_action called with NULL collectproto\n";
103 return false;
104 }
105
106 textout << outconvert << disp << "_document:header_\n";
107 textout << outconvert << disp << "_document:content_\n";
108
109 // Check a dynamic classifier ID has been specified
110 text_t arg_dcl = args["dcl"];
111 if (arg_dcl.empty())
112 {
113 textout << outconvert << disp << "Error: Missing dcl argument.\n";
114 textout << outconvert << disp << "_document:footer_\n";
115 return true;
116 }
117
118 // Check the dynamic classifier ID is valid (ie. there is an entry in the collect.cfg file for it)
119 ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
120 if (cinfo->dynamic_classifiers.find(arg_dcl) == cinfo->dynamic_classifiers.end())
121 {
122 textout << outconvert << disp << "Error: Invalid dcl value \"" << arg_dcl << "\".\n";
123 textout << outconvert << disp << "_document:footer_\n";
124 return true;
125 }
126
127 text_t metadata_element_name = cinfo->dynamic_classifiers[arg_dcl];
128 text_t classifier_type = "VList";
129 browserclass *bptr = browsers->getbrowser (classifier_type);
130
131 // Get the formatstring if there is one, or use the browser's default otherwise
132 text_t formatstring;
133 if (!get_formatstring (arg_dcl, classifier_type, cinfo->format, formatstring))
134 {
135 formatstring = bptr->get_default_formatstring();
136 }
137 format_t *formatlistptr = new format_t();
138 text_tset metadata;
139 bool getParents = false;
140 parse_formatstring (formatstring, formatlistptr, metadata, getParents);
141 bool use_table = is_table_content (formatlistptr);
142
143 // Check if a dynamic classifier node has been specified
144 text_t arg_dcn = args["dcn"];
145 if (arg_dcn.empty())
146 {
147 // No, so display the top-level classifier page, containing all the metadata values for the specified element
148 FilterResponse_t metadata_values_response;
149 get_metadata_values (metadata_element_name, args["c"], collectproto, metadata_values_response, logout);
150
151 // Add metadata necessary for output_section_group() to display the results as classifier nodes
152 ResultDocInfo_tarray::iterator metadata_value_iterator = metadata_values_response.docInfo.begin();
153 while (metadata_value_iterator != metadata_values_response.docInfo.end())
154 {
155 (*metadata_value_iterator).metadata["doctype"].values.push_back("classify");
156 (*metadata_value_iterator).metadata["haschildren"].values.push_back("1");
157 (*metadata_value_iterator).metadata["numleafdocs"].values.push_back((*metadata_value_iterator).result_num);
158 (*metadata_value_iterator).metadata["Title"].values.push_back((*metadata_value_iterator).OID);
159 metadata_value_iterator++;
160 }
161
162 // Display the classifier nodes
163 bptr->output_section_group (metadata_values_response, args, args["c"], 0, formatlistptr, use_table, metadata, getParents, collectproto, disp, outconvert, textout, logout);
164 }
165 else
166 {
167 // Yes, so get all the documents that fall under this node
168 text_t metadata_value = arg_dcn;
169 FilterResponse_t document_OIDs_response;
170 get_documents_with_metadata_value (metadata_element_name, metadata_value, args["c"], collectproto, document_OIDs_response, logout);
171
172 // Check the metadata value is valid
173 if (document_OIDs_response.docInfo.empty())
174 {
175 textout << outconvert << disp << "Error: No documents have metadata value \"" << arg_dcn << "\".\n";
176 textout << outconvert << disp << "_document:footer_\n";
177 return true;
178 }
179
180 // Make an array of matching document OIDs
181 text_tarray document_OIDs;
182 ResultDocInfo_tarray::iterator document_OID_iterator = document_OIDs_response.docInfo.begin();
183 while (document_OID_iterator != document_OIDs_response.docInfo.end())
184 {
185 document_OIDs.push_back ((*document_OID_iterator).OID);
186 document_OID_iterator++;
187 }
188
189 // Display the classifier node
190 ResultDocInfo_t classifier_node;
191 classifier_node.OID = arg_dcn;
192 classifier_node.metadata["doctype"].values.push_back("classify");
193 classifier_node.metadata["haschildren"].values.push_back("1");
194 classifier_node.metadata["numleafdocs"].values.push_back(document_OIDs.size());
195 classifier_node.metadata["Title"].values.push_back(classifier_node.OID);
196 bptr->output_section_group (classifier_node, args, args["c"], 0, formatlistptr, use_table, metadata, getParents, collectproto, disp, outconvert, textout, logout);
197
198 // Request the necessary metadata for the documents under this node
199 FilterResponse_t document_info_response;
200 get_info (document_OIDs, args["c"], args["l"], metadata, getParents, collectproto, document_info_response, logout);
201
202 // Display the document nodes
203 bptr->output_section_group (document_info_response, args, args["c"], 1, formatlistptr, use_table, metadata, getParents, collectproto, disp, outconvert, textout, logout);
204 }
205
206 textout << outconvert << disp << "_document:footer_\n";
207 return true;
208}
Note: See TracBrowser for help on using the repository browser.