source: gsdl/trunk/perllib/cfgread4gs3.pm@ 14741

Last change on this file since 14741 was 14741, checked in by xiao, 16 years ago

modify to read flaxActivity elements and write out as serviceRack to buildConfig.xml

  • Property svn:keywords set to Author Date Id Revision
File size: 24.8 KB
RevLine 
[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
28package cfgread4gs3;
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 descrepency between gs2 and gs3.
63my $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.
86my $data = {};
87
88my $repeatedBlock = q/^(browse|pluginList)$/;
89
90# use those unique attribute values to locate the text within the elements
91# creator, public, maintainer.
92my $currentLocation = "";
93my $stringexp = q/^(creator|maintainer|public)$/;
94
95my $currentLevel = "";
96
97# Count the elements with same name within the same block
98# ("plugin", "option")
99my $currentIndex = 0;
100my $arrayexp = q/^(index|level|indexSubcollection|indexLanguage)$/;
101my $arrayarrayexp= q/^(plugin|classifier)$/;
[14741]102
[14667]103my $defaults = q/^(defaultIndex|defaultLevel|defaultIndexLanguage|languageMetadata)$/;
104
105sub 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
253sub 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
267sub 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
294sub 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}
328sub 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.
340sub 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).
350sub 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
389sub write_line {
390 my ($filehandle, $line) = @_;
391 print $filehandle join ("", @$line), "\n";
392}
393
394# Create the buildConfig.xml file for a specific collection
395sub 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 }
541 # even if the user has assigned a default level, we ignore it. Why?
542 # I don't know, but it seems it's the way how the serving works
543 #if (defined $collectcfg->{"defaultlevel"}) {
544 # $default_search_level = $levelmap->{$collectcfg->{"defaultlevel"}};
545 # $default_retrieve_level = $default_search_level;
546 #}
547
548 if (defined $buildcfg->{'textlevel'}) {
549 # let the retrieve/gdbm levels always follow the textlevel
550 $default_retrieve_level = $buildcfg->{'textlevel'};
551 $default_gdbm_level = $buildcfg->{'textlevel'};
552
553 }
554 }
555 #for each level in levelList, write them out
556 if ($buildtype ne "mg") {
557 &write_line('COLCFG', ["<levelList>"]);
558 foreach my $lv (@levellist) {
559 my $level = $levelmap->{$lv};
560 &write_line('COLCFG', ["<level name=\"", $lv, "\" shortname=\"", $level, "\" />"]);
561 }
562 &write_line('COLCFG', ["</levelList>"]);
563 }
564 # add in defaultLevel as the same level as indexLevelList, making the reading job easier
565 if ($buildtype eq "lucene" || $buildtype eq "mgpp") {
566 &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_search_level, "\" />"]);
567 }
568 if ($buildtype eq "lucene" || $buildtype eq "mgpp") {
569 # make the GDBM level
570 &write_line('COLCFG', ["<defaultGDBMLevel shortname=\"", $default_gdbm_level, "\" />"]);
571 }
572 # do searchTypeList
573 if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
574 &write_line('COLCFG', ["<searchTypeList>"]);
575
576 if (defined $buildcfg->{"searchtype"}) {
577 my $searchtype_t = $buildcfg->{"searchtype"};
578 foreach my $s (@$searchtype_t) {
579 &write_line('COLCFG', ["<searchType name=\"", $s, "\" />"]);
580 }
581 } else {
582 &write_line('COLCFG', ["<searchType name=\"plain\" />"]);
583 &write_line('COLCFG', ["<searchType name=\"form\" />"]);
584 }
585 &write_line('COLCFG', ["</searchTypeList>"]);
586 }
587
588 # do indexLanguageList [in collect.cfg: languages; in build.cfg: languagemap]
589 $first = 1;
590 my $default_lang = "";
591 my $default_lang_short = "";
592 if (defined $buildcfg->{"languagemap"}) {
593 &write_line('COLCFG', ["<indexLanguageList>"]);
594
595 my $langmap_t = $buildcfg->{"languagemap"};
596 foreach my $l (@$langmap_t) {
597 my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
598
599 &write_line('COLCFG', ["<indexLanguage name=\"", $k, "\" shortname=\"", $v, "\" />"]);
600 if ($first) {
601 $default_lang = $k; #name
602 $default_lang_short = $v; #shortname
603 $first = 0;
604 }
605 }
606
607 &write_line('COLCFG', ["</indexLanguageList>"]);
608 # now if the user has assigned a default language (as "en", "ru" etc.)
609 if (defined $collectcfg->{"defaultlanguage"}) {
610 $default_lang = $collectcfg->{"defaultlanguage"};
611 }
612 &write_line('COLCFG', ["<defaultIndexLanguage name=\"", $default_lang, "\" shortname=\"", $default_lang_short, "\" />"]);
613 }
614
615
616 # do indexSubcollectionList
617 my $default_subcol = "";# make it in sub scope to be used in the concatenation
618 if (defined $buildcfg->{'subcollectionmap'}) {
619 &write_line('COLCFG', ["<indexSubcollectionList>"]);
620 my $subcolmap = {};
621 my @subcollist = ();
622 $first = 1;
623 my $subcolmap_t = $buildcfg->{'subcollectionmap'};
624 foreach my $l (@$subcolmap_t) {
625 my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
626 $subcolmap->{$k} = $v;
627 push @subcollist, $k;
628 if ($first) {
629 $default_subcol = $v;
630 $first = 0;
631 }
632 }
633 foreach my $sl (@subcollist) {
634 my $subcol = $subcolmap->{$sl};
635 &write_line('COLCFG', ["<indexSubcollection name=\"", $sl, "\" shortname=\"", $subcol, "\" />"]);
636 }
637
638 &write_line('COLCFG', ["</indexSubcollectionList>"]);
639 &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
640 }
641
642 # close off search service
643 &write_line('COLCFG', ["</serviceRack>"]);
644
645 # do the retrieve service
646 &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Retrieve\">"]);
647
648 # do default index
649 if (defined $buildcfg->{"languagemap"}) {
650 &write_line('COLCFG', ["<defaultIndexLanguage shortname=\"", $default_lang, "\" />"]);
651 }
652 if (defined $buildcfg->{'subcollectionmap'}) {
653 &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
654 }
655 if ($buildtype eq "mg") {
656 &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
657 }
658
659 if (defined $buildcfg->{'indexstem'}) {
660 my $indexstem = $buildcfg->{'indexstem'};
661 &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
662 }
663 if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
664 &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_retrieve_level, "\" />"]);
665 }
666 &write_line('COLCFG', ["</serviceRack>"]);
667
668 # do the browse service
669 my $count = 1;
670 my $phind = 0;
671 my $started_classifiers = 0;
672
673 my $classifiers = $collectcfg->{"classify"};
674 foreach my $cl (@$classifiers) {
675 my $name = "CL$count";
676 $count++;
677 my ($classname) = @$cl[0];
678 if ($classname =~ /^phind$/i) {
679 $phind=1;
680 #should add it into coll config classifiers
681 next;
682 }
683
684 if (not $started_classifiers) {
685 &write_line('COLCFG', ["<serviceRack name=\"GS2Browse\">"]);
686 if (defined $buildcfg->{'indexstem'}) {
687 my $indexstem = $buildcfg->{'indexstem'};
688 &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);
689 }
690 &write_line('COLCFG', ["<classifierList>"]);
691 $started_classifiers = 1;
692 }
693 my $content = ''; #use buttonname first, then metadata
694 if ($classname eq "DateList") {
695 $content = "Date";
696 } else {
697 for (my $j=0; $j<scalar(@$cl); $j++) {
698 my $arg = @$cl[$j];
699 if ($arg eq "-buttonname"){
700 $content = @$cl[$j+1];
701 last;
702 } elsif ($arg eq "-metadata") {
703 $content = @$cl[$j+1];
704 }
705
706 }
707 }
708 &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" />"]);
709 }
710 if ($started_classifiers) {
711 # end the classifiers
712 &write_line('COLCFG', ["</classifierList>"]);
713 # close off the Browse service
714 &write_line('COLCFG', ["</serviceRack>"]);
715 }
716
717 # the phind classifier is a separate service
718 if ($phind) {
719 # if phind classifier
720 &write_line('COLCFG', ["<serviceRack name=\"PhindPhraseBrowse\" />"]);
[14741]721 }
722
723 my $flaxActivities = $collectcfg->{"flaxActivity"};
724 foreach my $fa (@$flaxActivities) {
725 if(defined $fa and @$fa[0] =~ /\w/ and @$fa[1] =~ /\w/ and @$fa[2] =~ /\w/ and @$fa[3] =~ /\w/ ) {
726 &write_line('COLCFG', ["<serviceRack ", @$fa[0], "=\"", @$fa[1], "\" ", @$fa[2], "=\"", @$fa[3], "\" />"]);
727 }
728 }
729
[14667]730 &write_line('COLCFG', ["</serviceRackList>"]);
731 &write_line('COLCFG', ["</buildConfig>"]);
732
733 close (COLCFG);
734 }
735
736
737#########################################################
738
7391;
Note: See TracBrowser for help on using the repository browser.