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