source: trunk/gsdl/src/recpt/pagedbrowserclass.cpp@ 10988

Last change on this file since 10988 was 10988, checked in by mdewsnip, 18 years ago

Fixed a bug where entering an invalid "gp" value with a top-level "d" value would go to a bad page. Also removed the restriction that the "gp" value has to be numeric, since I have "i", "ii", "iii", "iv" etc. Title values.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/**********************************************************************
2 *
3 * pagedbrowserclass.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 "gsdl_modules_cfg.h"
27#ifdef GSDL_USE_PAGED_BROWSER
28
29#include "pagedbrowserclass.h"
30#include <assert.h>
31#include "OIDtools.h"
32#include "gsdltools.h"
33
34pagedbrowserclass::pagedbrowserclass () {
35}
36
37pagedbrowserclass::~pagedbrowserclass () {
38}
39
40// returns the name that specifies the browserclass type
41text_t pagedbrowserclass::get_browser_name () {
42 return "Paged";
43}
44
45browserclass* pagedbrowserclass::clone()
46{
47 return new pagedbrowserclass();
48}
49
50void pagedbrowserclass::load_metadata_defaults (text_tset &metadata) {
51 metadata.insert ("Title");
52}
53
54// if the "gp" (go to page) argument is set we need to set
55// the "d" argument to the corresponding page
56// also want to set "d" argument to first child if we're at
57// an 'Invisible' top level
58void pagedbrowserclass::processOID (cgiargsclass &args, recptproto *collectproto,
59 ostream &logout) {
60
61 text_t &arg_d = args["d"];
62 text_t &arg_gp = args["gp"];
63 text_tset metadata;
64 bool getParents = false;
65 FilterResponse_t response;
66
67 if (!arg_d.empty() && !arg_gp.empty()) {
68 text_t top;
69 get_top (arg_d, top);
70 metadata.insert ("Title");
71 get_children (top, args["c"], args["l"], metadata, getParents, collectproto, response, logout);
72 ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
73 ResultDocInfo_tarray::iterator docend = response.docInfo.end();
74 while (dochere != docend) {
75 if ((*dochere).metadata["Title"].values[0] == arg_gp) {
76 arg_d = (*dochere).OID;
77 return;
78 }
79 ++dochere;
80 }
81 }
82
83 // The "gp" argument was either empty or invalid, so display the first child if given a document OID
84 if (!arg_d.empty() && is_top(arg_d)) { // if top level doc, check if not invisible
85 metadata.insert("thistype");
86 if (get_info(arg_d, args["c"], args["l"], metadata, getParents, collectproto, response, logout)) {
87 text_t type = response.docInfo[0].metadata["thistype"].values[0];
88 if (type=="Invisible") { // display first child
89 arg_d = arg_d + ".fc";
90 }
91 }
92 }
93}
94
95int pagedbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
96 const text_t &/*collection*/, int /*colnumber*/,
97 format_t * /*formatlistptr*/, bool /*use_table*/,
98 text_tset &/*metadata*/, bool &/*getParents*/,
99 recptproto * /*collectproto*/, displayclass &disp,
100 outconvertclass &outconvert, ostream &textout,
101 ostream &/*logout*/) {
102
103 // this browser class only handles document levels
104 if (args["d"].empty()) return 0;
105
106 if (section.OID != args["d"]) {
107 text_t httpprevarrow = "_httpdocument_&cl=" + args["cl"] + "&d=" + dm_safe(section.OID);
108 text_t parentarrow = "<a href=\"" + httpprevarrow + "\">_iconprev_</a>\n";
109 disp.setmacro ("httpprevarrow", "document", httpprevarrow);
110 disp.setmacro ("parentarrow", "document", parentarrow);
111 return 0;
112 }
113
114 // must be at top level to get to here!
115 textout << outconvert << disp << "<b>" << section.metadata["Title"].values[0]
116 << "_document:textintro_</b>\n";
117
118 return 0;
119}
120
121int pagedbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
122 const text_t &/*collection*/, int /*colnumber*/,
123 format_t * /*formatlistptr*/, bool /*use_table*/,
124 text_tset &/*metadata*/, bool &/*getParents*/,
125 recptproto * /*collectproto*/, displayclass &disp,
126 outconvertclass &outconvert, ostream &textout,
127 ostream &/*logout*/) {
128
129 text_t &arg_d = args["d"];
130
131 // this browser class only handles document levels
132 if (arg_d.empty()) return 0;
133
134 text_t previousOID, previoustitle, nextOID, nexttitle;
135 text_t prevarrow, nextarrow, httpprevarrow, httpnextarrow;
136 bool found = false;
137
138 // this should be our list of pages
139
140 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
141 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
142
143 while (thissection != endsection) {
144 if (arg_d == (*thissection).OID) {
145 found = true;
146 textout << outconvert << disp
147 << "<table><tr valign=top><td colspan=3><center><b>_page_"
148 << (*thissection).metadata["Title"].values[0] << "</b>\n";
149 if (thissection != sections.docInfo.begin()) {
150 previousOID = (*(thissection-1)).OID;
151 previoustitle = (*(thissection-1)).metadata["Title"].values[0];
152 } else {
153 prevarrow = "_document:parentarrow_";
154 }
155
156 if ((thissection+1) != endsection) {
157 nextOID = (*(thissection+1)).OID;
158 nexttitle = (*(thissection+1)).metadata["Title"].values[0];
159 }
160 break;
161 }
162 ++thissection;
163 }
164
165 if (!found) {
166 textout << outconvert << disp
167 << "<table><tr valign=top> <td colspan=3><center>\n";
168 }
169 int numpages = sections.docInfo.size();
170 textout << outconvert << disp
171 << ("_document:textnumpages_(" + text_t(numpages) + ")</center></td></tr>\n");
172
173 disp.setmacro ("numpages", "document", numpages);
174
175 if (!found) {
176 httpnextarrow = "_httpdocument_&cl=" + args["cl"] + "&d=" + sections.docInfo[0].OID;
177 nextarrow = "<a href=\"" + httpnextarrow + "\">" +
178 sections.docInfo[0].metadata["Title"].values[0] + "_iconnext_</a>\n";
179
180 } else {
181 if (!previousOID.empty()) {
182 httpprevarrow = "_httpdocument_&cl=" + args["cl"] + "&d=" + dm_safe(previousOID);
183 prevarrow = "<a href=\"" + httpprevarrow + "\">_iconprev_" + previoustitle + "</a>\n";
184 }
185 if (!nextOID.empty()) {
186 httpnextarrow = "_httpdocument_&cl=" + args["cl"] + "&d=" + dm_safe(nextOID);
187 nextarrow = "<a href=\"" + httpnextarrow + "\">" + nexttitle + "_iconnext_</a>\n";
188 }
189 }
190
191 if (!httpprevarrow.empty()) disp.setmacro ("httpprevarrow", "document", httpprevarrow);
192 if (!httpnextarrow.empty()) disp.setmacro ("httpnextarrow", "document", httpnextarrow);
193
194 if (!prevarrow.empty()) disp.setmacro ("prevarrow", "document", prevarrow);
195 if (!nextarrow.empty()) disp.setmacro ("nextarrow", "document", nextarrow);
196
197
198 textout << outconvert << disp << "<tr valign=middle>\n"
199 << "<td align=right>" << prevarrow << "</td>\n"
200 << "<td align=center valign=top>_document:gotoform_</td>"
201 << "<td align=left>" << nextarrow << "</td>\n"
202 << "</tr></table>\n";
203
204 return 0;
205}
206
207#endif //GSDL_USE_PAGED_BROWSER
Note: See TracBrowser for help on using the repository browser.