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 "OIDtools.h"
|
---|
28 | #include "recptprototools.h"
|
---|
29 | #include "cgiutils.h"
|
---|
30 |
|
---|
31 |
|
---|
32 | hlistbrowserclass::hlistbrowserclass () {
|
---|
33 | }
|
---|
34 |
|
---|
35 | hlistbrowserclass::~hlistbrowserclass () {
|
---|
36 | }
|
---|
37 |
|
---|
38 | // returns the name that specifies the browserclass type
|
---|
39 | text_t hlistbrowserclass::get_browser_name () {
|
---|
40 | return "HList";
|
---|
41 | }
|
---|
42 |
|
---|
43 | browserclass* hlistbrowserclass::clone()
|
---|
44 | {
|
---|
45 | return new hlistbrowserclass();
|
---|
46 | }
|
---|
47 |
|
---|
48 | void hlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
|
---|
49 | metadata.insert ("doctype");
|
---|
50 | }
|
---|
51 |
|
---|
52 | text_t hlistbrowserclass::get_default_formatstring () {
|
---|
53 | return "[link][highlight][Title][/highlight][/link]";
|
---|
54 | }
|
---|
55 |
|
---|
56 | // need to change OID to it's child
|
---|
57 | void hlistbrowserclass::processOID (cgiargsclass &args, recptproto *collectproto,
|
---|
58 | ostream &logout) {
|
---|
59 |
|
---|
60 | text_t OID = args["d"];
|
---|
61 | bool is_classify = false;
|
---|
62 | if (OID.empty()) {
|
---|
63 | is_classify = true;
|
---|
64 | OID = args["cl"];
|
---|
65 | }
|
---|
66 |
|
---|
67 | FilterResponse_t response;
|
---|
68 | text_tset metadata;
|
---|
69 | metadata.insert ("childtype");
|
---|
70 | text_t classifytype = "Invisible";
|
---|
71 | text_tarray OIDs;
|
---|
72 |
|
---|
73 | while (classifytype == "Invisible" || classifytype == "HList") {
|
---|
74 | OIDs.erase (OIDs.begin(), OIDs.end());
|
---|
75 |
|
---|
76 | OIDs.push_back (OID);
|
---|
77 | OIDs.push_back (OID + ".fc");
|
---|
78 |
|
---|
79 | get_info (OIDs, args["c"], args["l"], metadata, false, collectproto, response, logout);
|
---|
80 |
|
---|
81 | // Avoid infinite loops in strange situations by checking that the OID has changed
|
---|
82 | if (response.docInfo[1].OID == OID) {
|
---|
83 | break;
|
---|
84 | }
|
---|
85 | OID = response.docInfo[1].OID;
|
---|
86 | classifytype = response.docInfo[1].metadata["childtype"].values[0];
|
---|
87 | }
|
---|
88 | if (is_classify) args["cl"] = OID;
|
---|
89 | else args["d"] = OID;
|
---|
90 | }
|
---|
91 |
|
---|
92 | int hlistbrowserclass::output_section_group (ResultDocInfo_t §ion, 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 | // expanded contents are going to cause some nasty recursions
|
---|
101 | // so we'll only continue if being passed the current section
|
---|
102 | if ((args["gc"] == 1) && (section.OID != args["d"])) return 0;
|
---|
103 |
|
---|
104 | // get all siblings
|
---|
105 | FilterResponse_t response;
|
---|
106 | get_children (section.OID + ".pr", args["c"], args["l"], metadata, getParents,
|
---|
107 | collectproto, response, logout);
|
---|
108 |
|
---|
109 | return output_section_group (response, args, collection, colnumber, formatlistptr, use_table, metadata, getParents, collectproto, disp, outconvert, textout, logout);
|
---|
110 | }
|
---|
111 |
|
---|
112 | int hlistbrowserclass::output_section_group (FilterResponse_t &response, cgiargsclass &args,
|
---|
113 | const text_t &collection, int colnumber,
|
---|
114 | format_t * formatlistptr, bool use_table,
|
---|
115 | text_tset &metadata, bool &getParents,
|
---|
116 | recptproto * collectproto, displayclass &disp,
|
---|
117 | outconvertclass &outconvert, ostream &textout,
|
---|
118 | ostream &logout)
|
---|
119 | {
|
---|
120 | /* use_table is set to true if the format string starts with <td> */
|
---|
121 | if (use_table || colnumber > 0) {
|
---|
122 | textout << outconvert << "<table><tr><td>";
|
---|
123 | // get tab size
|
---|
124 | text_t tab; int itab;
|
---|
125 | disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
|
---|
126 | itab = tab.getint();
|
---|
127 | if (colnumber > 0) textout << outconvert << disp
|
---|
128 | << "<img alt=\"\" src=\"_httpiconspace_\" width=\""
|
---|
129 | << (itab*colnumber) << "\"/>";
|
---|
130 | textout << outconvert << "</td>\n";
|
---|
131 | }
|
---|
132 |
|
---|
133 | if (use_table)
|
---|
134 | textout << outconvert << "<table class=\"h_list\"><tr>\n";
|
---|
135 | else
|
---|
136 | textout << outconvert << "<div class=\"h_list\">\n";
|
---|
137 |
|
---|
138 | ResultDocInfo_tarray::iterator tsibling = response.docInfo.begin();
|
---|
139 | ResultDocInfo_tarray::iterator esibling = response.docInfo.end();
|
---|
140 |
|
---|
141 | text_t icon, link;
|
---|
142 |
|
---|
143 | while (tsibling != esibling)
|
---|
144 | {
|
---|
145 | get_link_icon (*tsibling, args, link, icon);
|
---|
146 |
|
---|
147 | bool highlight = false;
|
---|
148 | if ((*tsibling).OID == args["cl"] || is_child_of ((*tsibling).OID, args["cl"]) ||
|
---|
149 | (*tsibling).OID == args["dcn"] || starts_with (args["dcn"], (*tsibling).OID))
|
---|
150 | {
|
---|
151 | link.clear();
|
---|
152 | highlight = true;
|
---|
153 | }
|
---|
154 |
|
---|
155 | text_tmap options;
|
---|
156 | options["link"] = link;
|
---|
157 | options["icon"] = icon;
|
---|
158 | if (highlight) options["highlight"] = "1";
|
---|
159 | else options["highlight"] = "0";
|
---|
160 |
|
---|
161 | text_t fmt_str=get_formatted_string (collection, collectproto,
|
---|
162 | *tsibling, disp, formatlistptr,
|
---|
163 | options, logout);
|
---|
164 |
|
---|
165 | text_t span_class = "h_item";
|
---|
166 | if (highlight) {
|
---|
167 | // the current option
|
---|
168 | span_class += " h_item_current";
|
---|
169 | }
|
---|
170 |
|
---|
171 | textout << outconvert << "<span class=\""<<span_class<<"\">" << disp << fmt_str << "</span>\n";
|
---|
172 | ++tsibling;
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (use_table)
|
---|
176 | textout << outconvert << "</tr></table>\n";
|
---|
177 | else
|
---|
178 | textout << outconvert << "</div>\n";
|
---|
179 |
|
---|
180 | if (use_table || colnumber > 0) textout << outconvert << "</tr></table>\n";
|
---|
181 |
|
---|
182 | return 0;
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | void hlistbrowserclass::get_link_icon (ResultDocInfo_t §ion, cgiargsclass &args, text_t &link, text_t &icon)
|
---|
187 | {
|
---|
188 | link = "<a href=\"_httpdocument_";
|
---|
189 |
|
---|
190 | text_t &doctype = section.metadata["doctype"].values[0];
|
---|
191 | if (doctype == "classify")
|
---|
192 | {
|
---|
193 | // Dynamic classifier nodes
|
---|
194 | if (args["a"] == "dc")
|
---|
195 | {
|
---|
196 | // The node label is going into the URL, so make it CGI-safe
|
---|
197 | text_t classifier_node_dcn_cgi_safe = cgi_safe_utf8(section.OID);
|
---|
198 | link = "<a href=\"_gwcgi_?c=" + args["c"] + "&a=dc&dcl=" + args["dcl"] + "&dcn=" + classifier_node_dcn_cgi_safe + "\">";
|
---|
199 | }
|
---|
200 | // Static classifier nodes
|
---|
201 | else
|
---|
202 | {
|
---|
203 | link += "&cl=" + section.OID + "\">";
|
---|
204 | }
|
---|
205 | }
|
---|
206 | else
|
---|
207 | {
|
---|
208 | link += "&cl=" + args["cl"] + "&d=" + section.OID;
|
---|
209 |
|
---|
210 | // [modification to allow default document detach settings -- kjdon]
|
---|
211 | if (args["xx"] == "1")
|
---|
212 | {
|
---|
213 | // documents should be detached
|
---|
214 | link += "&x=1\" target=\"_blank\">";
|
---|
215 | }
|
---|
216 | else
|
---|
217 | {
|
---|
218 | link += "\">";
|
---|
219 | }
|
---|
220 | }
|
---|
221 | }
|
---|