source: trunk/gsdl/src/recpt/hlistbrowserclass.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:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/**********************************************************************
2 *
3 * hlistbrowserclass.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 "hlistbrowserclass.h"
27#include <assert.h>
28#include "OIDtools.h"
29
30hlistbrowserclass::hlistbrowserclass () {
31}
32
33hlistbrowserclass::~hlistbrowserclass () {
34}
35
36// returns the name that specifies the browserclass type
37text_t hlistbrowserclass::get_browser_name () {
38 return "HList";
39}
40
41browserclass* hlistbrowserclass::clone()
42{
43 return new hlistbrowserclass();
44}
45
46void hlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
47 metadata.insert ("doctype");
48}
49
50text_t hlistbrowserclass::get_default_formatstring () {
51 return "[link][highlight][Title][/highlight][/link]";
52}
53
54// need to change OID to it's child
55void hlistbrowserclass::processOID (cgiargsclass &args, recptproto *collectproto,
56 ostream &logout) {
57
58 text_t OID = args["d"];
59 bool is_classify = false;
60 if (OID.empty()) {
61 is_classify = true;
62 OID = args["cl"];
63 }
64
65 FilterResponse_t response;
66 text_tset metadata;
67 metadata.insert ("childtype");
68 text_t classifytype = "Invisible";
69 text_tarray OIDs;
70
71 while (classifytype == "Invisible" || classifytype == "HList") {
72 OIDs.erase (OIDs.begin(), OIDs.end());
73
74 OIDs.push_back (OID);
75 OIDs.push_back (OID + ".fc");
76
77 get_info (OIDs, args["c"], args["l"], metadata, false, collectproto, response, logout);
78
79 OID = response.docInfo[1].OID;
80 classifytype = response.docInfo[1].metadata["childtype"].values[0];
81 }
82 if (is_classify) args["cl"] = OID;
83 else args["d"] = OID;
84}
85
86int hlistbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
87 const text_t& collection, int colnumber,
88 format_t *formatlistptr, bool use_table,
89 text_tset &metadata, bool &getParents,
90 recptproto *collectproto, displayclass &disp,
91 outconvertclass &outconvert, ostream &textout,
92 ostream &logout) {
93
94 // expanded contents are going to cause some nasty recursions
95 // so we'll only continue if being passed the current section
96 if ((args["gc"] == 1) && (section.OID != args["d"])) return 0;
97
98 // get all siblings
99 FilterResponse_t response;
100 text_t &arg_cl = args["cl"];
101 get_children (section.OID + ".pr", args["c"], args["l"], metadata, getParents,
102 collectproto, response, logout);
103
104
105 if (use_table || colnumber > 0) {
106 textout << outconvert << "<table><tr><td>";
107 // get tab size
108 text_t tab; int itab;
109 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
110 itab = tab.getint();
111 if (colnumber > 0) textout << outconvert << disp
112 << "<img src=\"_httpimg_/space.gif\" width="
113 << (itab*colnumber) << ">";
114 textout << outconvert << "</td>\n";
115 }
116
117 textout << outconvert << "<table><tr>\n";
118
119 ResultDocInfo_tarray::iterator tsibling = response.docInfo.begin();
120 ResultDocInfo_tarray::iterator esibling = response.docInfo.end();
121
122 text_t icon, link;
123 int num_chars=0; // see note below - jrm21
124 while (tsibling != esibling) {
125
126 bool highlight = false;
127 text_t &doctype = (*tsibling).metadata["doctype"].values[0];
128
129 if ((*tsibling).OID == section.OID) {
130 link.clear();
131 highlight = true;
132 } else {
133 link = "<a href=\"_httpdocument_";
134 if (doctype == "classify")
135 link += "&cl=" + (*tsibling).OID + "\">";
136 else {
137 link += "&cl=" + arg_cl + "&d=" + (*tsibling).OID;// + "\">";
138 // [modification to allow default document detach settings -- kjdon]
139 if (args["xx"]=="1") {
140 // documents should be detached
141 link += "&x=1\" target=\\_blank>";
142 } else {
143 link += "\">";
144 }
145 }
146 }
147
148 text_tmap options;
149 options["link"] = link;
150 options["icon"] = icon;
151 if (highlight) options["highlight"] = "1";
152 else options["highlight"] = "0";
153
154 text_t fmt_str=get_formatted_string (collection, collectproto,
155 *tsibling, disp, formatlistptr,
156 options, logout);
157
158 /* this is awful. Someone please come up with a better way to prevent
159 the table of contents when browsing metadata from becoming too wide.
160 This is an attempt to add new rows when the number of characters in
161 the current row becomes too high. It doesn't know about macros in the
162 string, though... -- jrm21 */
163
164 char *tmp_str=fmt_str.getcstr();
165 char *end_str=tmp_str+strlen(tmp_str);
166 while (tmp_str<end_str) {
167 if (*tmp_str=='<') { // for html tags
168 while (*tmp_str!='>') ++tmp_str;
169 } else if (*tmp_str=='&') { // for html entities
170 while (*tmp_str!=';') ++tmp_str;
171 ++num_chars;
172 } else ++num_chars;
173 ++tmp_str;
174 }
175
176 if (num_chars>100) { // this is fairly arbitrary...
177 textout << outconvert << "</tr>\n<tr>";
178 num_chars=0;
179 }
180
181 textout << outconvert << "<td>" << disp << fmt_str << "</td>\n";
182 ++tsibling;
183 }
184
185 textout << outconvert << "</tr></table>\n";
186 if (use_table || colnumber > 0) textout << outconvert << "</tr></table>\n";
187 return 0;
188}
189
190int hlistbrowserclass::output_section_group (FilterResponse_t &/*sections*/, cgiargsclass &/*args*/,
191 const text_t &/*collection*/, int /*colnumber*/,
192 format_t * /*formatlistptr*/, bool /*use_table*/,
193 text_tset &/*metadata*/, bool &/*getParents*/,
194 recptproto * /*collectproto*/, displayclass &/*disp*/,
195 outconvertclass &/*outconvert*/, ostream &/*textout*/,
196 ostream &/*logout*/) {
197 return 0;
198}
Note: See TracBrowser for help on using the repository browser.