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

Last change on this file since 824 was 824, checked in by davidb, 24 years ago

Better protection when accessing "haschildren"

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