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

Last change on this file since 4906 was 4906, checked in by sjboddie, 21 years ago

Replaced overloaded get_formatted_string() functions in formattools with
a single function by using a text_tmap in place of the old link, text,
icon, and highlight variables.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
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"
29
30vlistbrowserclass::vlistbrowserclass () {
31}
32
33vlistbrowserclass::~vlistbrowserclass () {
34}
35
36// returns the name that specifies the browserclass type
37text_t vlistbrowserclass::get_browser_name () {
38 return "VList";
39}
40
41void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
42 metadata.insert ("haschildren");
43 metadata.insert ("doctype");
44}
45
46text_t vlistbrowserclass::get_default_formatstring () {
47 return "<td valign=top>[link][icon][/link]</td>"
48 "<td valign=top>[srclink][srcicon][/srclink]</td>"
49 "<td valign=top>[highlight]{Or}{[Title],Untitled}[/highlight]"
50 "{If}{[Source],<br><i>([Source])</i>}</td>";
51}
52
53int vlistbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
54 const text_t &collection, int colnumber,
55 format_t *formatlistptr, bool use_table,
56 text_tset &/*metadata*/, bool &/*getParents*/,
57 recptproto * collectproto, displayclass &disp,
58 outconvertclass &outconvert, ostream &textout,
59 ostream& logout) {
60
61 text_t link, icon;
62
63 text_t collink = collection;
64 if (!collink.empty()) collink = "&c=" + collink;
65
66 get_link_icon (section, args, collink, link, icon);
67 bool highlight = false;
68 if (!args["d"].empty()) {
69 if (args["d"] == section.OID) highlight = true;
70 } else
71 if (args["cl"] == section.OID) highlight = true;
72
73
74 if (use_table || colnumber > 0) {
75 textout << outconvert << "<table><tr valign=top>";
76 // get tab size
77 text_t tab; int itab;
78 disp.expandstring ("Global", "_tabwidth_", tab);
79 itab = tab.getint();
80 if (colnumber > 0) textout << outconvert << disp
81 << "<td><img src=\"_httpimg_/space.gif\" width="
82 << (itab*colnumber) << "></td>";
83 }
84
85 text_tmap options;
86 options["link"] = link;
87 options["icon"] = icon;
88 if (highlight) options["highlight"] = "1";
89 else options["highlight"] = "0";
90 textout << outconvert << disp
91 << get_formatted_string (collection, collectproto,
92 section, disp, formatlistptr,
93 options, logout);
94
95 if (use_table || colnumber > 0) textout << outconvert << "</tr></table>\n";
96
97 return 1;
98}
99
100int vlistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
101 const text_t &collection, int colnumber,
102 format_t *formatlistptr, bool use_table,
103 text_tset &/*metadata*/, bool &/*getParents*/,
104 recptproto * collectproto, displayclass &disp,
105 outconvertclass &outconvert, ostream &textout,
106 ostream& logout) {
107
108 text_t link, icon;
109 text_t &arg_d = args["d"];
110 text_t &arg_cl = args["cl"];
111
112 text_t collink = collection;
113 if (!collink.empty()) collink = "&c=" + collink;
114
115 if (colnumber > 0) {
116 textout << outconvert << "<table><tr valign=top>";
117 // get tab size
118 text_t tab; int itab;
119 disp.expandstring ("Global", "_tabwidth_", tab);
120 itab = tab.getint();
121 if (colnumber > 0) textout << outconvert << disp
122 << "<td><img src=\"_httpimg_/space.gif\" width="
123 << (itab*colnumber) << "></td>";
124 textout << outconvert << "<td>";
125 }
126 if (use_table) textout << outconvert << "<table>\n";
127
128 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
129 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
130
131 // ** here lies Alan's hack to get 4 results per table row
132 int item = 0, perline;; // set perline to 1 normally
133 text_t fstring;
134
135 text_tmap options;
136 options["link"] = link;
137 options["icon"] = icon;
138 options["highlight"] = "0";
139
140 if ( thissection != endsection ) { // only if there are results (else corrupts display)
141 fstring = get_formatted_string (collection, collectproto, *thissection,
142 disp, formatlistptr, options, logout);
143 // if format string
144 // has <td><t (e.g. <td><table>) then
145 // we assume it is an image and put it in 4 columns
146 if (fstring[5] == 't')
147 perline = 4;
148 else
149 perline = 1;
150 }
151
152 while (thissection != endsection) {
153 item++;
154 get_link_icon (*thissection, args, collink, link, icon);
155 bool highlight = false;
156 if (!arg_d.empty()) {
157 if (arg_d == (*thissection).OID) highlight = true;
158 } else
159 if (arg_cl == (*thissection).OID) highlight = true;
160
161 if ((item == 1 && use_table) || colnumber > 0 )
162 textout << outconvert << "<tr valign=top>\n";
163
164 options["link"] = link;
165 options["icon"] = icon;
166 if (highlight) options["highlight"] = "1";
167 else options["highlight"] = "0";
168
169 textout << outconvert << disp
170 << " " << get_formatted_string (collection, collectproto, *thissection, disp,
171 formatlistptr, options, logout);
172
173 if ((item >= perline && use_table) || colnumber > 0) {
174 textout << outconvert << "\n</tr>";
175 item = 0;
176 }
177 textout << outconvert << "\n";
178 thissection ++;
179 }
180
181 if (use_table) textout << outconvert << "</table>\n";
182 if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
183
184 return 1;
185}
186
187
188// get_link_icon attempts to work out what type of icon should be displayed for
189// the given section and what it should link to.
190void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
191 const text_t &collink, text_t &link, text_t &icon) {
192
193 link = "<a href=\"_httpdocument_" + collink;
194 icon = "_document:icontext_";
195 int haschildren = 0;
196
197 if (section.metadata.count("haschildren")>0)
198 haschildren = section.metadata["haschildren"].values[0].getint();
199
200 text_t doctype;
201 if (section.metadata.count("doctype")>0)
202 doctype = section.metadata["doctype"].values[0];
203
204 text_t &arg_d = args["d"];
205 text_t &arg_cl = args["cl"];
206
207 if (args["a"] == "q") {
208 // query results
209 if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
210 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
211 link += "&cl=search&d=" + section.OID + "\">";
212
213 } else if (!arg_d.empty()) {
214 // document level
215 if (is_top(section.OID)) {
216 icon = "_document:iconopenbook_";
217 if (arg_cl == "search") link = "<a href=\"_httpquery_\">";
218 else link += "&cl=" + arg_cl + "\">";
219
220 } else if (haschildren == 1) {
221 if ((args["gc"] == "1") ||
222 (is_child_of (section.OID, arg_d)) ||
223 (section.OID == arg_d)) {
224 icon = "_document:iconopenfolder_";
225 link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
226 } else {
227 icon = "_document:iconclosedfolder_";
228 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
229 }
230 } else {
231 if (args["gt"] == "0") {
232 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
233 } else {
234 link += "&cl=" + arg_cl + "&d=" + section.OID + "#" + section.OID + "\">";
235 }
236 }
237
238 } else {
239 // classification level
240 if (haschildren == 1) {
241 if (doctype == "classify") {
242 if ((args["gc"] == "1") ||
243 (is_child_of (section.OID, arg_cl)) ||
244 (section.OID == arg_cl)) {
245 icon = "_document:iconopenbookshelf_";
246 link += "&cl=" + section.OID + ".pr\">";
247 } else {
248 icon = "_document:iconclosedbookshelf_";
249 link += "&cl=" + section.OID + "\">";
250 }
251 } else {
252 icon = "_document:iconclosedbook_";
253 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
254 }
255 } else {
256 if (doctype == "classify") link = "";
257 else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
258 }
259 }
260}
Note: See TracBrowser for help on using the repository browser.