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

Last change on this file since 13017 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
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#include "browsetoolsclass.h"
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
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
53void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
54 metadata.insert ("haschildren");
55 metadata.insert ("doctype");
56}
57
58text_t vlistbrowserclass::get_default_formatstring () {
59 return "<td valign=\"top\">[link][icon][/link]</td>"
60 "<td valign=\"top\">[srclink]{Or}{[thumbicon],[srcicon]}[/srclink]</td>"
61 "<td valign=\"top\">[highlight]{Or}{[dls.Title],[dc.Title],[Title],Untitled}[/highlight]"
62 "{If}{[Source],<br><i>([Source])</i>}</td>";
63}
64
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;
74 text_t link, icon;
75 text_t collink = collection;
76
77#ifndef DOCHANDLE
78 if (!collink.empty()) collink = "&amp;c=" + collink;
79#endif
80
81 get_link_icon (section, args, collink, link, icon);
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;
87
88
89 /* use_table is set to true if the format string starts with <td> */
90 if (use_table || colnumber > 0) {
91 textout << outconvert << "<table class=\"v_list\"><tr valign=\"top\">";
92 // get tab size
93 text_t tab; int itab;
94 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
95 itab = tab.getint();
96 if (colnumber > 0) textout << outconvert << disp
97 << "<td><img alt=\"\" src=\"_httpimg_/space.gif\" width=\""
98 << (itab*colnumber) << "\"/></td>";
99 } else {
100 textout << outconvert << "<div class=\"v_list\">\n";
101 }
102
103 text_tmap options;
104 options["link"] = link;
105 options["icon"] = icon;
106 if (highlight) options["highlight"] = "1";
107 else options["highlight"] = "0";
108 options["DocImage"] = btools.get_cover_image();
109 textout << outconvert << disp
110 << get_formatted_string (collection, collectproto,
111 section, disp, formatlistptr,
112 options, logout);
113
114 if (use_table || colnumber > 0) {
115 textout << outconvert << "</tr></table>\n";
116 } else {
117 textout << outconvert << "</div>\n";
118 }
119
120 return 1;
121}
122
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;
132 text_t link, icon;
133 text_t &arg_d = args["d"];
134 text_t &arg_cl = args["cl"];
135
136 text_t collink = collection;
137#ifndef DOCHANDLE
138 if (!collink.empty()) collink = "&amp;c=" + collink;
139#endif
140
141 if (colnumber > 0) {
142 textout << outconvert << "<table><tr valign=\"top\">";
143 // get tab size
144 text_t tab; int itab;
145 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
146 itab = tab.getint();
147 if (colnumber > 0) textout << outconvert << disp
148 << "<td><img alt=\"\" src=\"_httpimg_/space.gif\" width=\""
149 << (itab*colnumber) << "\"/></td>";
150 textout << outconvert << "<td>";
151 }
152
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
160 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
161 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
162
163 // ** here lies Alan's hack to get 4 results per table row
164 int item = 0, perline; // set perline to 1 normally
165 text_t fstring;
166
167 text_tmap options;
168 options["link"] = link;
169 options["icon"] = icon;
170 options["highlight"] = "0";
171 options["DocImage"] = btools.get_cover_image();
172
173 if ( thissection != endsection ) { // only if there are results (else corrupts display)
174 fstring = get_formatted_string (collection, collectproto, *thissection,
175 disp, formatlistptr, options, logout);
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
185 while (thissection != endsection) {
186 ++item;
187 get_link_icon (*thissection, args, collink, link, icon);
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
194 if ((item == 1 && use_table) || colnumber > 0 )
195 textout << outconvert << "<tr valign=top>\n";
196
197 options["link"] = link;
198 options["icon"] = icon;
199 if (highlight) options["highlight"] = "1";
200 else options["highlight"] = "0";
201 options["DocImage"] = btools.get_cover_image();
202
203 textout << outconvert << disp
204 << " " << get_formatted_string (collection, collectproto, *thissection, disp,
205 formatlistptr, options, logout);
206
207 if ((item >= perline && use_table) || colnumber > 0) {
208 textout << outconvert << "\n</tr>";
209 item = 0;
210 }
211 textout << outconvert << "\n";
212 ++thissection;
213 }
214
215 if (use_table)
216 textout << outconvert << "</table>\n";
217 else
218 textout << outconvert << "</div>\n";
219 if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
220
221 return 1;
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.
227// [modification to allow default document detach settings -- kjdon]
228void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
229 const text_t &collink, text_t &link, text_t &icon) {
230
231#ifndef DOCHANDLE
232 link = "<a href=\"_httpdocument_" + collink;
233#else
234 link = "<a href=\"_httpdocumenthandle_(" + collink;
235#endif
236
237 text_t link_end = "\">";
238#ifndef DOCHANDLE
239 text_t detach_link_end = "&amp;x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
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
244 icon = "_document:icontext_";
245
246 text_t doctype;
247 int haschildren = 0;
248
249 if (section.metadata.count("haschildren")>0)
250 haschildren = section.metadata["haschildren"].values[0].getint();
251 if (section.metadata.count("doctype")>0)
252 doctype = section.metadata["doctype"].values[0];
253
254 text_t &arg_d = args["d"];
255 text_t &arg_cl = args["cl"];
256
257 if (args["a"] == "q") {
258 // query results list
259#ifndef DOCHANDLE
260 link += "&amp;cl=search&amp;d=" + section.OID;
261#else
262 link += "," + section.OID+")";
263#endif
264 if (args["xx"] == "1") {
265 link += detach_link_end;
266 } else {
267 link += link_end;
268 }
269 if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
270 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
271
272 } else if (!arg_d.empty()) {
273 // we are in a document - none of the links should be detach links
274 if (is_top(section.OID)) {
275 // we link back to the originating page eg search page or classifier page
276 icon = "_document:iconopenbook_";
277 if (arg_cl == "search") {
278 link = "<a href=\"_httpquery_\">";
279 }
280 else {
281#ifndef DOCHANDLE
282 link += "&amp;cl=" + arg_cl + "\">";
283#else
284 link += ","+arg_cl + ")\">";
285#endif
286 }
287
288 } else if (haschildren == 1) {
289 if ((args["gc"] == "1") ||
290 (is_child_of (section.OID, arg_d)) ||
291 (section.OID == arg_d)) {
292 icon = "_document:iconopenfolder_";
293#ifndef DOCHANDLE
294 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + ".pr\">";
295#else
296 link += ","+section.OID + ".pr)\">";
297#endif
298 } else {
299 icon = "_document:iconclosedfolder_";
300#ifndef DOCHANDLE
301 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
302#else
303 link += ","+section.OID + ")\">";
304#endif
305 }
306 } else {
307 if (args["gt"] == "0") {
308#ifndef DOCHANDLE
309 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
310#else
311 link += ","+section.OID + ")\">";
312#endif
313 } else {
314#ifndef DOCHANDLE
315 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "#" + section.OID + "\">";
316#else
317 link += ","+section.OID + "#" + section.OID + ")\">";
318#endif
319 }
320 }
321
322 } else {
323 // classification level - links to docs may be detaching
324 if (haschildren == 1) {
325 if (doctype == "classify") {
326 if ((args["gc"] == "1") ||
327 (is_child_of (section.OID, arg_cl)) ||
328 (section.OID == arg_cl)) {
329 icon = "_document:iconopenbookshelf_";
330
331#ifndef DOCHANDLE
332 link += "&amp;cl=" + section.OID + ".pr\">";
333#else
334 link += ","+section.OID + ".pr)\">";
335#endif
336
337
338 } else {
339 icon = "_document:iconclosedbookshelf_";
340
341#ifndef DOCHANDLE
342 link += "&amp;cl=" + section.OID + "\">";
343#else
344 link += ","+section.OID + ")\">";
345#endif
346
347 }
348 } else {
349
350 icon = "_document:iconclosedbook_";
351#ifndef DOCHANDLE
352 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
353#else
354 link += ","+section.OID+")";
355#endif
356 if (args["xx"] == "1") {
357 link += detach_link_end;
358 } else {
359 link += link_end;
360 }
361
362 }
363 } else {
364 if (doctype == "classify") link = "";
365 else {
366#ifndef DOCHANDLE
367 link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
368#else
369 link += "," + section.OID +")";
370#endif
371 if (args["xx"] == "1") {
372 link += detach_link_end;
373 } else {
374 link += link_end;
375 }
376 }
377 }
378 }
379
380}
Note: See TracBrowser for help on using the repository browser.