source: gsdl/trunk/perllib/colcfg.pm@ 20101

Last change on this file since 20101 was 20101, checked in by kjdon, 15 years ago

tidied up the file

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