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

Last change on this file since 14558 was 14558, checked in by shaoqun, 14 years ago

make it parse the plugout element in the collectionConfig.xml

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