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

Last change on this file since 770 was 752, checked in by sjboddie, 25 years ago

tidied things up slightly

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