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

Last change on this file since 15619 was 15619, checked in by ak19, 16 years ago

Reads collectionConfig.xml file's collection name and description as collectionmeta for GS3, just as these elements were part of the collectionmeta for Greenstone 2

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