root/main/trunk/greenstone2/runtime-src/src/recpt/rssaction.cpp @ 24959

Revision 24959, 4.2 KB (checked in by ak19, 8 years ago)

Second commit to do with Greenstone's support for RSS. Has been tested on Linux, and works if zextra.dm and base.dm are setup properly and if the rss-items.rdf file generated by the update to BasePlugout? is moved to the index folder. Modified Dr Bainbridge's code to make the way that rssaction.cpp accesses the rss-items.rdf file independent of where the GS server is located, by adding a new method to get the rss-items.rdf file's contents to the recptproto protocol class and implementing it in nullproto. The method is also mirrored in corba/corbaproto, however compilation with corba fails in a part of the code that I've not modified.

  • Property svn:executable set to *
Line 
1/**********************************************************************
2 *
3 * rssaction.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 USE_RSS
28
29#include "fileutil.h"
30
31#include "rssaction.h"
32
33rssaction::rssaction () {
34  // this action uses cgi variable "a"
35  cgiarginfo arg_ainfo;
36  arg_ainfo.shortname = "a";
37  arg_ainfo.longname = "action";
38  arg_ainfo.multiplechar = true;
39  arg_ainfo.multiplevalue = false;
40  arg_ainfo.defaultstatus = cgiarginfo::weak;
41  arg_ainfo.argdefault = "rss";
42  arg_ainfo.savedarginfo = cgiarginfo::must;
43
44  argsinfo.addarginfo (NULL, arg_ainfo);
45
46}
47
48void rssaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
49                   response_t &response, text_t &response_data,
50                   ostream &/*logout*/) {
51  response = content;
52  response_data = "application/rdf+xml";
53}
54
55void rssaction::generate_rss_header( displayclass &disp,
56                     outconvertclass &outconvert, ostream &textout,
57                     ostream &logout)
58{
59  textout << outconvert << disp
60      << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
61      << "<rss version=\"2.0\"\n"
62      << "xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"\n"
63      << "  xmlns:taxo=\"http://purl.org/rss/1.0/modules/taxonomy/\"\n"
64      << "  xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"
65      << "  xmlns:syn=\"http://purl.org/rss/1.0/modules/syndication/\"\n"
66      << "  xmlns:admin=\"http://webns.net/mvcb/\">\n"
67
68      << "<channel>\n"
69      << "  <title>_collectionname_</title>\n"
70      << "  <link>_httppageabout_</link>\n"
71      << "  <description>_collectionextra_</description>\n"
72      << "  <language>_cgiargl_</language>\n"
73      << "  <pubDate>Thu, 23 Aug 1999 07:00:00 GMT</pubDate>\n"
74      << "  <lastBuildDate>Thu, 23 Aug 1999 16:20:26 GMT</lastBuildDate>\n"
75      << "  <managingEditor>_creator_</managingEditor>\n"
76      << "  <webMaster>_maintainer_</webMaster>\n"
77
78      << "<image>\n"
79      << "  <title>_collectionname_</title>\n"
80      << "  <url>_iconcollection_</url>\n"
81      << "  <link>_httppageabout_</link>\n"
82      << "  <description>_collectionextra_</description>\n"
83      << "</image>\n";
84}
85
86void rssaction::generate_rss_content(text_t& rss_items, displayclass &disp,
87                     outconvertclass &outconvert, ostream &textout,
88                     ostream &logout)
89{
90  textout << outconvert << disp << rss_items;
91}
92
93void rssaction::generate_rss_footer( displayclass &disp,
94                     outconvertclass &outconvert, ostream &textout,
95                     ostream &logout)
96{
97
98  textout << outconvert << disp
99      << "  </channel>\n"
100      << "</rss>\n";
101}
102
103
104bool rssaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
105                browsermapclass * /*browsers*/, displayclass& disp,
106                outconvertclass &outconvert, ostream &textout,
107                ostream &logout) {
108  text_t rss_items;
109  bool success = false;
110  comerror_t err;
111
112  text_t &arg_c = args["c"];
113
114
115  if (!args["c"].empty()) {
116    recptproto* collectproto = protos->getrecptproto (arg_c, logout);   
117    if (collectproto != NULL) {
118      collectproto->get_rss_items (arg_c, gsdlhome, rss_items, err, logout);
119      if (err == noError) success = true;
120      // else a communication error   
121    }
122  }
123
124  generate_rss_header(disp,outconvert,textout,logout);
125  if(success) {
126    generate_rss_content(rss_items,disp,outconvert,textout,logout);
127  }
128  generate_rss_footer(disp,outconvert,textout,logout);
129
130  return success;
131};
132
133#endif //USE_RSS
Note: See TracBrowser for help on using the browser.