[649] | 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 | * $Id: vlistbrowserclass.cpp 934 2000-02-17 02:33:09Z sjboddie $
|
---|
| 25 | *
|
---|
| 26 | *********************************************************************/
|
---|
| 27 |
|
---|
| 28 | /*
|
---|
| 29 | $Log$
|
---|
[934] | 30 | Revision 1.7 2000/02/17 02:33:09 sjboddie
|
---|
| 31 | minor tidy up - made some function definitions virtual
|
---|
| 32 |
|
---|
[824] | 33 | Revision 1.6 1999/12/13 02:44:23 davidb
|
---|
| 34 | Better protection when accessing "haschildren"
|
---|
| 35 |
|
---|
[752] | 36 | Revision 1.5 1999/10/30 23:01:24 sjboddie
|
---|
| 37 | tidied things up slightly
|
---|
| 38 |
|
---|
[747] | 39 | Revision 1.4 1999/10/30 22:14:44 sjboddie
|
---|
| 40 | added a collection argument
|
---|
| 41 |
|
---|
[727] | 42 | Revision 1.3 1999/10/19 08:40:13 sjboddie
|
---|
| 43 | fixed some stupid compiler warnings on windows
|
---|
| 44 |
|
---|
[668] | 45 | Revision 1.2 1999/10/14 22:59:34 sjboddie
|
---|
| 46 | finished off browser classes
|
---|
| 47 |
|
---|
[649] | 48 | Revision 1.1 1999/10/10 08:14:11 sjboddie
|
---|
| 49 | - metadata now returns mp rather than array
|
---|
| 50 | - redesigned browsing support (although it's not finished so
|
---|
| 51 | won't currently work ;-)
|
---|
| 52 |
|
---|
| 53 | */
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | #include "vlistbrowserclass.h"
|
---|
| 57 | #include <assert.h>
|
---|
| 58 | #include "OIDtools.h"
|
---|
| 59 |
|
---|
| 60 | vlistbrowserclass::vlistbrowserclass () {
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | vlistbrowserclass::~vlistbrowserclass () {
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | // returns the name that specifies the browserclass type
|
---|
| 67 | text_t vlistbrowserclass::get_browser_name () {
|
---|
| 68 | return "VList";
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
|
---|
| 72 | metadata.insert ("haschildren");
|
---|
| 73 | metadata.insert ("doctype");
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[668] | 76 | text_t vlistbrowserclass::get_default_formatstring () {
|
---|
| 77 | return "<td>[link][icon][/link]</td><td>[highlight]{Or}{[Title],Untitled}[/highlight]</td>";
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[649] | 80 | int vlistbrowserclass::output_section_group (ResultDocInfo_t §ion, cgiargsclass &args,
|
---|
[752] | 81 | const text_t &collection, int colnumber,
|
---|
| 82 | format_t *formatlistptr, bool use_table,
|
---|
| 83 | text_tset &/*metadata*/, bool &/*getParents*/,
|
---|
[727] | 84 | recptproto * /*collectproto*/, displayclass &disp,
|
---|
[752] | 85 | outconvertclass &outconvert, ostream &textout,
|
---|
| 86 | ostream &/*logout*/) {
|
---|
[649] | 87 |
|
---|
| 88 | text_t link, icon;
|
---|
[747] | 89 |
|
---|
| 90 | text_t collink = collection;
|
---|
| 91 | if (!collink.empty()) collink = "&c=" + collink;
|
---|
| 92 |
|
---|
| 93 | get_link_icon (section, args, collink, link, icon);
|
---|
[668] | 94 | bool highlight = false;
|
---|
| 95 | if (!args["d"].empty()) {
|
---|
| 96 | if (args["d"] == section.OID) highlight = true;
|
---|
| 97 | } else
|
---|
| 98 | if (args["cl"] == section.OID) highlight = true;
|
---|
[649] | 99 |
|
---|
[668] | 100 |
|
---|
| 101 | if (use_table || colnumber > 0) {
|
---|
| 102 | textout << "<table><tr>";
|
---|
| 103 | // get tab size
|
---|
| 104 | text_t tab; int itab;
|
---|
| 105 | disp.expandstring ("Global", "_tabwidth_", tab);
|
---|
| 106 | itab = tab.getint();
|
---|
| 107 | if (colnumber > 0) textout << outconvert << disp
|
---|
| 108 | << "<td><img src=\"_httpimg_/space.gif\" width="
|
---|
| 109 | << (itab*colnumber) << "></td>";
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | textout << outconvert << disp << get_formatted_string (section, formatlistptr,
|
---|
| 113 | link, icon, highlight);
|
---|
[649] | 114 |
|
---|
[668] | 115 | if (use_table || colnumber > 0) textout << "</tr></table>\n";
|
---|
| 116 |
|
---|
[649] | 117 | return 1;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[668] | 120 | int vlistbrowserclass::output_section_group (FilterResponse_t §ions, cgiargsclass &args,
|
---|
[752] | 121 | const text_t &collection, int colnumber,
|
---|
| 122 | format_t *formatlistptr, bool use_table,
|
---|
| 123 | text_tset &/*metadata*/, bool &/*getParents*/,
|
---|
[727] | 124 | recptproto * /*collectproto*/, displayclass &disp,
|
---|
[752] | 125 | outconvertclass &outconvert, ostream &textout,
|
---|
| 126 | ostream &/*logout*/) {
|
---|
[668] | 127 |
|
---|
| 128 | text_t link, icon;
|
---|
| 129 | text_t &arg_d = args["d"];
|
---|
| 130 | text_t &arg_cl = args["cl"];
|
---|
| 131 |
|
---|
[747] | 132 | text_t collink = collection;
|
---|
| 133 | if (!collink.empty()) collink = "&c=" + collink;
|
---|
| 134 |
|
---|
[668] | 135 | if (colnumber > 0) {
|
---|
| 136 | textout << "<table><tr>";
|
---|
[649] | 137 | // get tab size
|
---|
| 138 | text_t tab; int itab;
|
---|
| 139 | disp.expandstring ("Global", "_tabwidth_", tab);
|
---|
| 140 | itab = tab.getint();
|
---|
| 141 | if (colnumber > 0) textout << outconvert << disp
|
---|
[668] | 142 | << "<td><img src=\"_httpimg_/space.gif\" width="
|
---|
| 143 | << (itab*colnumber) << "></td>";
|
---|
| 144 | textout << "<td>";
|
---|
[649] | 145 | }
|
---|
[668] | 146 | if (use_table) textout << "<table>\n";
|
---|
[649] | 147 |
|
---|
[668] | 148 | ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
|
---|
| 149 | ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
|
---|
[649] | 150 |
|
---|
[668] | 151 | while (thissection != endsection) {
|
---|
| 152 |
|
---|
[747] | 153 | get_link_icon (*thissection, args, collink, link, icon);
|
---|
[668] | 154 | bool highlight = false;
|
---|
| 155 | if (!arg_d.empty()) {
|
---|
| 156 | if (arg_d == (*thissection).OID) highlight = true;
|
---|
| 157 | } else
|
---|
| 158 | if (arg_cl == (*thissection).OID) highlight = true;
|
---|
| 159 |
|
---|
| 160 | if (use_table || colnumber > 0) textout << "<tr>";
|
---|
| 161 | textout << outconvert << disp << get_formatted_string (*thissection, formatlistptr,
|
---|
| 162 | link, icon, highlight);
|
---|
| 163 | if (use_table || colnumber > 0) textout << "</tr>";
|
---|
| 164 | textout << "\n";
|
---|
| 165 | thissection ++;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | if (use_table) textout << "</table>\n";
|
---|
| 169 | if (colnumber > 0) textout << "</table></td></tr></table>\n";
|
---|
| 170 |
|
---|
| 171 | return 1;
|
---|
[649] | 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | // get_link_icon attempts to work out what type of icon should be displayed for
|
---|
| 176 | // the given section and what it should link to.
|
---|
| 177 | void vlistbrowserclass::get_link_icon (ResultDocInfo_t §ion, cgiargsclass &args,
|
---|
[747] | 178 | const text_t &collink, text_t &link, text_t &icon) {
|
---|
[649] | 179 |
|
---|
[747] | 180 | link = "<a href=\"_httpdocument_" + collink;
|
---|
[649] | 181 | icon = "_document:icontext_";
|
---|
[824] | 182 | int haschildren = 0;
|
---|
[649] | 183 |
|
---|
[824] | 184 | if (section.metadata.count("haschildren")>0)
|
---|
[934] | 185 | haschildren = section.metadata["haschildren"].values[0].getint();
|
---|
[824] | 186 |
|
---|
[934] | 187 | text_t doctype;
|
---|
[824] | 188 | if (section.metadata.count("doctype")>0)
|
---|
[934] | 189 | doctype = section.metadata["doctype"].values[0];
|
---|
[824] | 190 |
|
---|
[668] | 191 | text_t &arg_d = args["d"];
|
---|
| 192 | text_t &arg_cl = args["cl"];
|
---|
| 193 |
|
---|
[649] | 194 | if (args["a"] == "q") {
|
---|
| 195 | // query results
|
---|
| 196 | if (is_top (section.OID)) icon = "_document:iconclosedbook_";
|
---|
| 197 | else if (haschildren == 1) icon = "_document:iconclosedfolder_";
|
---|
| 198 | link += "&cl=search&d=" + section.OID + "\">";
|
---|
| 199 |
|
---|
[668] | 200 | } else if (!arg_d.empty()) {
|
---|
[649] | 201 | // document level
|
---|
| 202 | if (is_top(section.OID)) {
|
---|
| 203 | icon = "_document:iconopenbook_";
|
---|
[668] | 204 | if (arg_cl == "search") link = "<a href=\"_httpquery_\">";
|
---|
| 205 | else link += "&cl=" + arg_cl + "\">";
|
---|
[649] | 206 |
|
---|
| 207 | } else if (haschildren == 1) {
|
---|
[668] | 208 | if ((args["gc"] == "1") ||
|
---|
| 209 | (is_child_of (section.OID, arg_d)) ||
|
---|
| 210 | (section.OID == arg_d)) {
|
---|
[649] | 211 | icon = "_document:iconopenfolder_";
|
---|
[668] | 212 | link += "&cl=" + arg_cl + "&d=" + section.OID + ".pr\">";
|
---|
[649] | 213 | } else {
|
---|
| 214 | icon = "_document:iconclosedfolder_";
|
---|
[668] | 215 | link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
[649] | 216 | }
|
---|
[668] | 217 | } else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
[649] | 218 |
|
---|
| 219 | } else {
|
---|
| 220 | // classification level
|
---|
| 221 | if (haschildren == 1) {
|
---|
| 222 | if (doctype == "classify") {
|
---|
[668] | 223 | if ((args["gc"] == "1") ||
|
---|
| 224 | (is_child_of (section.OID, arg_cl)) ||
|
---|
| 225 | (section.OID == arg_cl)) {
|
---|
[649] | 226 | icon = "_document:iconopenbookshelf_";
|
---|
| 227 | link += "&cl=" + section.OID + ".pr\">";
|
---|
| 228 | } else {
|
---|
| 229 | icon = "_document:iconclosedbookshelf_";
|
---|
| 230 | link += "&cl=" + section.OID + "\">";
|
---|
| 231 | }
|
---|
| 232 | } else {
|
---|
| 233 | icon = "_document:iconclosedbook_";
|
---|
[668] | 234 | link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
[649] | 235 | }
|
---|
| 236 | } else {
|
---|
| 237 | if (doctype == "classify") link = "";
|
---|
[668] | 238 | else link += "&cl=" + arg_cl + "&d=" + section.OID + "\">";
|
---|
[649] | 239 | }
|
---|
| 240 | }
|
---|
| 241 | }
|
---|