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

Last change on this file since 3065 was 3065, checked in by sjboddie, 22 years ago

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 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 << "<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 textout << outconvert << disp
86 << get_formatted_string (collection, collectproto,
87 section, disp, formatlistptr,
88 link, icon, highlight, logout);
89
90 if (use_table || colnumber > 0) textout << "</tr></table>\n";
91
92 return 1;
93}
94
95int vlistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
96 const text_t &collection, int colnumber,
97 format_t *formatlistptr, bool use_table,
98 text_tset &/*metadata*/, bool &/*getParents*/,
99 recptproto * collectproto, displayclass &disp,
100 outconvertclass &outconvert, ostream &textout,
101 ostream& logout) {
102
103 text_t link, icon;
104 text_t &arg_d = args["d"];
105 text_t &arg_cl = args["cl"];
106
107 text_t collink = collection;
108 if (!collink.empty()) collink = "&c=" + collink;
109
110 if (colnumber > 0) {
111 textout << "<table><tr valign=top>";
112 // get tab size
113 text_t tab; int itab;
114 disp.expandstring ("Global", "_tabwidth_", tab);
115 itab = tab.getint();
116 if (colnumber > 0) textout << outconvert << disp
117 << "<td><img src=\"_httpimg_/space.gif\" width="
118 << (itab*colnumber) << "></td>";
119 textout << "<td>";
120 }
121 if (use_table) textout << "<table>\n";
122
123 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
124 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
125
126 // ** here lies Alan's hack to get 4 results per table row
127 int item = 0, perline;; // set perline to 1 normally
128 text_t fstring;
129 if ( thissection != endsection ) { // only if there are results (else corrupts display)
130 fstring =
131 get_formatted_string (collection, collectproto,
132 *thissection, disp, formatlistptr, link, icon, false, logout);
133 // if format string
134 // has <td><t (e.g. <td><table>) then
135 // we assume it is an image and put it in 4 columns
136 if (fstring[5] == 't')
137 perline = 4;
138 else
139 perline = 1;
140 }
141
142 while (thissection != endsection) {
143 item++;
144 get_link_icon (*thissection, args, collink, link, icon);
145 bool highlight = false;
146 if (!arg_d.empty()) {
147 if (arg_d == (*thissection).OID) highlight = true;
148 } else
149 if (arg_cl == (*thissection).OID) highlight = true;
150
151 if ((item == 1 && use_table) || colnumber > 0 )
152 textout << "<tr valign=top>\n";
153
154 textout << outconvert << disp
155 << " " << get_formatted_string (collection, collectproto,
156 *thissection, disp, formatlistptr, link, icon, false, logout);
157
158 if ((item >= perline && use_table) || colnumber > 0) {
159 textout << "\n</tr>";
160 item = 0;
161 }
162 textout << "\n";
163 thissection ++;
164 }
165
166 if (use_table) textout << "</table>\n";
167 if (colnumber > 0) textout << "</table></td></tr></table>\n";
168
169 return 1;
170}
171
172
173// get_link_icon attempts to work out what type of icon should be displayed for
174// the given section and what it should link to.
175void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
176 const text_t &collink, text_t &link, text_t &icon) {
177
178 link = "<a href=\"_httpdocument_" + collink;
179 icon = "_document:icontext_";
180 int haschildren = 0;
181
182 if (section.metadata.count("haschildren")>0)
183 haschildren = section.metadata["haschildren"].values[0].getint();
184
185 text_t doctype;
186 if (section.metadata.count("doctype")>0)
187 doctype = section.metadata["doctype"].values[0];
188
189 text_t &arg_d = args["d"];
190 text_t &arg_cl = args["cl"];
191
192 if (args["a"] == "q") {
193 // query results
194 if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
195 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
196 link += "&cl=search&d=" + section.OID + "\">";
197
198 } else if (!arg_d.empty()) {
199 // document level
200 if (is_top(section.OID)) {
201 icon = "_document:iconopenbook_";
202 if (arg_cl == "search") link = "<a href=\"_httpquery_\">";
203 else link += "&cl=" + arg_cl + "\">";
204
205 } else if (haschildren == 1) {
206 if ((args["gc"] == "1") ||
207 (is_child_of (section.OID, arg_d)) ||
208 (section.OID == arg_d)) {
209 icon = "_document:iconopenfolder_";
210 link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
211 } else {
212 icon = "_document:iconclosedfolder_";
213 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
214 }
215 } else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
216
217 } else {
218 // classification level
219 if (haschildren == 1) {
220 if (doctype == "classify") {
221 if ((args["gc"] == "1") ||
222 (is_child_of (section.OID, arg_cl)) ||
223 (section.OID == arg_cl)) {
224 icon = "_document:iconopenbookshelf_";
225 link += "&cl=" + section.OID + ".pr\">";
226 } else {
227 icon = "_document:iconclosedbookshelf_";
228 link += "&cl=" + section.OID + "\">";
229 }
230 } else {
231 icon = "_document:iconclosedbook_";
232 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
233 }
234 } else {
235 if (doctype == "classify") link = "";
236 else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
237 }
238 }
239}
Note: See TracBrowser for help on using the repository browser.