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

Last change on this file since 934 was 934, checked in by sjboddie, 24 years ago

minor tidy up - made some function definitions virtual

  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 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 * $Id: vlistbrowserclass.cpp 934 2000-02-17 02:33:09Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.7 2000/02/17 02:33:09 sjboddie
31 minor tidy up - made some function definitions virtual
32
33 Revision 1.6 1999/12/13 02:44:23 davidb
34 Better protection when accessing "haschildren"
35
36 Revision 1.5 1999/10/30 23:01:24 sjboddie
37 tidied things up slightly
38
39 Revision 1.4 1999/10/30 22:14:44 sjboddie
40 added a collection argument
41
42 Revision 1.3 1999/10/19 08:40:13 sjboddie
43 fixed some stupid compiler warnings on windows
44
45 Revision 1.2 1999/10/14 22:59:34 sjboddie
46 finished off browser classes
47
48 Revision 1.1 1999/10/10 08:14:11 sjboddie
49 - metadata now returns mp rather than array
50 - redesigned browsing support (although it's not finished so
51 won't currently work ;-)
52
53 */
54
55
56#include "vlistbrowserclass.h"
57#include <assert.h>
58#include "OIDtools.h"
59
60vlistbrowserclass::vlistbrowserclass () {
61}
62
63vlistbrowserclass::~vlistbrowserclass () {
64}
65
66// returns the name that specifies the browserclass type
67text_t vlistbrowserclass::get_browser_name () {
68 return "VList";
69}
70
71void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
72 metadata.insert ("haschildren");
73 metadata.insert ("doctype");
74}
75
76text_t vlistbrowserclass::get_default_formatstring () {
77 return "<td>[link][icon][/link]</td><td>[highlight]{Or}{[Title],Untitled}[/highlight]</td>";
78}
79
80int vlistbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
81 const text_t &collection, int colnumber,
82 format_t *formatlistptr, bool use_table,
83 text_tset &/*metadata*/, bool &/*getParents*/,
84 recptproto * /*collectproto*/, displayclass &disp,
85 outconvertclass &outconvert, ostream &textout,
86 ostream &/*logout*/) {
87
88 text_t link, icon;
89
90 text_t collink = collection;
91 if (!collink.empty()) collink = "&c=" + collink;
92
93 get_link_icon (section, args, collink, link, icon);
94 bool highlight = false;
95 if (!args["d"].empty()) {
96 if (args["d"] == section.OID) highlight = true;
97 } else
98 if (args["cl"] == section.OID) highlight = true;
99
100
101 if (use_table || colnumber > 0) {
102 textout << "<table><tr>";
103 // get tab size
104 text_t tab; int itab;
105 disp.expandstring ("Global", "_tabwidth_", tab);
106 itab = tab.getint();
107 if (colnumber > 0) textout << outconvert << disp
108 << "<td><img src=\"_httpimg_/space.gif\" width="
109 << (itab*colnumber) << "></td>";
110 }
111
112 textout << outconvert << disp << get_formatted_string (section, formatlistptr,
113 link, icon, highlight);
114
115 if (use_table || colnumber > 0) textout << "</tr></table>\n";
116
117 return 1;
118}
119
120int vlistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
121 const text_t &collection, int colnumber,
122 format_t *formatlistptr, bool use_table,
123 text_tset &/*metadata*/, bool &/*getParents*/,
124 recptproto * /*collectproto*/, displayclass &disp,
125 outconvertclass &outconvert, ostream &textout,
126 ostream &/*logout*/) {
127
128 text_t link, icon;
129 text_t &arg_d = args["d"];
130 text_t &arg_cl = args["cl"];
131
132 text_t collink = collection;
133 if (!collink.empty()) collink = "&c=" + collink;
134
135 if (colnumber > 0) {
136 textout << "<table><tr>";
137 // get tab size
138 text_t tab; int itab;
139 disp.expandstring ("Global", "_tabwidth_", tab);
140 itab = tab.getint();
141 if (colnumber > 0) textout << outconvert << disp
142 << "<td><img src=\"_httpimg_/space.gif\" width="
143 << (itab*colnumber) << "></td>";
144 textout << "<td>";
145 }
146 if (use_table) textout << "<table>\n";
147
148 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
149 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
150
151 while (thissection != endsection) {
152
153 get_link_icon (*thissection, args, collink, link, icon);
154 bool highlight = false;
155 if (!arg_d.empty()) {
156 if (arg_d == (*thissection).OID) highlight = true;
157 } else
158 if (arg_cl == (*thissection).OID) highlight = true;
159
160 if (use_table || colnumber > 0) textout << "<tr>";
161 textout << outconvert << disp << get_formatted_string (*thissection, formatlistptr,
162 link, icon, highlight);
163 if (use_table || colnumber > 0) textout << "</tr>";
164 textout << "\n";
165 thissection ++;
166 }
167
168 if (use_table) textout << "</table>\n";
169 if (colnumber > 0) textout << "</table></td></tr></table>\n";
170
171 return 1;
172}
173
174
175// get_link_icon attempts to work out what type of icon should be displayed for
176// the given section and what it should link to.
177void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
178 const text_t &collink, text_t &link, text_t &icon) {
179
180 link = "<a href=\"_httpdocument_" + collink;
181 icon = "_document:icontext_";
182 int haschildren = 0;
183
184 if (section.metadata.count("haschildren")>0)
185 haschildren = section.metadata["haschildren"].values[0].getint();
186
187 text_t doctype;
188 if (section.metadata.count("doctype")>0)
189 doctype = section.metadata["doctype"].values[0];
190
191 text_t &arg_d = args["d"];
192 text_t &arg_cl = args["cl"];
193
194 if (args["a"] == "q") {
195 // query results
196 if (is_top (section.OID)) icon = "_document:iconclosedbook_";
197 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
198 link += "&cl=search&d=" + section.OID + "\">";
199
200 } else if (!arg_d.empty()) {
201 // document level
202 if (is_top(section.OID)) {
203 icon = "_document:iconopenbook_";
204 if (arg_cl == "search") link = "<a href=\"_httpquery_\">";
205 else link += "&cl=" + arg_cl + "\">";
206
207 } else if (haschildren == 1) {
208 if ((args["gc"] == "1") ||
209 (is_child_of (section.OID, arg_d)) ||
210 (section.OID == arg_d)) {
211 icon = "_document:iconopenfolder_";
212 link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
213 } else {
214 icon = "_document:iconclosedfolder_";
215 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
216 }
217 } else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
218
219 } else {
220 // classification level
221 if (haschildren == 1) {
222 if (doctype == "classify") {
223 if ((args["gc"] == "1") ||
224 (is_child_of (section.OID, arg_cl)) ||
225 (section.OID == arg_cl)) {
226 icon = "_document:iconopenbookshelf_";
227 link += "&cl=" + section.OID + ".pr\">";
228 } else {
229 icon = "_document:iconclosedbookshelf_";
230 link += "&cl=" + section.OID + "\">";
231 }
232 } else {
233 icon = "_document:iconclosedbook_";
234 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
235 }
236 } else {
237 if (doctype == "classify") link = "";
238 else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
239 }
240 }
241}
Note: See TracBrowser for help on using the repository browser.