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

Last change on this file since 9620 was 9620, checked in by kjdon, 19 years ago

added some x++ -> ++x changes submitted by Emanuel Dejanu

  • Property svn:keywords set to Author Date Id Revision
File size: 9.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 "browsetools.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][srcicon][/srclink]</td>"
61 "<td valign=top>[highlight]{Or}{[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 text_t link, icon;
74
75 text_t collink = collection;
76 if (!collink.empty()) collink = "&c=" + collink;
77
78 get_link_icon (section, args, collink, link, icon);
79 bool highlight = false;
80 if (!args["d"].empty()) {
81 if (args["d"] == section.OID) highlight = true;
82 } else
83 if (args["cl"] == section.OID) highlight = true;
84
85
86 if (use_table || colnumber > 0) {
87 textout << outconvert << "<table><tr valign=top>";
88 // get tab size
89 text_t tab; int itab;
90 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
91 itab = tab.getint();
92 if (colnumber > 0) textout << outconvert << disp
93 << "<td><img src=\"_httpimg_/space.gif\" width="
94 << (itab*colnumber) << "></td>";
95 }
96
97 text_tmap options;
98 options["link"] = link;
99 options["icon"] = icon;
100 if (highlight) options["highlight"] = "1";
101 else options["highlight"] = "0";
102 options["DocImage"] = get_cover_image();
103 textout << outconvert << disp
104 << get_formatted_string (collection, collectproto,
105 section, disp, formatlistptr,
106 options, logout);
107
108 if (use_table || colnumber > 0) textout << outconvert << "</tr></table>\n";
109
110 return 1;
111}
112
113int vlistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
114 const text_t &collection, int colnumber,
115 format_t *formatlistptr, bool use_table,
116 text_tset &/*metadata*/, bool &/*getParents*/,
117 recptproto * collectproto, displayclass &disp,
118 outconvertclass &outconvert, ostream &textout,
119 ostream& logout) {
120
121 text_t link, icon;
122 text_t &arg_d = args["d"];
123 text_t &arg_cl = args["cl"];
124
125 text_t collink = collection;
126 if (!collink.empty()) collink = "&c=" + collink;
127
128 if (colnumber > 0) {
129 textout << outconvert << "<table><tr valign=top>";
130 // get tab size
131 text_t tab; int itab;
132 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
133 itab = tab.getint();
134 if (colnumber > 0) textout << outconvert << disp
135 << "<td><img src=\"_httpimg_/space.gif\" width="
136 << (itab*colnumber) << "></td>";
137 textout << outconvert << "<td>";
138 }
139 if (use_table) textout << outconvert << "<table>\n";
140
141 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
142 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
143
144 // ** here lies Alan's hack to get 4 results per table row
145 int item = 0, perline;; // set perline to 1 normally
146 text_t fstring;
147
148 text_tmap options;
149 options["link"] = link;
150 options["icon"] = icon;
151 options["highlight"] = "0";
152 options["DocImage"] = get_cover_image();
153
154 if ( thissection != endsection ) { // only if there are results (else corrupts display)
155 fstring = get_formatted_string (collection, collectproto, *thissection,
156 disp, formatlistptr, options, logout);
157 // if format string
158 // has <td><t (e.g. <td><table>) then
159 // we assume it is an image and put it in 4 columns
160 if (fstring[5] == 't')
161 perline = 4;
162 else
163 perline = 1;
164 }
165
166 while (thissection != endsection) {
167 ++item;
168 get_link_icon (*thissection, args, collink, link, icon);
169 bool highlight = false;
170 if (!arg_d.empty()) {
171 if (arg_d == (*thissection).OID) highlight = true;
172 } else
173 if (arg_cl == (*thissection).OID) highlight = true;
174
175 if ((item == 1 && use_table) || colnumber > 0 )
176 textout << outconvert << "<tr valign=top>\n";
177
178 options["link"] = link;
179 options["icon"] = icon;
180 if (highlight) options["highlight"] = "1";
181 else options["highlight"] = "0";
182 options["DocImage"] = get_cover_image();
183
184 textout << outconvert << disp
185 << " " << get_formatted_string (collection, collectproto, *thissection, disp,
186 formatlistptr, options, logout);
187
188 if ((item >= perline && use_table) || colnumber > 0) {
189 textout << outconvert << "\n</tr>";
190 item = 0;
191 }
192 textout << outconvert << "\n";
193 ++thissection;
194 }
195
196 if (use_table) textout << outconvert << "</table>\n";
197 if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
198
199 return 1;
200}
201
202
203// get_link_icon attempts to work out what type of icon should be displayed for
204// the given section and what it should link to.
205// [modification to allow default document detach settings -- kjdon]
206void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
207 const text_t &collink, text_t &link, text_t &icon) {
208
209 link = "<a href=\"_httpdocument_" + collink;
210 text_t link_end = "\">";
211 text_t detach_link_end = "&x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
212 icon = "_document:icontext_";
213
214 text_t doctype;
215 int haschildren = 0;
216
217 if (section.metadata.count("haschildren")>0)
218 haschildren = section.metadata["haschildren"].values[0].getint();
219 if (section.metadata.count("doctype")>0)
220 doctype = section.metadata["doctype"].values[0];
221
222 text_t &arg_d = args["d"];
223 text_t &arg_cl = args["cl"];
224
225 if (args["a"] == "q") {
226 // query results list
227 link += "&cl=search&d=" + section.OID;
228
229 if (args["xx"] == "1") {
230 link += detach_link_end;
231 } else {
232 link += link_end;
233 }
234 if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
235 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
236
237 } else if (!arg_d.empty()) {
238 // we are in a document - none of the links should be detach links
239 if (is_top(section.OID)) {
240 // we link back to the originating page eg search page or classifier page
241 icon = "_document:iconopenbook_";
242 if (arg_cl == "search") {
243 link = "<a href=\"_httpquery_\">";
244 }
245 else link += "&cl=" + arg_cl + "\">";
246
247 } else if (haschildren == 1) {
248 if ((args["gc"] == "1") ||
249 (is_child_of (section.OID, arg_d)) ||
250 (section.OID == arg_d)) {
251 icon = "_document:iconopenfolder_";
252 link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
253 } else {
254 icon = "_document:iconclosedfolder_";
255 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
256 }
257 } else {
258 if (args["gt"] == "0") {
259 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
260 } else {
261 link += "&cl=" + arg_cl + "&d=" + section.OID + "#" + section.OID + "\">";
262 }
263 }
264
265 } else {
266 // classification level - links to docs may be detaching
267 if (haschildren == 1) {
268 if (doctype == "classify") {
269 if ((args["gc"] == "1") ||
270 (is_child_of (section.OID, arg_cl)) ||
271 (section.OID == arg_cl)) {
272 icon = "_document:iconopenbookshelf_";
273 link += "&cl=" + section.OID + ".pr\">";
274 } else {
275 icon = "_document:iconclosedbookshelf_";
276 link += "&cl=" + section.OID + "\">";
277 }
278 } else {
279
280 icon = "_document:iconclosedbook_";
281 link += "&cl=" + arg_cl + "&d=" + section.OID;
282 if (args["xx"] == "1") {
283 link += detach_link_end;
284 } else {
285 link += link_end;
286 }
287
288 }
289 } else {
290 if (doctype == "classify") link = "";
291 else {
292 link += "&cl=" + arg_cl + "&d=" + section.OID;
293 if (args["xx"] == "1") {
294 link += detach_link_end;
295 } else {
296 link += link_end;
297 }
298 }
299 }
300 }
301
302}
Note: See TracBrowser for help on using the repository browser.