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