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

Revision 20416, 9.6 KB (checked in by kjdon, 10 years ago)

language_metadata was sometimes with an underscore, and sometimes without. Have standardised to no underscore: languagemetadata

  • 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/writes the collection configuration files:
27# collect.cfg/collectionConfig.xml and build.cfg/buildConfig.xml
28
29package colcfg;
30
31use cfgread;
32use collConfigxml;
33use buildConfigxml;
34use gsprintf 'gsprintf';
35use strict;
36
37# the collection configuration file data is stored in the form
38#
39# {'infodbtype'}->string
40# {'creator'}->string
41# {'public'}->string
42# {'defaultindex'}->string
43# {'importdir'}->string
44# {'archivedir'}->string
45# {'cachedir'}->string
46# {'builddir'}->string
47# {'removeold'}->string
48# {'textcompress'}->string
49# {'buildtype'}->string
50# {'maxnumeric'}->string
51# {'separate_cjk'}->string
52# {'sections_index_document_metadata'}->string (always, unless_section_metadata_exists)
53# {'languagemetadata'} -> string
54# {'maintainer'}->array of strings
55# {'languages'}->array of strings
56# {'indexsubcollections'}->array of strings
57# {'indexes'}->array of strings
58# {'indexoptions'}->array of strings (stem, casefold, accentfold)
59# {'dontbuild'}->array of strings
60# {'dontgdbm'}->array of strings
61# {'mirror'}->array of strings
62# {'phind'}->array of strings
63# {'plugout'}->array of strings
64# {'levels'}->array of strings (for mgpp eg Section, Paragraph)
65# {'searchtype'}->array of strings (for mgpp, form or plain)
66
67# {'subcollection'}->hash of key-value pairs
68
69# {'acquire'}->array of arrays of strings
70# {'plugin'}->array of arrays of strings
71# {'classify'}->array of arrays of strings
72
73# {'collectionmeta'}->hash of key->hash of param-value -used
74# for language specification
75#    for example, collectionmeta->collectionname->default->demo
76#                                               ->mi->maori demo
77
78# convenience method for reading in either collect.cfg/collectionConfig.xml
79sub read_collection_cfg {
80    my ($filename,$gs_mode) = @_;
81   
82    my $collectcfg = undef;
83
84    if ($gs_mode eq "gs2") {
85    $collectcfg = &colcfg::read_collect_cfg ($filename);
86    } elsif ($gs_mode eq "gs3") {
87    $collectcfg = &colcfg::read_collection_cfg_xml ($filename);
88    }
89    else {
90    print STDERR "Failed to read collection configuration file\n";
91    print STDERR "  Unrecognized mode: $gs_mode\n";
92    }
93
94    return $collectcfg;
95}
96
97# convenience method for writing out either collect.cfg/collectionConfig.xml
98# is this ever used??
99sub write_collection_cfg {
100     my ($filename, $collectcfg_data, $gs_mode) = @_;
101   
102    if ($gs_mode eq "gs2") {
103    &colcfg::write_collect_cfg ($filename, $collectcfg_data );
104    } elsif ($gs_mode eq "gs3") {
105    &colcfg::write_collection_cfg_xml ($filename, $collectcfg_data);
106    }
107    else {
108    print STDERR "Failed to write collection configuration file\n";
109    print STDERR "  Unrecognized mode: $gs_mode\n";
110    }
111}
112   
113# the build configuration file data is stored in the form
114#
115# {'infodbtype'}->string
116# {'builddate'}->string
117# {'buildtype'}->string
118# {'metadata'}->array of strings
119# {'languages'}->array of strings
120# {'numdocs'}->string
121# {'numsections'}->string
122# {'numwords'}->string
123# {'numbytes'}->string
124# {'maxnumeric'}->string
125# {'indexfields'}->array of strings
126# {'indexfieldmap'}->array of strings in the form "field->FI"
127# {'indexmap'} -> array of strings
128# {'indexlevels'} -> array of strings
129# {'stemindexes'} -> string (int)
130# {'textlevel'}->string
131# {'levelmap'} -> array of strings in the form "level->shortname"
132
133# convenience method for reading in either build.cfg/buildConfig.xml
134sub read_building_cfg {
135    my ($filename,$gs_mode) = @_;
136   
137    my $buildcfg = undef;
138
139    if ($gs_mode eq "gs2") {
140    $buildcfg = &colcfg::read_build_cfg ($filename);
141    } elsif ($gs_mode eq "gs3") {
142    $buildcfg = &colcfg::read_build_cfg_xml ($filename);
143    }
144    else {
145    print STDERR "Failed to read building configuration file\n";
146    print STDERR "  Unrecognized mode: $gs_mode\n";
147    }
148
149    return $buildcfg;
150}
151
152# convenience method for writing out either build.cfg/buildConfig.xml
153# haven't got one, as gs3 version needs extra parameters
154#sub write_building_cfg {}
155
156##############################
157### gs2/gs3 specific methods
158###############################
159
160#####################################
161### collect.cfg/collectionConfig.xml
162#####################################
163
164# gs2 read in collect.cfg
165sub read_collect_cfg {
166    my ($filename) = @_;
167
168    return &cfgread::read_cfg_file ($filename,
169                    q/^(infodbtype|creator|public|defaultindex|importdir|/ .
170                    q/archivedir|cachedir|builddir|removeold|/ .
171                    q/textcompress|buildtype|no_text|keepold|gzip|/ .
172                    q/verbosity|remove_empty_classifications|OIDtype|OIDmetadata|/ .
173                    q/groupsize|maxdocs|debug|mode|saveas|/ .
174                    q/sortmeta|removesuffix|removeprefix|create_images|/ .
175                    q/maxnumeric|languagemetadata|/ .
176                    q/no_strip_html|index|sections_index_document_metadata|/ .
177                    q/store_metadata_coverage)$/,
178                    q/(maintainer|languages|indexsubcollections|/ .
179                       q/indexes|indexoptions|dontbuild|dontgdbm|mirror|levels|plugout|/ .
180                       q/searchtype|searchtypes)$/,
181                    q/^(subcollection|format)$/,
182                    q/^(acquire|plugin|classify)$/,
183                    q/^(collectionmeta)$/);
184}
185
186# gs2 write out collect.cfg
187sub write_collect_cfg {
188    my ($filename, $data) = @_;
189   
190    &cfgread::write_cfg_file($filename, $data,
191                 q/^(infodbtype|creator|public|defaultindex|importdir|/ .
192                 q/archivedir|cachedir|builddir|removeold|/ .
193                 q/textcompress|buildtype|no_text|keepold|gzip|/ .
194                 q/verbosity|remove_empty_classifications|OIDtype|OIDmetadata|/.
195                 q/groupsize|maxdocs|debug|mode|saveas|/ .
196                 q/sortmeta|removesuffix|removeprefix|create_images|/ .
197                 q/maxnumeric|languagemetadata/ .
198                 q/no_strip_html|index|sections_index_document_metadata)$/,
199                 q/^(maintainer|languages|indexsubcollections|/ .
200                 q/indexes|indexoptions|dontbuild|dontgdbm|mirror|levels|/.
201                 q/searchtype|searchtypes)$/,
202                 q/^(subcollection|format)$/,
203                 q/^(acquire|plugin|classify)$/,
204                 q/^(collectionmeta)$/);
205}
206
207# gs3 read in collectionConfig.xml
208sub read_collection_cfg_xml {
209    my ($filename) = @_;
210
211    return &collConfigxml::read_cfg_file ($filename);
212}
213
214# gs3 write out collectionConfig.xml
215sub write_collection_cfg_xml {
216 
217}
218
219#####################################
220### build.cfg/buildConfig.xml
221######################################
222
223# gs2 read build.cfg
224sub read_build_cfg {
225    my ($filename) = @_;
226
227    return &cfgread::read_cfg_file ($filename,
228           q/^(infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
229           q/^(indexmap|subcollectionmap|languagemap|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);
230                   
231}
232
233# gs2 write build.cfg
234sub write_build_cfg {
235    my ($filename, $data) = @_;
236
237    &cfgread::write_cfg_file($filename, $data,
238           q/^(infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
239           q/^(indexmap|subcollectionmap|languagemap|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);           
240}
241
242# gs3 read buildConfig.xml
243sub read_build_cfg_xml {
244
245    my ($filename) = @_;
246   
247    return &buildConfigxml::read_cfg_file($filename);
248}
249
250# gs3 write buildConfig.xml
251sub write_build_cfg_xml {
252    my ($buildoutfile, $buildcfg, $collectcfg, $disable_OAI) = @_;
253
254    return &buildConfigxml::write_cfg_file ($buildoutfile, $buildcfg, $collectcfg, $disable_OAI);
255}
256
257
258# method to check for filename of collect.cfg, and gs mode.
259sub get_collect_cfg_name {
260    my ($out) = @_;
261
262    # First check if there's a
263    # gsdl/collect/COLLECTION/custom/COLLECTION/etc/custom.cfg file. This
264    # customization was added for DLC by Stefan, 30/6/2007.
265    my $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "custom", $ENV{'GSDLCOLLECTION'}, "etc", "custom.cfg");
266
267    if (-e $configfilename) {
268        return ($configfilename, "gs2");
269    }
270
271    # Now check if there is a collect.cfg file in the usual place, i.e. it is gs2.
272    $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
273    if (-e $configfilename) {
274        return ($configfilename, "gs2");
275    }
276
277    # If we get to here we check if there is a collectionConfig.xml file,
278    # i.e. it is gs3.
279    $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collectionConfig.xml");   
280    if (-e $configfilename) {
281        return ($configfilename, "gs3");
282    }
283
284    # Error. No collection configuration file.
285    (&gsprintf($out, "{common.cannot_find_cfg_file}\n", $configfilename) && die);
286}
287
288
289sub use_collection {
290   my ($site, $collection, $collectdir) = @_;
291
292   if ((defined $site) && ($site ne ""))
293   {
294       return &util::use_site_collection($site, $collection, $collectdir);
295   }
296   else
297   {
298       return &util::use_collection($collection, $collectdir);
299   }
300}
301
302
3031;
304
305
Note: See TracBrowser for help on using the browser.