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

Last change on this file since 2763 was 2763, checked in by sjboddie, 23 years ago

fixed bug in recent changes to default formatstring

  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 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 while (thissection != endsection) {
127
128 get_link_icon (*thissection, args, collink, link, icon);
129 bool highlight = false;
130 if (!arg_d.empty()) {
131 if (arg_d == (*thissection).OID) highlight = true;
132 } else
133 if (arg_cl == (*thissection).OID) highlight = true;
134
135 if (use_table || colnumber > 0) textout << "<tr valign=top>";
136 textout << outconvert << disp
137 << get_formatted_string (collection, collectproto,
138 *thissection, disp, formatlistptr,
139 link, icon, highlight, logout);
140
141 if (use_table || colnumber > 0) textout << "</tr>";
142 textout << "\n";
143 thissection ++;
144 }
145
146 if (use_table) textout << "</table>\n";
147 if (colnumber > 0) textout << "</table></td></tr></table>\n";
148
149 return 1;
150}
151
152
153// get_link_icon attempts to work out what type of icon should be displayed for
154// the given section and what it should link to.
155void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
156 const text_t &collink, text_t &link, text_t &icon) {
157
158 link = "<a href=\"_httpdocument_" + collink;
159 icon = "_document:icontext_";
160 int haschildren = 0;
161
162 if (section.metadata.count("haschildren")>0)
163 haschildren = section.metadata["haschildren"].values[0].getint();
164
165 text_t doctype;
166 if (section.metadata.count("doctype")>0)
167 doctype = section.metadata["doctype"].values[0];
168
169 text_t &arg_d = args["d"];
170 text_t &arg_cl = args["cl"];
171
172 if (args["a"] == "q") {
173 // query results
174 if (is_top (section.OID)) icon = "_document:iconclosedbook_";
175 else if (haschildren == 1) icon = "_document:iconclosedfolder_";
176 link += "&cl=search&d=" + section.OID + "\">";
177
178 } else if (!arg_d.empty()) {
179 // document level
180 if (is_top(section.OID)) {
181 icon = "_document:iconopenbook_";
182 if (arg_cl == "search") link = "<a href=\"_httpquery_\">";
183 else link += "&cl=" + arg_cl + "\">";
184
185 } else if (haschildren == 1) {
186 if ((args["gc"] == "1") ||
187 (is_child_of (section.OID, arg_d)) ||
188 (section.OID == arg_d)) {
189 icon = "_document:iconopenfolder_";
190 link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
191 } else {
192 icon = "_document:iconclosedfolder_";
193 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
194 }
195 } else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
196
197 } else {
198 // classification level
199 if (haschildren == 1) {
200 if (doctype == "classify") {
201 if ((args["gc"] == "1") ||
202 (is_child_of (section.OID, arg_cl)) ||
203 (section.OID == arg_cl)) {
204 icon = "_document:iconopenbookshelf_";
205 link += "&cl=" + section.OID + ".pr\">";
206 } else {
207 icon = "_document:iconclosedbookshelf_";
208 link += "&cl=" + section.OID + "\">";
209 }
210 } else {
211 icon = "_document:iconclosedbook_";
212 link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
213 }
214 } else {
215 if (doctype == "classify") link = "";
216 else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
217 }
218 }
219}
Note: See TracBrowser for help on using the repository browser.