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

Last change on this file since 1861 was 1559, checked in by nzdl, 24 years ago

made OIDs for arrow links dm safe

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