source: trunk/gsdl/src/recpt/vlistbrowserclass.cpp@ 12525

Last change on this file since 12525 was 12488, checked in by mdewsnip, 18 years ago

Some XHTML compliance changes.

  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
RevLine 
[649]1/**********************************************************************
2 *
3 * vlistbrowserclass.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
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 "vlistbrowserclass.h"
27#include <assert.h>
28#include "OIDtools.h"
[12044]29#include "browsetoolsclass.h"
[649]30
31vlistbrowserclass::vlistbrowserclass () {
32}
33
34vlistbrowserclass::~vlistbrowserclass () {
35}
36
37// returns the name that specifies the browserclass type
38text_t vlistbrowserclass::get_browser_name () {
39 return "VList";
40}
41
[7392]42browserclass* vlistbrowserclass::clone()
43{
44 vlistbrowserclass* browser = new vlistbrowserclass();
45 if (browser != NULL) {
46#ifdef GSDL_USE_BY_BOOK_MACROS
47 browser->m_oByBookMacros.Copy(m_oByBookMacros);
48#endif
49 }
50 return browser;
51}
52
[649]53void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
54 metadata.insert ("haschildren");
55 metadata.insert ("doctype");
56}
57
[668]58text_t vlistbrowserclass::get_default_formatstring () {
[10947]59 return "<td valign=\"top\">[link][icon][/link]</td>"
[11503]60 "<td valign=\"top\">[srclink]{Or}{[thumbicon],[srcicon]}[/srclink]</td>"
61 "<td valign=\"top\">[highlight]{Or}{[dls.Title],[dc.Title],[Title],Untitled}[/highlight]"
[2751]62 "{If}{[Source],<br><i>([Source])</i>}</td>";
[668]63}
64
[12044]65int vlistbrowserclass::output_section_group(ResultDocInfo_t &section, cgiargsclass &args,
66 const text_t &collection, int colnumber,
67 format_t *formatlistptr, bool use_table,
68 text_tset &metadata, bool &getParents,
69 recptproto * collectproto, displayclass &disp,
70 outconvertclass &outconvert, ostream &textout,
71 ostream& logout)
72{
73 browsetoolsclass btools;
[649]74 text_t link, icon;
[747]75 text_t collink = collection;
[12001]76
77#ifndef DOCHANDLE
[10873]78 if (!collink.empty()) collink = "&amp;c=" + collink;
[12001]79#endif
[747]80
81 get_link_icon (section, args, collink, link, icon);
[668]82 bool highlight = false;
83 if (!args["d"].empty()) {
84 if (args["d"] == section.OID) highlight = true;
85 } else
86 if (args["cl"] == section.OID) highlight = true;
[649]87
[668]88
[10947]89 /* use_table is set to true if the format string starts with <td> */
[668]90 if (use_table || colnumber > 0) {
[10947]91 textout << outconvert << "<table class=\"v_list\"><tr valign=\"top\">";
[668]92 // get tab size
93 text_t tab; int itab;
[7433]94 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
[668]95 itab = tab.getint();
96 if (colnumber > 0) textout << outconvert << disp
[12488]97 << "<td><img alt=\"\" src=\"_httpimg_/space.gif\" width=\""
98 << (itab*colnumber) << "\"/></td>";
[10947]99 } else {
100 textout << outconvert << "<div class=\"v_list\">\n";
[668]101 }
102
[4906]103 text_tmap options;
104 options["link"] = link;
105 options["icon"] = icon;
106 if (highlight) options["highlight"] = "1";
107 else options["highlight"] = "0";
[12044]108 options["DocImage"] = btools.get_cover_image();
[1443]109 textout << outconvert << disp
110 << get_formatted_string (collection, collectproto,
[1610]111 section, disp, formatlistptr,
[4906]112 options, logout);
[649]113
[10947]114 if (use_table || colnumber > 0) {
115 textout << outconvert << "</tr></table>\n";
116 } else {
117 textout << outconvert << "</div>\n";
118 }
[668]119
[649]120 return 1;
121}
122
[12044]123int vlistbrowserclass::output_section_group(FilterResponse_t &sections, cgiargsclass &args,
124 const text_t &collection, int colnumber,
125 format_t *formatlistptr, bool use_table,
126 text_tset &/*metadata*/, bool &/*getParents*/,
127 recptproto * collectproto, displayclass &disp,
128 outconvertclass &outconvert, ostream &textout,
129 ostream& logout)
130{
131 browsetoolsclass btools;
[668]132 text_t link, icon;
133 text_t &arg_d = args["d"];
134 text_t &arg_cl = args["cl"];
135
[747]136 text_t collink = collection;
[12001]137#ifndef DOCHANDLE
[10873]138 if (!collink.empty()) collink = "&amp;c=" + collink;
[12001]139#endif
[747]140
[668]141 if (colnumber > 0) {
[10947]142 textout << outconvert << "<table><tr valign=\"top\">";
[649]143 // get tab size
144 text_t tab; int itab;
[7433]145 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
[649]146 itab = tab.getint();
147 if (colnumber > 0) textout << outconvert << disp
[12488]148 << "<td><img alt=\"\" src=\"_httpimg_/space.gif\" width=\""
149 << (itab*colnumber) << "\"/></td>";
[3666]150 textout << outconvert << "<td>";
[649]151 }
152
[10947]153 /* use table set to true if format string starts with <td> */
154 if (use_table) {
155 textout << outconvert << "<table class=\"v_list\">\n";
156 } else {
157 textout << outconvert << "<div class=\"v_list\">\n";
158 }
159
[668]160 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
161 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
[649]162
[2899]163 // ** here lies Alan's hack to get 4 results per table row
[10947]164 int item = 0, perline; // set perline to 1 normally
[2899]165 text_t fstring;
[4906]166
167 text_tmap options;
168 options["link"] = link;
169 options["icon"] = icon;
170 options["highlight"] = "0";
[12044]171 options["DocImage"] = btools.get_cover_image();
[4936]172
[2899]173 if ( thissection != endsection ) { // only if there are results (else corrupts display)
[4906]174 fstring = get_formatted_string (collection, collectproto, *thissection,
175 disp, formatlistptr, options, logout);
[2899]176 // if format string
177 // has <td><t (e.g. <td><table>) then
178 // we assume it is an image and put it in 4 columns
179 if (fstring[5] == 't')
180 perline = 4;
181 else
182 perline = 1;
183 }
184
[668]185 while (thissection != endsection) {
[9620]186 ++item;
[747]187 get_link_icon (*thissection, args, collink, link, icon);
[668]188 bool highlight = false;
189 if (!arg_d.empty()) {
190 if (arg_d == (*thissection).OID) highlight = true;
191 } else
192 if (arg_cl == (*thissection).OID) highlight = true;
193
[2899]194 if ((item == 1 && use_table) || colnumber > 0 )
[3666]195 textout << outconvert << "<tr valign=top>\n";
[2899]196
[4906]197 options["link"] = link;
198 options["icon"] = icon;
199 if (highlight) options["highlight"] = "1";
200 else options["highlight"] = "0";
[12044]201 options["DocImage"] = btools.get_cover_image();
[4906]202
[1443]203 textout << outconvert << disp
[3543]204 << " " << get_formatted_string (collection, collectproto, *thissection, disp,
[4906]205 formatlistptr, options, logout);
[1443]206
[2899]207 if ((item >= perline && use_table) || colnumber > 0) {
[3666]208 textout << outconvert << "\n</tr>";
[2899]209 item = 0;
210 }
[3666]211 textout << outconvert << "\n";
[9620]212 ++thissection;
[668]213 }
214
[10947]215 if (use_table)
216 textout << outconvert << "</table>\n";
217 else
218 textout << outconvert << "</div>\n";
[4829]219 if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
[668]220
221 return 1;
[649]222}
223
224
225// get_link_icon attempts to work out what type of icon should be displayed for
226// the given section and what it should link to.
[5124]227// [modification to allow default document detach settings -- kjdon]
[649]228void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
[747]229 const text_t &collink, text_t &link, text_t &icon) {
[649]230
[12001]231#ifndef DOCHANDLE
[747]232 link = "<a href=\"_httpdocument_" + collink;
[12001]233#else
234 link = "<a href=\"_httpdocumenthandle_(" + collink;
235#endif
236
[5124]237 text_t link_end = "\">";
[12001]238#ifndef DOCHANDLE
[10873]239 text_t detach_link_end = "&amp;x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
[12001]240#else
241 text_t detach_link_end = "\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
242#endif
243
[649]244 icon = "_document:icontext_";
[5124]245
246 text_t doctype;
[824]247 int haschildren = 0;
[649]248
[824]249 if (section.metadata.count("haschildren")>0)
[934]250 haschildren = section.metadata["haschildren"].values[0].getint();
[824]251 if (section.metadata.count("doctype")>0)
[934]252 doctype = section.metadata["doctype"].values[0];
[824]253
[668]254 text_t &arg_d = args["d"];
255 text_t &arg_cl = args["cl"];
256
[649]257 if (args["a"] == "q") {
[5124]258 // query results list
[12001]259#ifndef DOCHANDLE
[10873]260 link += "&amp;cl=search&amp;d=" + section.OID;
[12001]261#else
262 link += "," + section.OID+")";
263#endif
[5124]264 if (args["xx"] == "1") {
265 link += detach_link_end;
266 } else {
267 link += link_end;
268 }
[3065]269 if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
[649]270 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
[5124]271
[668]272 } else if (!arg_d.empty()) {
[5124]273 // we are in a document - none of the links should be detach links
[649]274 if (is_top(section.OID)) {
[5124]275 // we link back to the originating page eg search page or classifier page
[649]276 icon = "_document:iconopenbook_";
[5124]277 if (arg_cl == "search") {
278 link = "<a href=\"_httpquery_\">";
279 }
[12001]280 else {
281#ifndef DOCHANDLE
282 link += "&amp;cl=" + arg_cl + "\">";
283#else
284 link += ","+arg_cl + ")\">";
285#endif
286 }
[5124]287
[649]288 } else if (haschildren == 1) {
[668]289 if ((args["gc"] == "1") ||
290 (is_child_of (section.OID, arg_d)) ||
291 (section.OID == arg_d)) {
[649]292 icon = "_document:iconopenfolder_";
[12001]293#ifndef DOCHANDLE
[10873]294 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + ".pr\">";
[12001]295#else
296 link += ","+section.OID + ".pr)\">";
297#endif
[649]298 } else {
299 icon = "_document:iconclosedfolder_";
[12001]300#ifndef DOCHANDLE
[10873]301 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
[12001]302#else
303 link += ","+section.OID + ")\">";
304#endif
[649]305 }
[3087]306 } else {
307 if (args["gt"] == "0") {
[12001]308#ifndef DOCHANDLE
[10873]309 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
[12001]310#else
311 link += ","+section.OID + ")\">";
312#endif
[3087]313 } else {
[12001]314#ifndef DOCHANDLE
[10873]315 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "#" + section.OID + "\">";
[12001]316#else
317 link += ","+section.OID + "#" + section.OID + ")\">";
318#endif
[3087]319 }
320 }
[5124]321
[649]322 } else {
[5124]323 // classification level - links to docs may be detaching
[649]324 if (haschildren == 1) {
325 if (doctype == "classify") {
[668]326 if ((args["gc"] == "1") ||
327 (is_child_of (section.OID, arg_cl)) ||
328 (section.OID == arg_cl)) {
[649]329 icon = "_document:iconopenbookshelf_";
[12001]330
331#ifndef DOCHANDLE
[10873]332 link += "&amp;cl=" + section.OID + ".pr\">";
[12001]333#else
334 link += ","+section.OID + ".pr)\">";
335#endif
336
337
[649]338 } else {
339 icon = "_document:iconclosedbookshelf_";
[12001]340
341#ifndef DOCHANDLE
[10873]342 link += "&amp;cl=" + section.OID + "\">";
[12001]343#else
344 link += ","+section.OID + ")\">";
345#endif
346
[649]347 }
348 } else {
[5124]349
[649]350 icon = "_document:iconclosedbook_";
[12001]351#ifndef DOCHANDLE
[10873]352 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
[12001]353#else
354 link += ","+section.OID+")";
355#endif
[5124]356 if (args["xx"] == "1") {
357 link += detach_link_end;
358 } else {
359 link += link_end;
360 }
361
[649]362 }
363 } else {
364 if (doctype == "classify") link = "";
[5124]365 else {
[12001]366#ifndef DOCHANDLE
[10873]367 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
[12001]368#else
369 link += "," + section.OID +")";
370#endif
[5124]371 if (args["xx"] == "1") {
372 link += detach_link_end;
373 } else {
374 link += link_end;
375 }
376 }
[649]377 }
378 }
[5124]379
[649]380}
Note: See TracBrowser for help on using the repository browser.