root/gsdl/trunk/perllib/colcfg.pm @ 19751

Revision 19751, 7.5 KB (checked in by davidb, 11 years ago)

Added new function read_collection_cfg() which uses the argument passed in (gs2 or gs3) to work out which read function to use

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1###########################################################################
2#
3# colcfg.pm --
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
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# reads in a collection configuration file
27
28package colcfg;
29
30use cfgread;
31use cfgread4gs3;
32use gsprintf 'gsprintf';
33use strict;
34
35# the collection configuration file data is stored in the form
36#
37# {'infodbtype'}->string
38# {'creator'}->string
39# {'public'}->string
40# {'defaultindex'}->string
41# {'importdir'}->string
42# {'archivedir'}->string
43# {'cachedir'}->string
44# {'builddir'}->string
45# {'removeold'}->string
46# {'textcompress'}->string
47# {'buildtype'}->string
48# {'maxnumeric'}->string
49# {'separate_cjk'}->string
50# {'sections_index_document_metadata'}->string (always, unless_section_metadata_exists)
51# {'maintainer'}->array of strings
52# {'languages'}->array of strings
53# {'indexsubcollections'}->array of strings
54# {'indexes'}->array of strings
55# {'indexoptions'}->array of strings (stem, casefold, accentfold)
56# {'dontbuild'}->array of strings
57# {'dontgdbm'}->array of strings
58# {'mirror'}->array of strings
59# {'phind'}->array of strings
60# {'plugout'}->array of strings
61# {'levels'}->array of strings (for mgpp eg Section, Paragraph)
62# {'searchtype'}->array of strings (for mgpp, form or plain)
63
64# {'subcollection'}->hash of key-value pairs
65
66# {'acquire'}->array of arrays of strings
67# {'plugin'}->array of arrays of strings
68# {'classify'}->array of arrays of strings
69
70# {'collectionmeta'}->hash of key->hash of param-value -used
71# for language specification
72#    for example, collectionmeta->collectionname->default->demo
73#                                               ->mi->maori demo
74
75sub read_collect_cfg {
76    my ($filename) = @_;
77
78    return &cfgread::read_cfg_file ($filename,
79                    q/^(infodbtype|creator|public|defaultindex|importdir|/ .
80                    q/archivedir|cachedir|builddir|removeold|/ .
81                    q/textcompress|buildtype|no_text|keepold|gzip|/ .
82                    q/verbosity|remove_empty_classifications|OIDtype|OIDmetadata|/ .
83                    q/groupsize|maxdocs|debug|mode|saveas|/ .
84                    q/sortmeta|removesuffix|removeprefix|create_images|/ .
85                    q/maxnumeric|languagemetadata|/ .
86                    q/no_strip_html|index|sections_index_document_metadata|/ .
87                    q/store_metadata_coverage)$/,
88                    q/(maintainer|languages|indexsubcollections|/ .
89                       q/indexes|indexoptions|dontbuild|dontgdbm|mirror|levels|plugout|/ .
90                       q/searchtype|searchtypes)$/,
91                    q/^(subcollection|format)$/,
92                    q/^(acquire|plugin|classify)$/,
93                    q/^(collectionmeta)$/);
94}
95
96sub read_collection_cfg_xml {
97    my ($filename) = @_;
98
99    return &cfgread4gs3::read_cfg_file ($filename);
100}
101
102sub read_collection_cfg {
103    my ($filename,$gs_mode) = @_;
104   
105    my $collectcfg = undef;
106
107    if ($gs_mode eq "gs2") {
108    $collectcfg = &colcfg::read_collect_cfg ($filename);
109    } elsif ($gs_mode eq "gs3") {
110    $collectcfg = &colcfg::read_collection_cfg_xml ($filename);
111    }
112    else {
113    print STDERR "Failed to read collection configuration file\n";
114    print STDERR "  Unrecognized mode: $gs_mode\n";
115    }
116
117    return $collectcfg;
118}
119
120
121
122sub write_collection_cfg_xml {
123 
124}
125
126sub write_build_cfg_xml {
127    my ($buildoutfile, $buildcfg, $collectcfg, $disable_OAI) = @_;
128
129    return &cfgread4gs3::write_cfg_file ($buildoutfile, $buildcfg, $collectcfg, $disable_OAI);
130}
131
132sub write_collect_cfg {
133    my ($filename, $data) = @_;
134   
135    &cfgread::write_cfg_file($filename, $data,
136                 q/^(infodbtype|creator|public|defaultindex|importdir|/ .
137                 q/archivedir|cachedir|builddir|removeold|/ .
138                 q/textcompress|buildtype|no_text|keepold|gzip|/ .
139                 q/verbosity|remove_empty_classifications|OIDtype|OIDmetadata|/.
140                 q/groupsize|maxdocs|debug|mode|saveas|/ .
141                 q/sortmeta|removesuffix|removeprefix|create_images|/ .
142                 q/maxnumeric|language_metadata/ .
143                 q/no_strip_html|index|sections_index_document_metadata)$/,
144                 q/^(maintainer|languages|indexsubcollections|/ .
145                 q/indexes|indexoptions|dontbuild|dontgdbm|mirror|levels|/.
146                 q/searchtype|searchtypes)$/,
147                 q/^(subcollection|format)$/,
148                 q/^(acquire|plugin|classify)$/,
149                 q/^(collectionmeta)$/);
150}
151
152
153# the build configuration file data is stored in the form
154#
155# {'infodbtype'}->string
156# {'builddate'}->string
157# {'buildtype'}->string
158# {'metadata'}->array of strings
159# {'languages'}->array of strings
160# {'numdocs'}->string
161# {'numsections'}->string
162# {'numwords'}->string
163# {'numbytes'}->string
164# {'maxnumeric'}->string
165# {'indexfields'}->array of strings
166# {'indexfieldmap'}->array of strings in the form "field->FI"
167# {'indexmap'} -> array of strings
168# {'indexlevels'} -> array of strings
169# {'stemindexes'} -> string (int)
170# {'textlevel'}->string
171# {'levelmap'} -> array of strings in the form "level->shortname"
172sub read_build_cfg {
173    my ($filename) = @_;
174
175    return &cfgread::read_cfg_file ($filename,
176           q/^(infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
177           q/^(indexmap|subcollectionmap|languagemap|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);
178                   
179}
180
181sub write_build_cfg {
182    my ($filename, $data) = @_;
183
184    &cfgread::write_cfg_file($filename, $data,
185           q/^(infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
186           q/^(indexmap|subcollectionmap|languagemap|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);           
187}
188
189sub get_collect_cfg_name {
190    my ($out) = @_;
191
192    # First check if there's a
193    # gsdl/collect/COLLECTION/custom/COLLECTION/etc/custom.cfg file. This
194    # customization was added for DLC by Stefan, 30/6/2007.
195    my $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "custom", $ENV{'GSDLCOLLECTION'}, "etc", "custom.cfg");
196
197    if (-e $configfilename) {
198        return ($configfilename, "gs2");
199    }
200
201    # Now check if there is a collect.cfg file in the usual place, i.e. it is gs2.
202    $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
203    if (-e $configfilename) {
204        return ($configfilename, "gs2");
205    }
206
207    # If we get to here we check if there is a collectionConfig.xml file,
208    # i.e. it is gs3.
209    $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collectionConfig.xml");   
210    if (-e $configfilename) {
211        return ($configfilename, "gs3");
212    }
213
214    # Error. No collection configuration file.
215    (&gsprintf($out, "{common.cannot_find_cfg_file}\n", $configfilename) && die);
216}
217
218
219sub use_collection {
220   my ($site, $collection, $collectdir) = @_;
221
222   if ((defined $site) && ($site ne ""))
223   {
224       return &util::use_site_collection($site, $collection, $collectdir);
225   }
226   else
227   {
228       return &util::use_collection($collection, $collectdir);
229   }
230}
231
232
2331;
234
235
Note: See TracBrowser for help on using the browser.