source: main/trunk/greenstone2/runtime-src/src/recpt/datelistbrowserclass.cpp@ 24874

Last change on this file since 24874 was 24810, checked in by ak19, 12 years ago

Dr Bainbridge fixed the Datelist Browsing Classifier: previously, if the format features for Datelist were set to contain the srclink, this wasn't being resolved to the full path. But it did work for the default VListBrowsingClassifier. Turns out that the GS2 runtime code was replacing assocfilepath metadata with a fuller path for the VListBrowsingClassifer. This has now been added into the Datelist classifer too.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/**********************************************************************
2 *
3 * datelistbrowserclass.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_DATELIST_BROWSER
28
29#include "browsetoolsclass.h"
30#include "datelistbrowserclass.h"
31#include <assert.h>
32
33
34datelistbrowserclass::datelistbrowserclass () {
35}
36
37datelistbrowserclass::~datelistbrowserclass () {
38}
39
40text_t datelistbrowserclass::get_browser_name () {
41 return "DateList";
42}
43
44browserclass* datelistbrowserclass::clone()
45{
46 return new datelistbrowserclass();
47}
48
49void datelistbrowserclass::load_metadata_defaults (text_tset &metadata) {
50 metadata.insert ("Date");
51 metadata.insert ("doctype");
52}
53
54text_t datelistbrowserclass::get_default_formatstring () {
55 return "<td>[link][icon][/link]</td><td>[highlight]{Or}{[dc.Title],[exp.Title],[ex.Title],Untitled}[/highlight]</td><td>{Or}{[format:dc.Date],[format:exp.Date],[format:ex.Date]}</td>";
56}
57
58int datelistbrowserclass::output_section_group (ResultDocInfo_t &/*section*/, cgiargsclass &/*args*/,
59 const text_t &/*collection*/, int /*colnumber*/,
60 format_t * /*formatlistptr*/, bool /*use_table*/,
61 text_tset &/*metadata*/, bool &/*getParents*/,
62 recptproto * /*collectproto*/, displayclass &/*disp*/,
63 outconvertclass &/*outconvert*/, ostream &/*textout*/,
64 ostream &/*logout*/) {
65 return 0;
66}
67
68int datelistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
69 const text_t &collection, int colnumber, format_t *formatlistptr,
70 bool use_table, text_tset &/*metadata*/, bool &/*getParents*/,
71 recptproto * collectproto, displayclass &disp,
72 outconvertclass &outconvert, ostream &textout, ostream &logout) {
73
74 browsetoolsclass btools;
75 text_t lastyear = "0000";
76 text_t lastmonth = "00";
77 text_t tabbing, endtabbing;
78
79 if (use_table || colnumber > 0) {
80 textout << outconvert << "<table><tr><td>";
81 // get tab size
82 text_t tab; int itab;
83 disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
84 itab = tab.getint();
85 if (colnumber > 0)
86 textout << outconvert << "<img alt=\"\" src=\"_httpiconspace_\" width=\"" << (itab*colnumber) << "\"/>";
87 textout << outconvert << "</td><td>";
88 }
89
90 textout << outconvert << "<table class=\"date_list\">\n";
91
92 ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
93 ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
94
95 // use the dm arg as date metadata or else Date
96 text_t date_meta = args["dm"];
97 if (date_meta == "") {
98 date_meta = "Date";
99 }
100 text_tarray dates;
101 splitchar(date_meta.begin(), date_meta.end(), ',', dates);
102
103 while (thissection != endsection) {
104
105 text_t &doctype = (*thissection).metadata["doctype"].values[0];
106
107 text_tarray::iterator begin = dates.begin();
108 text_tarray::iterator end = dates.end();
109 text_t date;
110 while (begin!= end && date.empty()) {
111 date = (*thissection).metadata[*begin].values[0];
112 begin++;
113 }
114 text_t thisyear = "";
115 text_t thismonth = "";
116 if (!date.empty()) {
117 text_t::const_iterator datebegin = date.begin();
118 int datesize = date.size();
119
120 if (datesize >=4) {
121 thisyear = substr (datebegin, datebegin+4);
122 thismonth = "00";
123 int pos = 4;
124 // allow for yyyy-mm-dd
125 if (date[pos]=='-') {
126 ++pos;
127 }
128 if (datesize >= pos+2)
129 thismonth = substr (datebegin+pos, datebegin+pos+2);
130 }
131 }
132
133 text_t link = "<a href=\"_httpdocument_&cl=";
134 text_t icon = "_document:iconclosedbook_";
135
136 if (doctype == "classify") {
137 icon = "_document:iconclosedbookshelf_";
138 link += (*thissection).OID + "\">";
139 } else {
140 link += args["cl"] + "&d=" + (*thissection).OID; // + "\">";
141 // [modification to allow default document detach settings -- kjdon]
142 if (args["xx"]=="1") {
143 // documents should be detached
144 link += "&x=1\" target=\\_blank>";
145 } else {
146 link += "\">";
147 }
148 }
149
150 textout << outconvert << "<tr valign=top>";
151
152 if (thisyear != "" && thisyear != lastyear) {
153 textout << outconvert << "<td><span class=\"date_list_year\">" << thisyear << "</span></td>";
154 lastyear = thisyear;
155 } else {
156 textout << outconvert << "<td></td>";
157 }
158 if (thismonth != "" && thismonth != lastmonth) {
159 textout << outconvert << disp << ("<td><span class=\"date_list_month\">_textmonth" + thismonth + "_</span></td>");
160 lastmonth = thismonth;
161 } else {
162 textout << outconvert << "<td></td>";
163 }
164 if (!use_table) textout << outconvert << "<td>\n";
165
166 text_tmap options;
167 options["link"] = link;
168 options["icon"] = icon;
169 options["highlight"] = "0";
170 options["DocImage"] = btools.get_cover_image();
171 options["assocfilepath"] = btools.get_assocfile_path();
172
173 textout << outconvert << disp
174 << get_formatted_string (collection, collectproto,
175 *thissection, disp, formatlistptr,
176 options, logout) << "\n";
177
178 if (!use_table) textout << outconvert << "</td>";
179
180 textout << outconvert << "</tr>\n";
181
182 ++thissection;
183 }
184
185 textout << outconvert << "</table>\n";
186
187 if (use_table || colnumber > 0) textout << outconvert << "</td></tr></table>\n";
188 return 1;
189}
190
191#endif //GSDL_USE_DATELIST_BROWSER
Note: See TracBrowser for help on using the repository browser.