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