source: trunk/gsdl/src/recpt/formattools.h@ 7389

Last change on this file since 7389 was 7389, checked in by davidb, 20 years ago

Format statment 'if' syntax extended to support operators such as
'eq' and 'ne'. Can now say things like: {If}{[format] eq 'ab cd',X,Y}
Two main changes in code. The first is where the text of the text-condition
of the if statement is handled. This now needs to be parsed, to ensure
any metadata present it recorded, so when 'docinfo' is setup the necessary
metadata is there. The second change is that, when the test condition
of the if statement is evaluated, it is parsed 'on the fly' to look
for the precence of an operator such as 'eq' or 'ne' (in fact these are
currently the only ones implemented; others, such as 'gt' for greater
than etc would be straightforward to add). If there is an operator
detected, the the left and right hand sides of the expression are
determined (any metadata looked up) and the operator applied.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/**********************************************************************
2 *
3 * formattools.h --
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
27#ifndef FORMATTOOLS_H
28#define FORMATTOOLS_H
29
30#include "text_t.h"
31#include "comtypes.h"
32#include "recptproto.h"
33#include "display.h"
34
35enum command_t {comIf, comOr, comMeta, comText, comLink, comEndLink, comNum, comIcon,
36 comDoc, comHighlight, comEndHighlight, comRel, comHref, comSummary,
37 comTOC, comImage, comDocumentButtonDetach, comDocumentButtonHighlight,
38 comDocumentButtonExpandContents, comDocumentButtonExpandText, comOID, comRank};
39enum pcommand_t {pNone, pImmediate, pTop, pAll};
40enum dcommand_t {dMeta, dText};
41enum mcommand_t {mNone=0, mCgiSafe=1, mParent=2, mSibling=4};
42
43struct metadata_t {
44 void clear();
45 metadata_t () {clear();}
46
47 text_t metaname;
48 int metacommand; // used to hold flags from mcommand_t
49 pcommand_t parentcommand;
50 text_t functionoptions;
51};
52
53
54// The decision component of an {If}{decision,true-text,false-text}
55// formatstring. The decision can be based on metadata or on text;
56// normally that text would be a macro like _cgiargmode_. --gordon
57struct decision_t {
58 void clear();
59 decision_t () {clear();}
60
61 dcommand_t command;
62 metadata_t meta;
63 text_t text;
64};
65
66struct format_t {
67 void clear();
68 format_t () {clear();}
69
70 command_t command;
71 decision_t decision;
72 text_t text;
73 metadata_t meta;
74 format_t *nextptr;
75 format_t *ifptr;
76 format_t *elseptr;
77 format_t *orptr;
78};
79
80// the format structure used by this receptionist
81struct formatinfo_t {
82 void clear();
83 formatinfo_t () {clear();}
84
85 bool DocumentImages;
86 bool DocumentTitles;
87 text_t DocumentHeading;
88 bool DocumentContents;
89 bool DocumentArrowsBottom;
90 bool DocumentArrowsTop;
91 text_tarray DocumentButtons;
92 text_t DocumentText;
93 //-----------------
94 text_t RelatedDocuments;
95 //----------------
96 text_tmap formatstrings;
97 bool DocumentUseHTML;
98 bool AllowExtendedOptions;
99};
100
101bool is_table_content (const text_t &formatstring);
102bool is_table_content (const format_t *formatlistptr);
103
104bool get_formatstring (const text_t &key, const text_tmap &formatstringmap,
105 text_t &formatstring);
106bool get_formatstring (const text_t &key1, const text_t &key2,
107 const text_tmap &formatstringmap,
108 text_t &formatstring);
109
110text_t format_date (const text_t &date);
111
112text_t remove_namespace(const text_t &meta_name);
113
114text_t iso639 (const text_t &langcode);
115
116text_t get_href (const text_t &link);
117
118text_t get_related_docs(const text_t& collection, recptproto* collectproto,
119 ResultDocInfo_t &docinfo, ostream& logout);
120
121
122bool parse_formatstring (const text_t &formatstring, format_t *formatlistptr,
123 text_tset &metadata, bool &getParents);
124
125
126
127text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
128 ResultDocInfo_t &docinfo, displayclass &disp,
129 format_t *formatlistptr, text_tmap &options,
130 ostream& logout);
131
132#endif
133
134
Note: See TracBrowser for help on using the repository browser.