Updated the server installation and server upgrade documentation to refer to the...
[working/Evergreen.git] / tools / permissions_to_docbook_function.sql
1 /*
2 * Function: permissions_list_to_docbook2() 
3  * Copyright (C) 2011  Robert Soulliere <robert.soulliere@mohawkcollege.ca>
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * This function can be used for generating a DocBook appendix in XML format to be included in the Evergreen DocBook documentation. 
15  * It takes the code and descrtiption values from permission.perm_list and formats it into XML. Some cleanup is required to remove added lines in the beginning and end of the file. 
16  * To run this script simple use the following commands from psql:
17  * \g permissions.xml
18  * SELECT * FROM permissions_list_to_docbook2();
19 */
20
21 CREATE OR REPLACE FUNCTION permissions_list_to_docbook2()
22   RETURNS text AS
23 $BODY$
24 DECLARE
25     r permission.perm_list;
26   --  r permission.perm_list;
27     strXML xml;
28   strHead text;
29   strFoot text;
30   xmlCode xml;
31   xmlTerm xml;
32   xmlTermEnd xml;
33   --  description permission.perm_list.description;
34 BEGIN
35         FOR r.code, r.description IN SELECT code, description FROM permission.perm_list AS pl WHERE id > 0 ORDER BY code
36                         LOOP   
37                                 XMLTerm = XMLCONCAT(XMLTerm, '
38                         ',      
39                                         XMLELEMENT (name formalpara,
40                                                 XMLCONCAT('
41
42                                 ',
43                                                         XMLELEMENT(
44                                                                 name title,
45                                                                 r.code), '
46                                 ',   
47                                                         XMLELEMENT(
48                                                                 name para, 
49                                                                 r.description), '
50                         '
51                         
52                                                 )
53                                         )
54                                 );
55                                 
56                         --      XMLTerm = XMLCONCAT(XMLTerm,  XMLELEMENT (name listitem, r.description), '
57                         --');
58                         END LOOP;
59
60         strXML = XMLELEMENT (
61                 name appendix, 
62                 XMLATTRIBUTES(
63                         'http://docbook.org/ns/docbook' AS "xmlns",
64                         'http://www.w3.org/2001/XInclude' AS "xmlns:xi",
65                         'http://www.w3.org/1999/xlink' AS "xmlns:xl",
66                         '5.0' as version, 
67                         'permissions_appendix' AS "xml:id"
68                 ),
69                 XMLCONCAT(
70                         ' 
71         ',
72                         XMLELEMENT (
73                                 name info, 
74                                 XMLELEMENT (name title, 'Permissions List')
75                         ), '
76         ', 
77                         XMLELEMENT (
78                                 name section,
79                                 XMLATTRIBUTES(
80                                   'permission_descriptions' AS "xml:id"
81                                 ),
82                                 XMLCONCAT (
83                                         ' 
84                 ',
85                                         XMLELEMENT (name title, 'Permission Descriptions'), 
86                                         ' ',
87                                         XMLCONCAT (' 
88                         ',                      XMLTerm, ' 
89                 ')
90                                                         
91                                 ), '
92         '
93                                         
94                         )
95                 ), '
96 '
97         );                                      
98  RETURN strXML;
99 END
100 $BODY$
101   LANGUAGE 'plpgsql' VOLATILE
102   COST 100;
103
104
105