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