source: main/trunk/greenstone2/runtime-src/src/recpt/pagedbrowserclass.cpp@ 28760

Last change on this file since 28760 was 19047, checked in by davidb, 15 years ago

Additional macros set to assist in more advanced use of a PageImageDoc's table of contents and goto-form

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