source: gsdl/trunk/perllib/buildConfigxml.pm@ 20096

Last change on this file since 20096 was 20096, checked in by kjdon, 15 years ago

package name changes

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