source: main/trunk/greenstone2/perllib/colcfg.pm@ 27356

Last change on this file since 27356 was 27356, checked in by kjdon, 11 years ago

added sortfields (collect.cfg) and indexsortfields, indexsortfieldmap (build.cfg) - used for sorting search results in lucene collections

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