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

Revision 27093, 5.3 KB (checked in by ak19, 7 years ago)

httpdomain macro in rss items resolved in receptionist with primary preference given to what's in zextra.dm. At present, forced to use package Global in the code that sets the macro, since a new macro file, rss.dm, registered in etc/main.cfg and containing the package name rss(feed) wasn't getting through with the setmacro call.

  • 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>_httpdomain__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>_httpdomain__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  // For some reason, setting the _httpdomain_ macro only works when its package name is specified as Global
115  // Doesn't work if package name is set as rssfeed, even though etc/main.cfg refers to new rss.dm containing a package by that name
116 
117  // Before resolving the _httpdomain_ macro
118  // 1. Check if _httpdomain_ was defined by user in macros (packages rssfeed of rss.dm and Global).
119  // E.g. user could have defined it in package Global of zextra.dm
120  // If none found, try to get it from the cgiargs hostname= (set using javascript),
121  // and set as macro for package Rss.
122 
123  if(disp.havemacro("Global", "httpdomain") == 0) { // checks rss(feed) and Global packages and if not found
124   
125    if(!args["hostname"].empty()) {
126      disp.setmacro("httpdomain", "Global", "http://" + args["hostname"]); //disp.setmacro("httpdomain", "Global", args["hostname"]);
127    }
128    else { // we shouldn't have to get here
129      disp.setmacro("httpdomain", "Global", "http://localhost:8282"); // the default used in zextra.dm. (Could perhaps default this to localhost too)
130    }
131  }
132
133
134  if (!args["c"].empty()) {
135    recptproto* collectproto = protos->getrecptproto (arg_c, logout);   
136    if (collectproto != NULL) {
137      collectproto->get_rss_items (arg_c, gsdlhome, rss_items, err, logout);
138      if (err == noError) success = true;
139      // else a communication error   
140    }
141  }
142
143  generate_rss_header(disp,outconvert,textout,logout);
144  if(success) {
145    generate_rss_content(rss_items,disp,outconvert,textout,logout);
146  }
147  generate_rss_footer(disp,outconvert,textout,logout);
148
149  return success;
150};
151
152#endif //USE_RSS
Note: See TracBrowser for help on using the browser.