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 |
|
---|
30 | vlistbrowserclass::vlistbrowserclass () {
|
---|
31 | }
|
---|
32 |
|
---|
33 | vlistbrowserclass::~vlistbrowserclass () {
|
---|
34 | }
|
---|
35 |
|
---|
36 | // returns the name that specifies the browserclass type
|
---|
37 | text_t vlistbrowserclass::get_browser_name () {
|
---|
38 | return "VList";
|
---|
39 | }
|
---|
40 |
|
---|
41 | void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
|
---|
42 | metadata.insert ("haschildren");
|
---|
43 | metadata.insert ("doctype");
|
---|
44 | }
|
---|
45 |
|
---|
46 | text_t vlistbrowserclass::get_default_formatstring () {
|
---|
47 | return "<td>[link][icon][/link]</td><td>[highlight]{Or}{[Title],Untitled}[/highlight]</td>";
|
---|
48 | }
|
---|
49 |
|
---|
50 | int vlistbrowserclass::output_section_group (ResultDocInfo_t §ion, cgiargsclass &args,
|
---|
51 | const text_t &collection, int colnumber,
|
---|
52 | format_t *formatlistptr, bool use_table,
|
---|
53 | text_tset &/*metadata*/, bool &/*getParents*/,
|
---|
54 | recptproto * collectproto, displayclass &disp,
|
---|
55 | outconvertclass &outconvert, ostream &textout,
|
---|
56 | ostream& logout) {
|
---|
57 |
|
---|
58 | text_t link, icon;
|
---|
59 |
|
---|
60 | text_t collink = collection;
|
---|
61 | if (!collink.empty()) collink = "&c=" + collink;
|
---|
62 |
|
---|
63 | get_link_icon (section, args, collink, link, icon);
|
---|
64 | bool highlight = false;
|
---|
65 | if (!args["d"].empty()) {
|
---|
66 | if (args["d"] == section.OID) highlight = true;
|
---|
67 | } else
|
---|
68 | if (args["cl"] == section.OID) highlight = true;
|
---|
69 |
|
---|
70 |
|
---|
71 | if (use_table || colnumber > 0) {
|
---|
72 | textout << "<table><tr valign=top>";
|
---|
73 | // get tab size
|
---|
74 | text_t tab; int itab;
|
---|
75 | disp.expandstring ("Global", "_tabwidth_", tab);
|
---|
76 | itab = tab.getint();
|
---|
77 | if (colnumber > 0) textout << outconvert << disp
|
---|
78 | << "<td><img src=\"_httpimg_/space.gif\" width="
|
---|
79 | << (itab*colnumber) << "></td>";
|
---|
80 | }
|
---|
81 |
|
---|
82 | textout << outconvert << disp
|
---|
83 | << get_formatted_string (collection, collectproto,
|
---|
84 | section, disp, formatlistptr,
|
---|
85 | link, icon, highlight, logout);
|
---|
86 |
|
---|
87 | if (use_table || colnumber > 0) textout << "</tr></table>\n";
|
---|
88 |
|
---|
89 | return 1;
|
---|
90 | }
|
---|
91 |
|
---|
92 | int vlistbrowserclass::output_section_group (FilterResponse_t §ions, cgiargsclass &args,
|
---|
93 | const text_t &collection, int colnumber,
|
---|
94 | format_t *formatlistptr, bool use_table,
|
---|
95 | text_tset &/*metadata*/, bool &/*getParents*/,
|
---|
96 | recptproto * collectproto, displayclass &disp,
|
---|
97 | outconvertclass &outconvert, ostream &textout,
|
---|
98 | ostream& logout) {
|
---|
99 |
|
---|
100 | text_t link, icon;
|
---|
101 | text_t &arg_d = args["d"];
|
---|
102 | text_t &arg_cl = args["cl"];
|
---|
103 |
|
---|
104 | text_t collink = collection;
|
---|
105 | if (!collink.empty()) collink = "&c=" + collink;
|
---|
106 |
|
---|
107 | if (colnumber > 0) {
|
---|
108 | textout << "<table><tr valign=top>";
|
---|
109 | // get tab size
|
---|
110 | text_t tab; int itab;
|
---|
111 | disp.expandstring ("Global", "_tabwidth_", tab);
|
---|
112 | itab = tab.getint();
|
---|
113 | if (colnumber > 0) textout << outconvert << disp
|
---|
114 | << "<td><img src=\"_httpimg_/space.gif\" width="
|
---|
115 | << (itab*colnumber) << "></td>";
|
---|
116 | textout << "<td>";
|
---|
117 | }
|
---|
118 | if (use_table) textout << "<table>\n";
|
---|
119 |
|
---|
120 | ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
|
---|
121 | ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
|
---|
122 |
|
---|
123 | while (thissection != endsection) {
|
---|
124 |
|
---|
125 | get_link_icon (*thissection, args, collink, link, icon);
|
---|
126 | bool highlight = false;
|
---|
127 | if (!arg_d.empty()) {
|
---|
128 | if (arg_d == (*thissection).OID) highlight = true;
|
---|
129 | } else
|
---|
130 | if (arg_cl == (*thissection).OID) highlight = true;
|
---|
131 |
|
---|
132 | if (use_table || colnumber > 0) textout << "<tr valign=top>";
|
---|
133 | textout << outconvert << disp
|
---|
134 | << get_formatted_string (collection, collectproto,
|
---|
135 | *thissection, disp, formatlistptr,
|
---|
136 | link, icon, highlight, logout);
|
---|
137 |
|
---|
138 | if (use_table || colnumber > 0) textout << "</tr>";
|
---|
139 | textout << "\n";
|
---|
140 | thissection ++;
|
---|
141 | }
|
---|
142 |
|
---|
143 | if (use_table) textout << "</table>\n";
|
---|
144 | if (colnumber > 0) textout << "</table></td></tr></table>\n";
|
---|
145 |
|
---|
146 | return 1;
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | // get_link_icon attempts to work out what type of icon should be displayed for
|
---|
151 | // the given section and what it should link to.
|
---|
152 | void vlistbrowserclass::get_link_icon (ResultDocInfo_t §ion, cgiargsclass &args,
|
---|
153 | const text_t &collink, text_t &link, text_t &icon) {
|
---|
154 |
|
---|
155 | link = "<a href=\"_httpdocument_" + collink;
|
---|
156 | icon = "_document:icontext_";
|
---|
157 | int haschildren = 0;
|
---|
158 |
|
---|
159 | if (section.metadata.count("haschildren")>0)
|
---|
160 | haschildren = section.metadata["haschildren"].values[0].getint();
|
---|
161 |
|
---|
162 | text_t doctype;
|
---|
163 | if (section.metadata.count("doctype")>0)
|
---|
164 | doctype = section.metadata["doctype"].values[0];
|
---|
165 |
|
---|
166 | text_t &arg_d = args["d"];
|
---|
167 | text_t &arg_cl = args["cl"];
|
---|
168 |
|
---|
169 | if (args["a"] == "q") {
|
---|
170 | // query results
|
---|
171 | if (is_top (section.OID)) icon = "_document:iconclosedbook_";
|
---|
172 | else if (haschildren == 1) icon = "_document:iconclosedfolder_";
|
---|
173 | link += "&cl=search&d=" + section.OID + "\">";
|
---|
174 |
|
---|
175 | } else if (!arg_d.empty()) {
|
---|
176 | // document level
|
---|
177 | if (is_top(section.OID)) {
|
---|
178 | icon = "_document:iconopenbook_";
|
---|
179 | if (arg_cl == "search") link = "<a href=\"_httpquery_\">";
|
---|
180 | else link += "&cl=" + arg_cl + "\">";
|
---|
181 |
|
---|
182 | } else if (haschildren == 1) {
|
---|
183 | if ((args["gc"] == "1") ||
|
---|
184 | (is_child_of (section.OID, arg_d)) ||
|
---|
185 | (section.OID == arg_d)) {
|
---|
186 | icon = "_document:iconopenfolder_";
|
---|
187 | link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
|
---|
188 | } else {
|
---|
189 | icon = "_document:iconclosedfolder_";
|
---|
190 | link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
191 | }
|
---|
192 | } else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
193 |
|
---|
194 | } else {
|
---|
195 | // classification level
|
---|
196 | if (haschildren == 1) {
|
---|
197 | if (doctype == "classify") {
|
---|
198 | if ((args["gc"] == "1") ||
|
---|
199 | (is_child_of (section.OID, arg_cl)) ||
|
---|
200 | (section.OID == arg_cl)) {
|
---|
201 | icon = "_document:iconopenbookshelf_";
|
---|
202 | link += "&cl=" + section.OID + ".pr\">";
|
---|
203 | } else {
|
---|
204 | icon = "_document:iconclosedbookshelf_";
|
---|
205 | link += "&cl=" + section.OID + "\">";
|
---|
206 | }
|
---|
207 | } else {
|
---|
208 | icon = "_document:iconclosedbook_";
|
---|
209 | link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
210 | }
|
---|
211 | } else {
|
---|
212 | if (doctype == "classify") link = "";
|
---|
213 | else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
214 | }
|
---|
215 | }
|
---|
216 | }
|
---|