[14667] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # cfgread4gs3.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 in configuration files of xml form
|
---|
| 27 |
|
---|
| 28 | package cfgread4gs3;
|
---|
| 29 | use strict;
|
---|
| 30 | no strict 'refs';
|
---|
| 31 | no strict 'subs';
|
---|
| 32 |
|
---|
| 33 | # Wrapper that ensures the right version of XML::Parser is loaded given
|
---|
| 34 | # the version of Perl being used. Need to distinguish between Perl 5.6 and
|
---|
| 35 | # Perl 5.8
|
---|
| 36 | sub BEGIN {
|
---|
| 37 | my $perl_dir;
|
---|
| 38 |
|
---|
| 39 | # Note: $] encodes the version number of perl
|
---|
| 40 | if ($]>5.008) {
|
---|
| 41 | # perl 5.8.1 or above
|
---|
| 42 | $perl_dir = "perl-5.8";
|
---|
| 43 | }
|
---|
| 44 | elsif ($]<5.008) {
|
---|
| 45 | # assume perl 5.6
|
---|
| 46 | $perl_dir = "perl-5.6";
|
---|
| 47 | }
|
---|
| 48 | else {
|
---|
| 49 | print STDERR "Warning: Perl 5.8.0 is not a maintained release.\n";
|
---|
| 50 | print STDERR " Please upgrade to a newer version of Perl.\n";
|
---|
| 51 | $perl_dir = "perl-5.8";
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | if ($ENV{'GSDLOS'} !~ /^windows$/i) {
|
---|
| 55 | # Use push to put this on the end, so an existing XML::Parser will be used by default
|
---|
| 56 | push (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/$perl_dir");
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | use XML::Parser;
|
---|
| 61 |
|
---|
| 62 | # A mapping hash to resolve name descrepency between gs2 and gs3.
|
---|
| 63 | my $nameMap = {"key" => "value",
|
---|
| 64 | "creator" => "creator",
|
---|
| 65 | "maintainer" => "maintainer",
|
---|
| 66 | "public" => "public",
|
---|
| 67 | "defaultIndex" => "defaultindex",
|
---|
| 68 | "defaultLevel" => "defaultlevel",
|
---|
| 69 | "name" => "collectionname",
|
---|
| 70 | "description" => "collectionextra",
|
---|
| 71 | "smallicon" => "iconcollectionsmall",
|
---|
| 72 | "icon" => "iconcollection",
|
---|
| 73 | "level" => "levels",
|
---|
| 74 | "classifier" => "classify",
|
---|
| 75 | "indexSubcollection" => "indexsubcollections",
|
---|
| 76 | "indexLanguage" => "languages",
|
---|
| 77 | "defaultIndexLanguage" => "defaultlanguage",
|
---|
| 78 | "index" => "indexes",
|
---|
| 79 | "plugin" => "plugin",
|
---|
[14741] | 80 | "plugout" => "plugout",
|
---|
[14667] | 81 | "indexOption" => "indexoptions",
|
---|
| 82 | "searchType" => "searchtype",
|
---|
| 83 | "languageMetadata" => "languagemetadata",
|
---|
| 84 | };
|
---|
| 85 | # A hash structure which is returned by sub read_cfg_file.
|
---|
| 86 | my $data = {};
|
---|
| 87 |
|
---|
| 88 | my $repeatedBlock = q/^(browse|pluginList)$/;
|
---|
| 89 |
|
---|
| 90 | # use those unique attribute values to locate the text within the elements
|
---|
| 91 | # creator, public, maintainer.
|
---|
| 92 | my $currentLocation = "";
|
---|
| 93 | my $stringexp = q/^(creator|maintainer|public)$/;
|
---|
| 94 |
|
---|
| 95 | my $currentLevel = "";
|
---|
| 96 |
|
---|
| 97 | # Count the elements with same name within the same block
|
---|
| 98 | # ("plugin", "option")
|
---|
| 99 | my $currentIndex = 0;
|
---|
| 100 | my $arrayexp = q/^(index|level|indexSubcollection|indexLanguage)$/;
|
---|
| 101 | my $arrayarrayexp= q/^(plugin|classifier)$/;
|
---|
[14741] | 102 |
|
---|
[14667] | 103 | my $defaults = q/^(defaultIndex|defaultLevel|defaultIndexLanguage|languageMetadata)$/;
|
---|
| 104 |
|
---|
| 105 | sub StartTag {
|
---|
| 106 | # Those marked with #@ will not be executed at the same time when this sub is being called
|
---|
| 107 | # so that if/elsif is used to avoid unnecessary tests
|
---|
| 108 | my ($expat, $element) = @_;
|
---|
| 109 |
|
---|
| 110 | my $name = $_{'name'};
|
---|
| 111 | my $value = $_{'value'};
|
---|
| 112 | my $type = $_{'type'};
|
---|
| 113 |
|
---|
| 114 | # for subcollections
|
---|
| 115 | my $filter = $_{'filter'};
|
---|
[14741] | 116 |
|
---|
| 117 | # for flax activities
|
---|
| 118 | my $desid = $_{'desid'};
|
---|
| 119 | my $assigned = $_{'assigned'};
|
---|
| 120 |
|
---|
[14667] | 121 | #@ Marking repeated block
|
---|
| 122 | if ($element =~ /$repeatedBlock/) {
|
---|
| 123 | $currentIndex = 0;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | #@ handling block metadataList
|
---|
| 127 | elsif (defined $name and $name =~ /$stringexp/){
|
---|
| 128 | $currentLocation = $name;
|
---|
| 129 | }
|
---|
| 130 | #@ handling default search index/level/indexLanguage and languageMetadata
|
---|
| 131 | elsif ($element =~ /$defaults/) {
|
---|
| 132 | if (defined $name and $name =~ /\w/) {
|
---|
| 133 | $data->{$nameMap->{$element}} = $name;
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | #@ Handling indexer: mgpp/mg/lucene; stringexp
|
---|
| 138 | elsif ($element eq "search") {
|
---|
| 139 | $data->{'buildtype'} = $type;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | #@ Handling searchtype: plain,form; arrayexp
|
---|
| 143 | #elsif ($element eq "format" and defined $name and $name =~ /searchType/) {
|
---|
| 144 | #@ Handling searchtype: plain, form
|
---|
| 145 | #$currentLocation = $name;
|
---|
| 146 | #}
|
---|
| 147 |
|
---|
| 148 | #@ Handle index|level|indexSubcollection|indexLanguage
|
---|
| 149 | elsif ($element =~ /$arrayexp/) {
|
---|
| 150 | my $key = $nameMap->{$element};
|
---|
| 151 | if (!defined $data->{$key}) {
|
---|
| 152 | $data->{$key} = [];
|
---|
| 153 | }
|
---|
[14741] | 154 |
|
---|
[14667] | 155 | push (@{$data->{$key}},$name);
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | #@ indexoptions: accentfold/casefold/stem; arrayexp
|
---|
| 159 | elsif ($element eq "indexOption") {
|
---|
| 160 | $currentLevel = "indexOption";
|
---|
| 161 | }
|
---|
| 162 | if ($currentLevel eq "indexOption" and $element eq "option") {
|
---|
| 163 | my $key = $nameMap->{$currentLevel};
|
---|
| 164 | if (!defined $data->{$key}) {
|
---|
| 165 | $data->{$key} = [];
|
---|
| 166 | }
|
---|
| 167 | push (@{$data->{$key}},$name);
|
---|
| 168 | }
|
---|
| 169 | #@ plugout options
|
---|
| 170 | elsif ($element eq "plugout") {
|
---|
| 171 | $currentLevel = "plugout";
|
---|
| 172 | my $key = $nameMap->{$currentLevel};
|
---|
| 173 | if (!defined $data->{$key}) {
|
---|
| 174 | $data->{$key} = [];
|
---|
| 175 | }
|
---|
| 176 | if(defined $name and $name ne ""){
|
---|
| 177 | push (@{$data->{$key}},$name);
|
---|
| 178 | }
|
---|
| 179 | else{
|
---|
| 180 | push (@{$data->{$key}},"GAPlugout");
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | if ($currentLevel eq "plugout" and $element eq "option") {
|
---|
| 184 | my $key = $nameMap->{$currentLevel};
|
---|
| 185 | if (defined $name and $name ne ""){
|
---|
| 186 | push (@{$data->{$key}},$name);
|
---|
| 187 | }
|
---|
| 188 | if (defined $value and $value ne ""){
|
---|
| 189 | push (@{$data->{$key}},$value);
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
[14741] | 192 |
|
---|
[14667] | 193 | #@ use hash of hash of strings: hashexp
|
---|
| 194 | elsif ($element eq "subcollection") {
|
---|
| 195 | if (!defined $data->{'subcollection'}) {
|
---|
| 196 | $data->{'subcollection'} = {};
|
---|
| 197 | }
|
---|
| 198 | if (defined $name and $name =~ /\w/) {
|
---|
| 199 | if (defined $filter and $filter =~ /\w/) {
|
---|
| 200 | $data->{'subcollection'}->{$name} = $filter;
|
---|
| 201 |
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | #@ Handling each classifier/plugin element
|
---|
| 207 | elsif ($element =~ /$arrayarrayexp/) {
|
---|
| 208 | # find the gs2 mapping name
|
---|
| 209 | $currentLevel = $element;
|
---|
| 210 | my $key = $nameMap->{$element};
|
---|
| 211 |
|
---|
| 212 | # define an array of array of strings foreach $k (@{$data->{$key}}) {
|
---|
| 213 | if (!defined $data->{$key}) {
|
---|
| 214 | $data->{$key} = [];
|
---|
| 215 | }
|
---|
| 216 | # Push classifier/plugin name (e.g. AZList) into $data as the first string
|
---|
| 217 | push (@{$data->{$key}->[$currentIndex]},$name);
|
---|
| 218 | #print $currentIndex."indexup\n";
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | #@ Handling the option elements in each classifier/plugin element (as the following strings)
|
---|
| 222 | elsif ($currentLevel =~ /$arrayarrayexp/ and $element eq "option") {
|
---|
| 223 | # find the gs2 mapping name for classifier and plugin
|
---|
| 224 | my $key = $nameMap->{$currentLevel};
|
---|
| 225 |
|
---|
| 226 | if (defined $name and $name =~ /\w/) {
|
---|
| 227 | push (@{$data->{$key}->[$currentIndex]}, $name);
|
---|
| 228 | }
|
---|
| 229 | if (defined $value and $value =~ /\w/) {
|
---|
| 230 | push (@{$data->{$key}->[$currentIndex]}, $value);
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | }
|
---|
[14741] | 234 | #@ Handling each flaxActivity element (arrayarrayexp)
|
---|
| 235 | elsif ($element eq "flaxActivity") {
|
---|
| 236 | if (!defined $data->{'flaxActivity'}) {
|
---|
| 237 | $data->{'flaxActivity'} = [];
|
---|
| 238 | }
|
---|
| 239 | if(defined $assigned and $assigned =~ /\w/ and $assigned eq "true") {
|
---|
| 240 | if (defined $name and $name =~ /\w/) {
|
---|
| 241 | push (@{$data->{'flaxActivity'}->[$currentIndex]}, 'name');
|
---|
| 242 | push (@{$data->{'flaxActivity'}->[$currentIndex]}, $name);
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | if (defined $desid and $desid =~ /\w/) {
|
---|
| 246 | push (@{$data->{'flaxActivity'}->[$currentIndex]}, 'desid');
|
---|
| 247 | push (@{$data->{'flaxActivity'}->[$currentIndex]}, $desid);
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
| 250 | }
|
---|
[14667] | 251 | }
|
---|
| 252 |
|
---|
| 253 | sub EndTag {
|
---|
| 254 | my ($expat, $element) = @_;
|
---|
| 255 | my $endTags = q/^(browse|pluginList)$/;
|
---|
| 256 | if ($element =~ /$endTags/) {
|
---|
[14741] | 257 | $currentIndex = 0;
|
---|
| 258 | $currentLevel = "";
|
---|
[14667] | 259 | }
|
---|
| 260 | # $arrayarrayexp contains classifier|plugin
|
---|
[14741] | 261 | elsif($element =~ /$arrayarrayexp/ || $element eq "flaxActivity"){
|
---|
[14667] | 262 | $currentIndex = $currentIndex + 1;
|
---|
[14741] | 263 | }
|
---|
[14667] | 264 |
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | sub Text {
|
---|
| 268 | #@ Handling block metadataList(creator, maintainer, public)
|
---|
| 269 | if (defined $currentLocation and $currentLocation =~ /$stringexp/){
|
---|
| 270 | #print $currentLocation;
|
---|
| 271 | my $key = $nameMap->{$currentLocation};
|
---|
| 272 | $data->{$key} = $_;
|
---|
| 273 | undef $currentLocation;
|
---|
| 274 | }
|
---|
| 275 | #@ Handling searchtype: plain,form; arrayexp
|
---|
| 276 | if (defined $currentLocation and $currentLocation =~ /searchType/) {
|
---|
| 277 | # map 'searchType' into 'searchtype'
|
---|
| 278 | my $key = $nameMap->{$currentLocation};
|
---|
| 279 | # split it by ','
|
---|
| 280 | my ($plain, $form) = split (",", $_);
|
---|
| 281 |
|
---|
| 282 | if (!defined $data->{$key}) {
|
---|
| 283 | $data->{$key} = [];
|
---|
| 284 | }
|
---|
| 285 | if (defined $plain and $plain =~ /\w/) {
|
---|
| 286 | push @{ $data->{$key} }, $plain;
|
---|
| 287 | }
|
---|
| 288 | if (defined $form and $form =~ /\w/) {
|
---|
| 289 | push @{ $data->{$key} }, $form;
|
---|
| 290 | }
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
| 293 | # This sub is for debugging purposes
|
---|
| 294 | sub Display {
|
---|
| 295 | # metadataList
|
---|
| 296 |
|
---|
| 297 | print $data->{'creator'}."\n" if (defined $data->{'creator'});
|
---|
| 298 | print $data->{"maintainer"}."\n" if (defined $data->{"maintainer"});
|
---|
| 299 | print $data->{"public"}."\n" if (defined $data->{"public"});
|
---|
| 300 | print $data->{"defaultindex"}."\n" if (defined $data->{"defaultindex"});
|
---|
| 301 | print $data->{"defaultlevel"}."\n" if (defined $data->{"defaultlevel"});
|
---|
| 302 | print $data->{"buildtype"}."\n" if (defined $data->{"buildtype"});
|
---|
| 303 | print join(",",@{$data->{"searchtype"}})."\n" if (defined $data->{"searchtype"});
|
---|
| 304 | print join(",",@{$data->{'levels'}})."\n" if (defined $data->{'levels'});
|
---|
| 305 | print join(",",@{$data->{'indexsubcollections'}})."\n" if (defined $data->{'indexsubcollections'});
|
---|
| 306 | print join(",",@{$data->{'indexes'}})."\n" if (defined $data->{'indexes'});
|
---|
| 307 | print join(",",@{$data->{'indexoptions'}})."\n" if (defined $data->{'indexoptions'});
|
---|
| 308 | print join(",",@{$data->{'languages'}})."\n" if (defined $data->{'languages'});
|
---|
| 309 | print join(",",@{$data->{'languagemetadata'}})."\n" if (defined $data->{'languagemetadata'});
|
---|
| 310 |
|
---|
| 311 | if (defined $data->{'plugin'}) {
|
---|
| 312 | foreach $a (@{$data->{'plugin'}}) {
|
---|
| 313 | print join(",",@$a);
|
---|
| 314 | print "\n";
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 | if (defined $data->{'classify'}) {
|
---|
| 318 | print "Classifiers: \n";
|
---|
| 319 | map { print join(",",@$_)."\n"; } @{$data->{'classify'}};
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | if (defined $data->{'subcollection'}) {
|
---|
| 323 | foreach my $key (keys %{$data->{'subcollection'}}) {
|
---|
| 324 | print "subcollection ".$key." ".$data->{'subcollection'}->{$key}."\n";
|
---|
| 325 | }
|
---|
| 326 | }
|
---|
| 327 | }
|
---|
| 328 | sub Doctype {
|
---|
| 329 | my ($expat, $name, $sysid, $pubid, $internal) = @_;
|
---|
| 330 |
|
---|
| 331 | # allow the short-lived and badly named "GreenstoneDirectoryMetadata" files
|
---|
| 332 | # to be processed as well as the "DirectoryMetadata" files which should now
|
---|
| 333 | # be created by import.pl
|
---|
| 334 | die if ($name !~ /^(Greenstone)?DirectoryMetadata$/);
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | # This Char function overrides the one in XML::Parser::Stream to overcome a
|
---|
| 338 | # problem where $expat->{Text} is treated as the return value, slowing
|
---|
| 339 | # things down significantly in some cases.
|
---|
| 340 | sub Char {
|
---|
| 341 | if ($]<5.008) {
|
---|
| 342 | use bytes; # Necessary to prevent encoding issues with XML::Parser 2.31+ and Perl 5.6
|
---|
| 343 | }
|
---|
| 344 | $_[0]->{'Text'} .= $_[1];
|
---|
| 345 | return undef;
|
---|
| 346 | }
|
---|
| 347 | # Reads in the model collection configuration file, collectionConfig.xml,
|
---|
| 348 | # into a structure which complies with the one used by gs2 (i.e. one read
|
---|
| 349 | # in by &cfgread::read_cfg_file).
|
---|
| 350 | sub read_cfg_file {
|
---|
| 351 | my ($filename) = @_;
|
---|
| 352 | $data = {};
|
---|
| 353 | if ($filename !~ /collectionConfig\.xml$/ || !-f $filename) {
|
---|
| 354 | return undef;
|
---|
| 355 | }
|
---|
| 356 |
|
---|
| 357 | # create XML::Parser object for parsing metadata.xml files
|
---|
| 358 | my $parser;
|
---|
| 359 | if ($]<5.008) {
|
---|
| 360 | # Perl 5.6
|
---|
| 361 | $parser = new XML::Parser('Style' => 'Stream',
|
---|
| 362 | 'Handlers' => {'Char' => \&Char,
|
---|
| 363 | 'Doctype' => \&Doctype
|
---|
| 364 | });
|
---|
| 365 | }
|
---|
| 366 | else {
|
---|
| 367 | # Perl 5.8
|
---|
| 368 | $parser = new XML::Parser('Style' => 'Stream',
|
---|
| 369 | 'ProtocolEncoding' => 'ISO-8859-1',
|
---|
| 370 | 'Handlers' => {'Char' => \&Char,
|
---|
| 371 | 'Doctype' => \&Doctype
|
---|
| 372 | });
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | if (!open (COLCFG, $filename)) {
|
---|
| 376 | print STDERR "cfgread::read_cfg_file couldn't read the cfg file $filename\n";
|
---|
| 377 | } else {
|
---|
| 378 |
|
---|
| 379 | $parser->parsefile ($filename);# (COLCFG);
|
---|
| 380 | close (COLCFG);
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | #print "*** collectionConfig.xml internal ***\n";
|
---|
| 384 | #&Display;
|
---|
| 385 | return $data;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 |
|
---|
| 389 | sub write_line {
|
---|
| 390 | my ($filehandle, $line) = @_;
|
---|
| 391 | print $filehandle join ("", @$line), "\n";
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 | # Create the buildConfig.xml file for a specific collection
|
---|
| 395 | sub write_cfg_file {
|
---|
| 396 | # this sub is called in make_auxiliary_files() in basebuilder.pm
|
---|
| 397 | # the received args: $buildoutfile - destination file: buildConfig.xml
|
---|
| 398 | # $buildcfg - all build options, eg, disable_OAI
|
---|
| 399 | # $collectcfg - contents of collectionConfig.xml read in by read_cfg_file sub in cfgread4gs3.pm.
|
---|
| 400 | my ($buildoutfile, $buildcfg, $collectcfg, $disable_OAI) = @_;
|
---|
| 401 | my $line = [];
|
---|
| 402 |
|
---|
| 403 | if (!open (COLCFG, ">$buildoutfile")) {
|
---|
| 404 | print STDERR "cfgread4gs3::write_cfg_file couldn't write the build config file $buildoutfile\n";
|
---|
| 405 | die;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | &write_line('COLCFG', ["<buildConfig xmlns:gsf=\"http://www.greenstone.org/greenstone3/schema/ConfigFormat\">"]);
|
---|
| 409 |
|
---|
| 410 | # output building metadata to build config file
|
---|
| 411 | my $buildtype;
|
---|
| 412 | if (defined $buildcfg->{"buildtype"}) {
|
---|
| 413 | $buildtype = $buildcfg->{"buildtype"};
|
---|
| 414 | } else {
|
---|
| 415 | $buildtype = "mgpp";
|
---|
| 416 | }
|
---|
| 417 | my $numdocs;
|
---|
| 418 | if (defined $buildcfg->{"numdocs"}) {
|
---|
| 419 | $numdocs = $buildcfg->{"numdocs"};
|
---|
| 420 | }
|
---|
| 421 | &write_line('COLCFG', ["<metadataList>"]);
|
---|
| 422 | &write_line('COLCFG', ["<metadata name=\"numDocs\">", $numdocs, "</metadata>"]);
|
---|
| 423 | &write_line('COLCFG', ["<metadata name=\"buildType\">", $buildtype, "</metadata>"]);
|
---|
| 424 | &write_line('COLCFG', ["</metadataList>"]);
|
---|
| 425 |
|
---|
| 426 | my $service_type = "MGPP";
|
---|
| 427 | if ($buildtype eq "mg") {
|
---|
| 428 | $service_type = "MG";
|
---|
| 429 | } elsif ($buildtype eq "lucene") {
|
---|
| 430 | $service_type = "Lucene";
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | # output serviceRackList
|
---|
| 434 | &write_line('COLCFG', ["<serviceRackList>"]);
|
---|
| 435 |
|
---|
| 436 | # This serviceRack enables the collection to provide the oai metadata retrieve service, which is served by the OAIPMH.java class
|
---|
| 437 | # For each collection, we write the following serviceRack in the collection's buildConfig.xml file if the 'disable_OAI' argument is not checked in the GLI (or equivalently, a 'disable_OAI' flag is not specified on the command line). There are also other configurations in the OAIConfig.xml.
|
---|
| 438 | if ($disable_OAI == 0) {
|
---|
| 439 | &write_line('COLCFG', ["<serviceRack name=\"OAIPMH\">"]);
|
---|
| 440 | if (defined $buildcfg->{'indexstem'}) {
|
---|
| 441 | my $indexstem = $buildcfg->{'indexstem'};
|
---|
| 442 | &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
|
---|
| 443 | }
|
---|
| 444 | &write_line('COLCFG', ["</serviceRack>"]);
|
---|
| 445 | }
|
---|
| 446 | # do the search service
|
---|
| 447 | &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Search\">"]);
|
---|
| 448 | if (defined $buildcfg->{'indexstem'}) {
|
---|
| 449 | my $indexstem = $buildcfg->{'indexstem'};
|
---|
| 450 | &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
|
---|
| 451 | }
|
---|
| 452 |
|
---|
| 453 | #indexes
|
---|
| 454 | # maps index name to shortname
|
---|
| 455 | my $indexmap = {};
|
---|
| 456 | # keeps the order for indexes
|
---|
| 457 | my @indexlist = ();
|
---|
| 458 |
|
---|
| 459 | my $defaultindex = "";
|
---|
| 460 | my $first = 1;
|
---|
| 461 | my $maptype = "indexfieldmap";
|
---|
| 462 | if ($buildtype eq "mg") {
|
---|
| 463 | $maptype = "indexmap";
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | #map {print $_."\n"} keys %$buildcfg;
|
---|
| 467 |
|
---|
| 468 | if (defined $buildcfg->{$maptype}) {
|
---|
| 469 | my $indexmap_t = $buildcfg->{$maptype};
|
---|
| 470 | foreach my $i (@$indexmap_t) {
|
---|
| 471 | my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
|
---|
| 472 | $indexmap->{$k} = $v;
|
---|
| 473 | push @indexlist, $k;
|
---|
| 474 | if ($first) {
|
---|
| 475 | $defaultindex = $v;
|
---|
| 476 | $first = 0;
|
---|
| 477 | }
|
---|
| 478 | }
|
---|
| 479 | # now if the user has assigned a default index, we use it
|
---|
| 480 | if (defined $collectcfg->{"defaultindex"}) {
|
---|
| 481 | $defaultindex = $indexmap->{$collectcfg->{"defaultindex"}};
|
---|
| 482 | }
|
---|
| 483 |
|
---|
| 484 | } else {
|
---|
| 485 | print STDERR "$maptype not defined";
|
---|
| 486 | }
|
---|
| 487 | #for each index in indexList, write them out
|
---|
| 488 | &write_line('COLCFG', ["<indexList>"]);
|
---|
| 489 | foreach my $i (@indexlist) {
|
---|
| 490 | my $index = $indexmap->{$i};
|
---|
| 491 | &write_line('COLCFG', ["<index name=\"", $i, "\" ", "shortname=\"", $index, "\" />"]);
|
---|
| 492 | }
|
---|
| 493 | &write_line('COLCFG', ["</indexList>"]);
|
---|
| 494 |
|
---|
| 495 | # do default index only for mg
|
---|
| 496 | if ($buildtype eq "mg") {
|
---|
| 497 | &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 | # do indexOptionList
|
---|
| 501 | if ($buildtype eq "mg" || $buildtype eq "mgpp") {
|
---|
| 502 | &write_line('COLCFG', ["<indexOptionList>"]);
|
---|
| 503 | my $stemindexes = 3; # default is stem and casefold
|
---|
| 504 | if (defined $buildcfg->{'stemindexes'} && $buildcfg->{'stemindexes'} =~ /^\d+$/ ) {
|
---|
| 505 | $stemindexes = $buildcfg->{'stemindexes'};
|
---|
| 506 | }
|
---|
| 507 | &write_line('COLCFG', ["<indexOption name=\"stemIndexes\" value=\"", $stemindexes, "\" />"]);
|
---|
| 508 |
|
---|
| 509 | my $maxnumeric = 4; # default
|
---|
| 510 | if (defined $buildcfg->{'maxnumeric'} && $buildcfg->{'maxnumeric'} =~ /^\d+$/) {
|
---|
| 511 | $maxnumeric = $buildcfg->{'maxnumeric'};
|
---|
| 512 | }
|
---|
| 513 | &write_line('COLCFG', ["<indexOption name=\"maxnumeric\" value=\"", $maxnumeric, "\" />"]);
|
---|
| 514 | &write_line('COLCFG', ["</indexOptionList>"]);
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | # levelList
|
---|
| 518 | my $levelmap = {};
|
---|
| 519 | my @levellist = ();
|
---|
| 520 | my $default_search_level = "Doc";
|
---|
| 521 | my $default_retrieve_level = "Doc";
|
---|
| 522 | my $default_gdbm_level = "Doc";
|
---|
| 523 | $first = 1;
|
---|
| 524 | if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
|
---|
| 525 | if (defined $buildcfg->{'levelmap'}) {
|
---|
| 526 | my $levelmap_t = $buildcfg->{'levelmap'};
|
---|
| 527 | foreach my $l (@$levelmap_t) {
|
---|
| 528 | my ($key, $val) = $l =~ /^(.*)\-\>(.*)$/;
|
---|
| 529 | $levelmap->{$key} = $val;
|
---|
| 530 | push @levellist, $key;
|
---|
| 531 | if ($first) {
|
---|
| 532 | # let default search level follow the first level in the level list
|
---|
| 533 | $default_search_level = $val;
|
---|
| 534 | # retrieve/GDBM levels may get modified later if text level is defined
|
---|
| 535 | $default_retrieve_level = $val;
|
---|
| 536 | $default_gdbm_level = $val;
|
---|
| 537 | $first = 0;
|
---|
| 538 | }
|
---|
| 539 | }
|
---|
| 540 | }
|
---|
[14944] | 541 | # the default level assigned by the user is no longer ignored [Shaoqun], but the retrievel level stays the same.
|
---|
| 542 | #if (defined $collectcfg->{"defaultlevel"}) {
|
---|
| 543 | $default_search_level = $levelmap->{$collectcfg->{"defaultlevel"}};
|
---|
[14667] | 544 | # $default_retrieve_level = $default_search_level;
|
---|
| 545 | #}
|
---|
| 546 |
|
---|
| 547 | if (defined $buildcfg->{'textlevel'}) {
|
---|
| 548 | # let the retrieve/gdbm levels always follow the textlevel
|
---|
| 549 | $default_retrieve_level = $buildcfg->{'textlevel'};
|
---|
| 550 | $default_gdbm_level = $buildcfg->{'textlevel'};
|
---|
| 551 |
|
---|
| 552 | }
|
---|
| 553 | }
|
---|
| 554 | #for each level in levelList, write them out
|
---|
| 555 | if ($buildtype ne "mg") {
|
---|
| 556 | &write_line('COLCFG', ["<levelList>"]);
|
---|
| 557 | foreach my $lv (@levellist) {
|
---|
| 558 | my $level = $levelmap->{$lv};
|
---|
| 559 | &write_line('COLCFG', ["<level name=\"", $lv, "\" shortname=\"", $level, "\" />"]);
|
---|
| 560 | }
|
---|
| 561 | &write_line('COLCFG', ["</levelList>"]);
|
---|
| 562 | }
|
---|
| 563 | # add in defaultLevel as the same level as indexLevelList, making the reading job easier
|
---|
| 564 | if ($buildtype eq "lucene" || $buildtype eq "mgpp") {
|
---|
| 565 | &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_search_level, "\" />"]);
|
---|
| 566 | }
|
---|
| 567 | if ($buildtype eq "lucene" || $buildtype eq "mgpp") {
|
---|
| 568 | # make the GDBM level
|
---|
| 569 | &write_line('COLCFG', ["<defaultGDBMLevel shortname=\"", $default_gdbm_level, "\" />"]);
|
---|
| 570 | }
|
---|
| 571 | # do searchTypeList
|
---|
| 572 | if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
|
---|
| 573 | &write_line('COLCFG', ["<searchTypeList>"]);
|
---|
| 574 |
|
---|
| 575 | if (defined $buildcfg->{"searchtype"}) {
|
---|
| 576 | my $searchtype_t = $buildcfg->{"searchtype"};
|
---|
| 577 | foreach my $s (@$searchtype_t) {
|
---|
| 578 | &write_line('COLCFG', ["<searchType name=\"", $s, "\" />"]);
|
---|
| 579 | }
|
---|
| 580 | } else {
|
---|
| 581 | &write_line('COLCFG', ["<searchType name=\"plain\" />"]);
|
---|
| 582 | &write_line('COLCFG', ["<searchType name=\"form\" />"]);
|
---|
| 583 | }
|
---|
| 584 | &write_line('COLCFG', ["</searchTypeList>"]);
|
---|
| 585 | }
|
---|
| 586 |
|
---|
| 587 | # do indexLanguageList [in collect.cfg: languages; in build.cfg: languagemap]
|
---|
| 588 | $first = 1;
|
---|
| 589 | my $default_lang = "";
|
---|
| 590 | my $default_lang_short = "";
|
---|
| 591 | if (defined $buildcfg->{"languagemap"}) {
|
---|
| 592 | &write_line('COLCFG', ["<indexLanguageList>"]);
|
---|
| 593 |
|
---|
| 594 | my $langmap_t = $buildcfg->{"languagemap"};
|
---|
| 595 | foreach my $l (@$langmap_t) {
|
---|
| 596 | my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
|
---|
| 597 |
|
---|
| 598 | &write_line('COLCFG', ["<indexLanguage name=\"", $k, "\" shortname=\"", $v, "\" />"]);
|
---|
| 599 | if ($first) {
|
---|
| 600 | $default_lang = $k; #name
|
---|
| 601 | $default_lang_short = $v; #shortname
|
---|
| 602 | $first = 0;
|
---|
| 603 | }
|
---|
| 604 | }
|
---|
| 605 |
|
---|
| 606 | &write_line('COLCFG', ["</indexLanguageList>"]);
|
---|
| 607 | # now if the user has assigned a default language (as "en", "ru" etc.)
|
---|
| 608 | if (defined $collectcfg->{"defaultlanguage"}) {
|
---|
| 609 | $default_lang = $collectcfg->{"defaultlanguage"};
|
---|
| 610 | }
|
---|
| 611 | &write_line('COLCFG', ["<defaultIndexLanguage name=\"", $default_lang, "\" shortname=\"", $default_lang_short, "\" />"]);
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 |
|
---|
| 615 | # do indexSubcollectionList
|
---|
| 616 | my $default_subcol = "";# make it in sub scope to be used in the concatenation
|
---|
| 617 | if (defined $buildcfg->{'subcollectionmap'}) {
|
---|
| 618 | &write_line('COLCFG', ["<indexSubcollectionList>"]);
|
---|
| 619 | my $subcolmap = {};
|
---|
| 620 | my @subcollist = ();
|
---|
| 621 | $first = 1;
|
---|
| 622 | my $subcolmap_t = $buildcfg->{'subcollectionmap'};
|
---|
| 623 | foreach my $l (@$subcolmap_t) {
|
---|
| 624 | my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
|
---|
| 625 | $subcolmap->{$k} = $v;
|
---|
| 626 | push @subcollist, $k;
|
---|
| 627 | if ($first) {
|
---|
| 628 | $default_subcol = $v;
|
---|
| 629 | $first = 0;
|
---|
| 630 | }
|
---|
| 631 | }
|
---|
| 632 | foreach my $sl (@subcollist) {
|
---|
| 633 | my $subcol = $subcolmap->{$sl};
|
---|
| 634 | &write_line('COLCFG', ["<indexSubcollection name=\"", $sl, "\" shortname=\"", $subcol, "\" />"]);
|
---|
| 635 | }
|
---|
| 636 |
|
---|
| 637 | &write_line('COLCFG', ["</indexSubcollectionList>"]);
|
---|
| 638 | &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
|
---|
| 639 | }
|
---|
| 640 |
|
---|
| 641 | # close off search service
|
---|
| 642 | &write_line('COLCFG', ["</serviceRack>"]);
|
---|
| 643 |
|
---|
| 644 | # do the retrieve service
|
---|
| 645 | &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Retrieve\">"]);
|
---|
| 646 |
|
---|
| 647 | # do default index
|
---|
| 648 | if (defined $buildcfg->{"languagemap"}) {
|
---|
| 649 | &write_line('COLCFG', ["<defaultIndexLanguage shortname=\"", $default_lang, "\" />"]);
|
---|
| 650 | }
|
---|
| 651 | if (defined $buildcfg->{'subcollectionmap'}) {
|
---|
| 652 | &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
|
---|
| 653 | }
|
---|
| 654 | if ($buildtype eq "mg") {
|
---|
| 655 | &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
|
---|
| 656 | }
|
---|
| 657 |
|
---|
| 658 | if (defined $buildcfg->{'indexstem'}) {
|
---|
| 659 | my $indexstem = $buildcfg->{'indexstem'};
|
---|
| 660 | &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
|
---|
| 661 | }
|
---|
| 662 | if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
|
---|
| 663 | &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_retrieve_level, "\" />"]);
|
---|
| 664 | }
|
---|
| 665 | &write_line('COLCFG', ["</serviceRack>"]);
|
---|
| 666 |
|
---|
| 667 | # do the browse service
|
---|
| 668 | my $count = 1;
|
---|
| 669 | my $phind = 0;
|
---|
| 670 | my $started_classifiers = 0;
|
---|
| 671 |
|
---|
| 672 | my $classifiers = $collectcfg->{"classify"};
|
---|
| 673 | foreach my $cl (@$classifiers) {
|
---|
| 674 | my $name = "CL$count";
|
---|
| 675 | $count++;
|
---|
| 676 | my ($classname) = @$cl[0];
|
---|
| 677 | if ($classname =~ /^phind$/i) {
|
---|
| 678 | $phind=1;
|
---|
| 679 | #should add it into coll config classifiers
|
---|
| 680 | next;
|
---|
| 681 | }
|
---|
| 682 |
|
---|
| 683 | if (not $started_classifiers) {
|
---|
| 684 | &write_line('COLCFG', ["<serviceRack name=\"GS2Browse\">"]);
|
---|
| 685 | if (defined $buildcfg->{'indexstem'}) {
|
---|
| 686 | my $indexstem = $buildcfg->{'indexstem'};
|
---|
| 687 | &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
|
---|
| 688 | }
|
---|
| 689 | &write_line('COLCFG', ["<classifierList>"]);
|
---|
| 690 | $started_classifiers = 1;
|
---|
| 691 | }
|
---|
| 692 | my $content = ''; #use buttonname first, then metadata
|
---|
| 693 | if ($classname eq "DateList") {
|
---|
| 694 | $content = "Date";
|
---|
| 695 | } else {
|
---|
| 696 | for (my $j=0; $j<scalar(@$cl); $j++) {
|
---|
| 697 | my $arg = @$cl[$j];
|
---|
| 698 | if ($arg eq "-buttonname"){
|
---|
| 699 | $content = @$cl[$j+1];
|
---|
| 700 | last;
|
---|
| 701 | } elsif ($arg eq "-metadata") {
|
---|
| 702 | $content = @$cl[$j+1];
|
---|
| 703 | }
|
---|
| 704 |
|
---|
| 705 | }
|
---|
| 706 | }
|
---|
| 707 | &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" />"]);
|
---|
| 708 | }
|
---|
| 709 | if ($started_classifiers) {
|
---|
| 710 | # end the classifiers
|
---|
| 711 | &write_line('COLCFG', ["</classifierList>"]);
|
---|
| 712 | # close off the Browse service
|
---|
| 713 | &write_line('COLCFG', ["</serviceRack>"]);
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | # the phind classifier is a separate service
|
---|
| 717 | if ($phind) {
|
---|
| 718 | # if phind classifier
|
---|
| 719 | &write_line('COLCFG', ["<serviceRack name=\"PhindPhraseBrowse\" />"]);
|
---|
[14741] | 720 | }
|
---|
| 721 |
|
---|
| 722 | my $flaxActivities = $collectcfg->{"flaxActivity"};
|
---|
| 723 | foreach my $fa (@$flaxActivities) {
|
---|
| 724 | if(defined $fa and @$fa[0] =~ /\w/ and @$fa[1] =~ /\w/ and @$fa[2] =~ /\w/ and @$fa[3] =~ /\w/ ) {
|
---|
| 725 | &write_line('COLCFG', ["<serviceRack ", @$fa[0], "=\"", @$fa[1], "\" ", @$fa[2], "=\"", @$fa[3], "\" />"]);
|
---|
| 726 | }
|
---|
| 727 | }
|
---|
| 728 |
|
---|
[14667] | 729 | &write_line('COLCFG', ["</serviceRackList>"]);
|
---|
| 730 | &write_line('COLCFG', ["</buildConfig>"]);
|
---|
| 731 |
|
---|
| 732 | close (COLCFG);
|
---|
| 733 | }
|
---|
| 734 |
|
---|
| 735 |
|
---|
| 736 | #########################################################
|
---|
| 737 |
|
---|
| 738 | 1;
|
---|