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 |
|
---|
31 | vlistbrowserclass::vlistbrowserclass () {
|
---|
32 | }
|
---|
33 |
|
---|
34 | vlistbrowserclass::~vlistbrowserclass () {
|
---|
35 | }
|
---|
36 |
|
---|
37 | // returns the name that specifies the browserclass type
|
---|
38 | text_t vlistbrowserclass::get_browser_name () {
|
---|
39 | return "VList";
|
---|
40 | }
|
---|
41 |
|
---|
42 | void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
|
---|
43 | metadata.insert ("haschildren");
|
---|
44 | metadata.insert ("doctype");
|
---|
45 | }
|
---|
46 |
|
---|
47 | text_t vlistbrowserclass::get_default_formatstring () {
|
---|
48 | return "<td valign=top>[link][icon][/link]</td>"
|
---|
49 | "<td valign=top>[srclink][srcicon][/srclink]</td>"
|
---|
50 | "<td valign=top>[highlight]{Or}{[Title],Untitled}[/highlight]"
|
---|
51 | "{If}{[Source],<br><i>([Source])</i>}</td>";
|
---|
52 | }
|
---|
53 |
|
---|
54 | int vlistbrowserclass::output_section_group (ResultDocInfo_t §ion, cgiargsclass &args,
|
---|
55 | const text_t &collection, int colnumber,
|
---|
56 | format_t *formatlistptr, bool use_table,
|
---|
57 | text_tset &/*metadata*/, bool &/*getParents*/,
|
---|
58 | recptproto * collectproto, displayclass &disp,
|
---|
59 | outconvertclass &outconvert, ostream &textout,
|
---|
60 | ostream& logout) {
|
---|
61 |
|
---|
62 | text_t link, icon;
|
---|
63 |
|
---|
64 | text_t collink = collection;
|
---|
65 | if (!collink.empty()) collink = "&c=" + collink;
|
---|
66 |
|
---|
67 | get_link_icon (section, args, collink, link, icon);
|
---|
68 | bool highlight = false;
|
---|
69 | if (!args["d"].empty()) {
|
---|
70 | if (args["d"] == section.OID) highlight = true;
|
---|
71 | } else
|
---|
72 | if (args["cl"] == section.OID) highlight = true;
|
---|
73 |
|
---|
74 |
|
---|
75 | if (use_table || colnumber > 0) {
|
---|
76 | textout << outconvert << "<table><tr valign=top>";
|
---|
77 | // get tab size
|
---|
78 | text_t tab; int itab;
|
---|
79 | disp.expandstring ("Global", "_tabwidth_", tab);
|
---|
80 | itab = tab.getint();
|
---|
81 | if (colnumber > 0) textout << outconvert << disp
|
---|
82 | << "<td><img src=\"_httpimg_/space.gif\" width="
|
---|
83 | << (itab*colnumber) << "></td>";
|
---|
84 | }
|
---|
85 |
|
---|
86 | text_tmap options;
|
---|
87 | options["link"] = link;
|
---|
88 | options["icon"] = icon;
|
---|
89 | if (highlight) options["highlight"] = "1";
|
---|
90 | else options["highlight"] = "0";
|
---|
91 | options["DocImage"] = get_cover_image();
|
---|
92 | textout << outconvert << disp
|
---|
93 | << get_formatted_string (collection, collectproto,
|
---|
94 | section, disp, formatlistptr,
|
---|
95 | options, logout);
|
---|
96 |
|
---|
97 | if (use_table || colnumber > 0) textout << outconvert << "</tr></table>\n";
|
---|
98 |
|
---|
99 | return 1;
|
---|
100 | }
|
---|
101 |
|
---|
102 | int vlistbrowserclass::output_section_group (FilterResponse_t §ions, cgiargsclass &args,
|
---|
103 | const text_t &collection, int colnumber,
|
---|
104 | format_t *formatlistptr, bool use_table,
|
---|
105 | text_tset &/*metadata*/, bool &/*getParents*/,
|
---|
106 | recptproto * collectproto, displayclass &disp,
|
---|
107 | outconvertclass &outconvert, ostream &textout,
|
---|
108 | ostream& logout) {
|
---|
109 |
|
---|
110 | text_t link, icon;
|
---|
111 | text_t &arg_d = args["d"];
|
---|
112 | text_t &arg_cl = args["cl"];
|
---|
113 |
|
---|
114 | text_t collink = collection;
|
---|
115 | if (!collink.empty()) collink = "&c=" + collink;
|
---|
116 |
|
---|
117 | if (colnumber > 0) {
|
---|
118 | textout << outconvert << "<table><tr valign=top>";
|
---|
119 | // get tab size
|
---|
120 | text_t tab; int itab;
|
---|
121 | disp.expandstring ("Global", "_tabwidth_", tab);
|
---|
122 | itab = tab.getint();
|
---|
123 | if (colnumber > 0) textout << outconvert << disp
|
---|
124 | << "<td><img src=\"_httpimg_/space.gif\" width="
|
---|
125 | << (itab*colnumber) << "></td>";
|
---|
126 | textout << outconvert << "<td>";
|
---|
127 | }
|
---|
128 | if (use_table) textout << outconvert << "<table>\n";
|
---|
129 |
|
---|
130 | ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
|
---|
131 | ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
|
---|
132 |
|
---|
133 | // ** here lies Alan's hack to get 4 results per table row
|
---|
134 | int item = 0, perline;; // set perline to 1 normally
|
---|
135 | text_t fstring;
|
---|
136 |
|
---|
137 | text_tmap options;
|
---|
138 | options["link"] = link;
|
---|
139 | options["icon"] = icon;
|
---|
140 | options["highlight"] = "0";
|
---|
141 | options["DocImage"] = get_cover_image();
|
---|
142 |
|
---|
143 | if ( thissection != endsection ) { // only if there are results (else corrupts display)
|
---|
144 | fstring = get_formatted_string (collection, collectproto, *thissection,
|
---|
145 | disp, formatlistptr, options, logout);
|
---|
146 | // if format string
|
---|
147 | // has <td><t (e.g. <td><table>) then
|
---|
148 | // we assume it is an image and put it in 4 columns
|
---|
149 | if (fstring[5] == 't')
|
---|
150 | perline = 4;
|
---|
151 | else
|
---|
152 | perline = 1;
|
---|
153 | }
|
---|
154 |
|
---|
155 | while (thissection != endsection) {
|
---|
156 | item++;
|
---|
157 | get_link_icon (*thissection, args, collink, link, icon);
|
---|
158 | bool highlight = false;
|
---|
159 | if (!arg_d.empty()) {
|
---|
160 | if (arg_d == (*thissection).OID) highlight = true;
|
---|
161 | } else
|
---|
162 | if (arg_cl == (*thissection).OID) highlight = true;
|
---|
163 |
|
---|
164 | if ((item == 1 && use_table) || colnumber > 0 )
|
---|
165 | textout << outconvert << "<tr valign=top>\n";
|
---|
166 |
|
---|
167 | options["link"] = link;
|
---|
168 | options["icon"] = icon;
|
---|
169 | if (highlight) options["highlight"] = "1";
|
---|
170 | else options["highlight"] = "0";
|
---|
171 | options["DocImage"] = get_cover_image();
|
---|
172 |
|
---|
173 | textout << outconvert << disp
|
---|
174 | << " " << get_formatted_string (collection, collectproto, *thissection, disp,
|
---|
175 | formatlistptr, options, logout);
|
---|
176 |
|
---|
177 | if ((item >= perline && use_table) || colnumber > 0) {
|
---|
178 | textout << outconvert << "\n</tr>";
|
---|
179 | item = 0;
|
---|
180 | }
|
---|
181 | textout << outconvert << "\n";
|
---|
182 | thissection ++;
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (use_table) textout << outconvert << "</table>\n";
|
---|
186 | if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
|
---|
187 |
|
---|
188 | return 1;
|
---|
189 | }
|
---|
190 |
|
---|
191 |
|
---|
192 | // get_link_icon attempts to work out what type of icon should be displayed for
|
---|
193 | // the given section and what it should link to.
|
---|
194 | void vlistbrowserclass::get_link_icon (ResultDocInfo_t §ion, cgiargsclass &args,
|
---|
195 | const text_t &collink, text_t &link, text_t &icon) {
|
---|
196 |
|
---|
197 | link = "<a href=\"_httpdocument_" + collink;
|
---|
198 | icon = "_document:icontext_";
|
---|
199 | int haschildren = 0;
|
---|
200 |
|
---|
201 | if (section.metadata.count("haschildren")>0)
|
---|
202 | haschildren = section.metadata["haschildren"].values[0].getint();
|
---|
203 |
|
---|
204 | text_t doctype;
|
---|
205 | if (section.metadata.count("doctype")>0)
|
---|
206 | doctype = section.metadata["doctype"].values[0];
|
---|
207 |
|
---|
208 | text_t &arg_d = args["d"];
|
---|
209 | text_t &arg_cl = args["cl"];
|
---|
210 |
|
---|
211 | if (args["a"] == "q") {
|
---|
212 | // query results
|
---|
213 | if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
|
---|
214 | else if (haschildren == 1) icon = "_document:iconclosedfolder_";
|
---|
215 | link += "&cl=search&d=" + section.OID + "\">";
|
---|
216 |
|
---|
217 | } else if (!arg_d.empty()) {
|
---|
218 | // document level
|
---|
219 | if (is_top(section.OID)) {
|
---|
220 | icon = "_document:iconopenbook_";
|
---|
221 | if (arg_cl == "search") link = "<a href=\"_httpquery_\">";
|
---|
222 | else link += "&cl=" + arg_cl + "\">";
|
---|
223 |
|
---|
224 | } else if (haschildren == 1) {
|
---|
225 | if ((args["gc"] == "1") ||
|
---|
226 | (is_child_of (section.OID, arg_d)) ||
|
---|
227 | (section.OID == arg_d)) {
|
---|
228 | icon = "_document:iconopenfolder_";
|
---|
229 | link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
|
---|
230 | } else {
|
---|
231 | icon = "_document:iconclosedfolder_";
|
---|
232 | link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
233 | }
|
---|
234 | } else {
|
---|
235 | if (args["gt"] == "0") {
|
---|
236 | link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
237 | } else {
|
---|
238 | link += "&cl=" + arg_cl + "&d=" + section.OID + "#" + section.OID + "\">";
|
---|
239 | }
|
---|
240 | }
|
---|
241 |
|
---|
242 | } else {
|
---|
243 | // classification level
|
---|
244 | if (haschildren == 1) {
|
---|
245 | if (doctype == "classify") {
|
---|
246 | if ((args["gc"] == "1") ||
|
---|
247 | (is_child_of (section.OID, arg_cl)) ||
|
---|
248 | (section.OID == arg_cl)) {
|
---|
249 | icon = "_document:iconopenbookshelf_";
|
---|
250 | link += "&cl=" + section.OID + ".pr\">";
|
---|
251 | } else {
|
---|
252 | icon = "_document:iconclosedbookshelf_";
|
---|
253 | link += "&cl=" + section.OID + "\">";
|
---|
254 | }
|
---|
255 | } else {
|
---|
256 | icon = "_document:iconclosedbook_";
|
---|
257 | link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
258 | }
|
---|
259 | } else {
|
---|
260 | if (doctype == "classify") link = "";
|
---|
261 | else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|