[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 |
|
---|
| 29 | package colcfg;
|
---|
| 30 |
|
---|
| 31 | use cfgread;
|
---|
| 32 | use gsprintf 'gsprintf';
|
---|
| 33 | use strict;
|
---|
| 34 |
|
---|
| 35 | # the collection configuration file data is stored in the form
|
---|
| 36 | #
|
---|
[15724] | 37 | # {'infodbtype'}->string
|
---|
[14657] | 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
|
---|
[24464] | 48 | # {'orthogonalbuildtypes'}->array of strings
|
---|
[14657] | 49 | # {'maxnumeric'}->string
|
---|
| 50 | # {'separate_cjk'}->string
|
---|
| 51 | # {'sections_index_document_metadata'}->string (always, unless_section_metadata_exists)
|
---|
[20416] | 52 | # {'languagemetadata'} -> string
|
---|
[14657] | 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] | 78 | sub 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??
|
---|
| 98 | sub 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
|
---|
[24464] | 117 | # {'orthogonalbuildtypes'}->array of strings
|
---|
[20101] | 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"
|
---|
[19751] | 132 |
|
---|
[20101] | 133 | # convenience method for reading in either build.cfg/buildConfig.xml
|
---|
| 134 | sub read_building_cfg {
|
---|
| 135 | my ($filename,$gs_mode) = @_;
|
---|
| 136 |
|
---|
| 137 | my $buildcfg = undef;
|
---|
[19751] | 138 |
|
---|
[20101] | 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;
|
---|
[14657] | 150 | }
|
---|
[19751] | 151 |
|
---|
[20101] | 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 {}
|
---|
[14657] | 155 |
|
---|
[20101] | 156 | ##############################
|
---|
| 157 | ### gs2/gs3 specific methods
|
---|
| 158 | ###############################
|
---|
| 159 |
|
---|
| 160 | #####################################
|
---|
| 161 | ### collect.cfg/collectionConfig.xml
|
---|
| 162 | #####################################
|
---|
| 163 |
|
---|
| 164 | # gs2 read in collect.cfg
|
---|
| 165 | sub read_collect_cfg {
|
---|
| 166 | my ($filename) = @_;
|
---|
| 167 |
|
---|
[24741] | 168 | return &cfgread::read_cfg_file_unicode ($filename,
|
---|
[20101] | 169 | q/^(infodbtype|creator|public|defaultindex|importdir|/ .
|
---|
| 170 | q/archivedir|cachedir|builddir|removeold|/ .
|
---|
[24464] | 171 | q/textcompress|buildtype|othogonalbuildtypes|no_text|keepold|gzip|/ .
|
---|
[20101] | 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)$/,
|
---|
[24519] | 178 | q/(maintainer|languages|indexsubcollections|orthogonalbuildtypes|/ .
|
---|
[20101] | 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)$/);
|
---|
[14657] | 184 | }
|
---|
| 185 |
|
---|
[20101] | 186 | # gs2 write out collect.cfg
|
---|
[14657] | 187 | sub write_collect_cfg {
|
---|
| 188 | my ($filename, $data) = @_;
|
---|
| 189 |
|
---|
| 190 | &cfgread::write_cfg_file($filename, $data,
|
---|
[15724] | 191 | q/^(infodbtype|creator|public|defaultindex|importdir|/ .
|
---|
[14657] | 192 | q/archivedir|cachedir|builddir|removeold|/ .
|
---|
| 193 | q/textcompress|buildtype|no_text|keepold|gzip|/ .
|
---|
[18528] | 194 | q/verbosity|remove_empty_classifications|OIDtype|OIDmetadata|/.
|
---|
[14657] | 195 | q/groupsize|maxdocs|debug|mode|saveas|/ .
|
---|
| 196 | q/sortmeta|removesuffix|removeprefix|create_images|/ .
|
---|
[20416] | 197 | q/maxnumeric|languagemetadata/ .
|
---|
[24754] | 198 | q/no_strip_html|index|sections_index_document_metadata)$/.
|
---|
| 199 | q/store_metadata_coverage)$/,
|
---|
[24519] | 200 | q/^(maintainer|languages|indexsubcollections|orthogonalbuildtypes|/ .
|
---|
[14657] | 201 | q/indexes|indexoptions|dontbuild|dontgdbm|mirror|levels|/.
|
---|
| 202 | q/searchtype|searchtypes)$/,
|
---|
| 203 | q/^(subcollection|format)$/,
|
---|
| 204 | q/^(acquire|plugin|classify)$/,
|
---|
| 205 | q/^(collectionmeta)$/);
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[20101] | 208 | # gs3 read in collectionConfig.xml
|
---|
| 209 | sub read_collection_cfg_xml {
|
---|
| 210 | my ($filename) = @_;
|
---|
[14657] | 211 |
|
---|
[21570] | 212 | require collConfigxml;
|
---|
[20101] | 213 | return &collConfigxml::read_cfg_file ($filename);
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | # gs3 write out collectionConfig.xml
|
---|
| 217 | sub write_collection_cfg_xml {
|
---|
| 218 |
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | #####################################
|
---|
| 222 | ### build.cfg/buildConfig.xml
|
---|
| 223 | ######################################
|
---|
| 224 |
|
---|
| 225 | # gs2 read build.cfg
|
---|
[14657] | 226 | sub read_build_cfg {
|
---|
| 227 | my ($filename) = @_;
|
---|
| 228 |
|
---|
| 229 | return &cfgread::read_cfg_file ($filename,
|
---|
[23939] | 230 | q/^(earliestdatestamp|infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
|
---|
[24464] | 231 | q/^(indexmap|subcollectionmap|languagemap|orthogonalbuildtypes|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);
|
---|
[14657] | 232 |
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[20101] | 235 | # gs2 write build.cfg
|
---|
[14657] | 236 | sub write_build_cfg {
|
---|
| 237 | my ($filename, $data) = @_;
|
---|
| 238 |
|
---|
| 239 | &cfgread::write_cfg_file($filename, $data,
|
---|
[23939] | 240 | q/^(earliestdatestamp|infodbtype|builddate|buildtype|numdocs|numsections|numwords|numbytes|maxnumeric|textlevel|indexstem|stemindexes|separate_cjk)$/,
|
---|
[24464] | 241 | q/^(indexmap|subcollectionmap|languagemap|orthogonalbuildtypes|notbuilt|indexfields|indexfieldmap|indexlevels|levelmap)$/);
|
---|
[14657] | 242 | }
|
---|
| 243 |
|
---|
[20101] | 244 | # gs3 read buildConfig.xml
|
---|
| 245 | sub read_build_cfg_xml {
|
---|
| 246 |
|
---|
| 247 | my ($filename) = @_;
|
---|
[21570] | 248 |
|
---|
| 249 | require buildConfigxml;
|
---|
[20101] | 250 | return &buildConfigxml::read_cfg_file($filename);
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | # gs3 write buildConfig.xml
|
---|
| 254 | sub write_build_cfg_xml {
|
---|
[21785] | 255 | my ($buildoutfile, $buildcfg, $collectcfg) = @_;
|
---|
[20101] | 256 |
|
---|
[21570] | 257 | require buildConfigxml;
|
---|
[21785] | 258 | return &buildConfigxml::write_cfg_file ($buildoutfile, $buildcfg, $collectcfg);
|
---|
[20101] | 259 | }
|
---|
| 260 |
|
---|
| 261 |
|
---|
| 262 | # method to check for filename of collect.cfg, and gs mode.
|
---|
[26567] | 263 | sub get_collect_cfg_name_old {
|
---|
[14657] | 264 | my ($out) = @_;
|
---|
| 265 |
|
---|
| 266 | # First check if there's a
|
---|
| 267 | # gsdl/collect/COLLECTION/custom/COLLECTION/etc/custom.cfg file. This
|
---|
| 268 | # customization was added for DLC by Stefan, 30/6/2007.
|
---|
| 269 | my $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "custom", $ENV{'GSDLCOLLECTION'}, "etc", "custom.cfg");
|
---|
| 270 |
|
---|
| 271 | if (-e $configfilename) {
|
---|
| 272 | return ($configfilename, "gs2");
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[25677] | 275 | # Check if there is a collectionConfig.xml file. If there is one, it's gs3
|
---|
| 276 | $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collectionConfig.xml");
|
---|
[14657] | 277 | if (-e $configfilename) {
|
---|
[25677] | 278 | return ($configfilename, "gs3");
|
---|
[14657] | 279 | }
|
---|
| 280 |
|
---|
[25677] | 281 | # If we get to here we check if there is a collect.cfg file in the usual place, i.e. it is gs2.
|
---|
| 282 | $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
|
---|
[14657] | 283 | if (-e $configfilename) {
|
---|
[25677] | 284 | return ($configfilename, "gs2");
|
---|
[14657] | 285 | }
|
---|
| 286 |
|
---|
| 287 | # Error. No collection configuration file.
|
---|
| 288 | (&gsprintf($out, "{common.cannot_find_cfg_file}\n", $configfilename) && die);
|
---|
| 289 | }
|
---|
| 290 |
|
---|
[26567] | 291 | # method to check for filename of collect.cfg
|
---|
| 292 | # needs to be given gs_version, since we can have a GS2 collection ported into
|
---|
| 293 | # GS3 which could potentially have collect.cfg AND collectionConfig.xml
|
---|
| 294 | # in which case the older version of this subroutine (get_collect_cfg_name_old)
|
---|
| 295 | # will return the wrong answer for the gs version we're using.
|
---|
| 296 | sub get_collect_cfg_name {
|
---|
| 297 | my ($out, $gs_version) = @_;
|
---|
[14926] | 298 |
|
---|
[26567] | 299 | # First check if there's a
|
---|
| 300 | # gsdl/collect/COLLECTION/custom/COLLECTION/etc/custom.cfg file. This
|
---|
| 301 | # customization was added for DLC by Stefan, 30/6/2007.
|
---|
| 302 | my $configfilename;
|
---|
| 303 |
|
---|
| 304 | if($gs_version eq "gs2") {
|
---|
| 305 | $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "custom", $ENV{'GSDLCOLLECTION'}, "etc", "custom.cfg");
|
---|
| 306 |
|
---|
| 307 | if (-e $configfilename) {
|
---|
| 308 | return $configfilename;
|
---|
| 309 | }
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | # Check if there is a collectionConfig.xml file if it's gs3
|
---|
| 313 | if($gs_version eq "gs3") {
|
---|
| 314 | $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collectionConfig.xml");
|
---|
| 315 | if (-e $configfilename) {
|
---|
| 316 | return $configfilename;
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | # Check if there is a collect.cfg file in the usual place for gs2.
|
---|
| 321 | if($gs_version eq "gs2") {
|
---|
| 322 | $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
|
---|
| 323 | if (-e $configfilename) {
|
---|
| 324 | return $configfilename;
|
---|
| 325 | }
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | # Error. No collection configuration file.
|
---|
| 329 | (&gsprintf($out, "{common.cannot_find_cfg_file}\n", $configfilename) && die);
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 |
|
---|
| 333 |
|
---|
[14926] | 334 | sub use_collection {
|
---|
| 335 | my ($site, $collection, $collectdir) = @_;
|
---|
| 336 |
|
---|
| 337 | if ((defined $site) && ($site ne ""))
|
---|
| 338 | {
|
---|
| 339 | return &util::use_site_collection($site, $collection, $collectdir);
|
---|
| 340 | }
|
---|
| 341 | else
|
---|
| 342 | {
|
---|
| 343 | return &util::use_collection($collection, $collectdir);
|
---|
| 344 | }
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 |
|
---|
[14657] | 348 | 1;
|
---|
| 349 |
|
---|
[14926] | 350 |
|
---|