root/gsdl/trunk/perllib/cfgread4gs3.pm @ 15685

Revision 15685, 26.9 KB (checked in by mdewsnip, 11 years ago)

(Adding new DB support) Changed all the "gdbm_level"s to "db_level".

  • Property svn:keywords set to Author Date Id Revision
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";
[15685]579    my $default_db_level = "Doc";
[15600]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;
[15685]591            # retrieve/database levels may get modified later if text level is defined
[15600]592            $default_retrieve_level = $val;
[15685]593            $default_db_level = $val;
[15600]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'}) {
[15685]605       # let the retrieve/database levels always follow the textlevel
[15600]606           $default_retrieve_level = $buildcfg->{'textlevel'};
[15685]607       $default_db_level = $buildcfg->{'textlevel'};
[15600]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") {
[15685]625        &write_line('COLCFG', ["<defaultDBLevel shortname=\"", $default_db_level, "\" />"]);
[15600]626    }
627    # do searchTypeList
628    if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
629      &write_line('COLCFG', ["<searchTypeList>"]);
630     
631      if (defined $buildcfg->{"searchtype"}) {
632      my $searchtype_t = $buildcfg->{"searchtype"};
633      foreach my $s (@$searchtype_t) {
634      &write_line('COLCFG', ["<searchType name=\"", $s, "\" />"]);
635    }
636      } else {
637      &write_line('COLCFG', ["<searchType name=\"plain\" />"]);
638      &write_line('COLCFG', ["<searchType name=\"form\" />"]);
639      }
640      &write_line('COLCFG', ["</searchTypeList>"]);
641    }
642
643    # do indexLanguageList [in collect.cfg: languages; in build.cfg: languagemap]
644    $first = 1;
645    my $default_lang = "";
646    my $default_lang_short = "";
647    if (defined $buildcfg->{"languagemap"}) {
648      &write_line('COLCFG', ["<indexLanguageList>"]);
649
650      my $langmap_t = $buildcfg->{"languagemap"};
651      foreach my $l (@$langmap_t) {
652    my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
653
654    &write_line('COLCFG', ["<indexLanguage name=\"", $k, "\" shortname=\"", $v, "\" />"]);
655    if ($first) {
656      $default_lang = $k; #name
657      $default_lang_short = $v; #shortname
658      $first = 0;
659    }
660      }
661
662      &write_line('COLCFG', ["</indexLanguageList>"]);
663      # now if the user has assigned a default language (as "en", "ru" etc.)
664      if (defined $collectcfg->{"defaultlanguage"}) {
665    $default_lang = $collectcfg->{"defaultlanguage"};
666      }
667      &write_line('COLCFG', ["<defaultIndexLanguage name=\"", $default_lang, "\" shortname=\"", $default_lang_short, "\" />"]);
668    }
669
670
671    # do indexSubcollectionList
672    my $default_subcol = "";# make it in sub scope to be used in the concatenation
673    if (defined $buildcfg->{'subcollectionmap'}) {
674      &write_line('COLCFG', ["<indexSubcollectionList>"]);
675      my $subcolmap = {};
676      my @subcollist = ();
677      $first = 1;
678      my $subcolmap_t = $buildcfg->{'subcollectionmap'};
679      foreach my $l (@$subcolmap_t) {
680    my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
681    $subcolmap->{$k} = $v;
682    push @subcollist, $k;
683    if ($first) {
684      $default_subcol = $v;
685      $first = 0;
686    }
687      }
688      foreach my $sl (@subcollist) {
689    my $subcol = $subcolmap->{$sl};
690    &write_line('COLCFG', ["<indexSubcollection name=\"", $sl, "\" shortname=\"", $subcol, "\" />"]);
691      }
692
693      &write_line('COLCFG', ["</indexSubcollectionList>"]);
694      &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
695    }
696     
697    # close off search service
698    &write_line('COLCFG', ["</serviceRack>"]);
699
700    # do the retrieve service
701    &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Retrieve\">"]);
702
703    # do default index
704    if (defined $buildcfg->{"languagemap"}) {
705    &write_line('COLCFG', ["<defaultIndexLanguage shortname=\"", $default_lang, "\" />"]);
706    }
707    if (defined $buildcfg->{'subcollectionmap'}) {
708    &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
709    }
710    if ($buildtype eq "mg") {
711      &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
712    }
713
714    if (defined $buildcfg->{'indexstem'}) {
715      my $indexstem = $buildcfg->{'indexstem'};
716      &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);     
717    }
718    if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
719      &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_retrieve_level, "\" />"]);
720    }
721    &write_line('COLCFG', ["</serviceRack>"]);
722
723    # do the browse service
724    my $count = 1;
725    my $phind = 0;
726    my $started_classifiers = 0;
727
728    my $classifiers = $collectcfg->{"classify"};
729    foreach my $cl (@$classifiers) {
730      my $name = "CL$count";
731      $count++;
732      my ($classname) = @$cl[0];
733      if ($classname =~ /^phind$/i) {
734    $phind=1;
735    #should add it into coll config classifiers
736    next;
737      }
738     
739      if (not $started_classifiers) {
740    &write_line('COLCFG', ["<serviceRack name=\"GS2Browse\">"]);
741    if (defined $buildcfg->{'indexstem'}) {
742      my $indexstem = $buildcfg->{'indexstem'};
743      &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);     
744    }
745    &write_line('COLCFG', ["<classifierList>"]);       
746    $started_classifiers = 1;
747      }
748      my $content = ''; #use buttonname first, then metadata
749      if ($classname eq "DateList") {
750    $content = "Date";
751      } else {
752    for (my $j=0; $j<scalar(@$cl); $j++) {
753      my $arg = @$cl[$j];
754      if ($arg eq "-buttonname"){
755        $content = @$cl[$j+1];
756        last;
757      } elsif ($arg eq "-metadata") {
758        $content = @$cl[$j+1];
759      }
760     
761    }
762      }
763      &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" />"]);
764    }     
765    if ($started_classifiers) {
766      # end the classifiers
767      &write_line('COLCFG', ["</classifierList>"]);
768      # close off the Browse service
769      &write_line('COLCFG', ["</serviceRack>"]);
770    }
771   
772    # the phind classifier is a separate service
773    if ($phind) {
774    # if phind classifier
775    &write_line('COLCFG', ["<serviceRack name=\"PhindPhraseBrowse\" />"]);
776    }
777
778    my $flaxActivities = $collectcfg->{"flaxActivity"};
779    foreach my $fa (@$flaxActivities) {
[15068]780        # Six elements of the array for three attribute name/value pairs: name, desid, and lang.
[15600]781        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]782            &write_line('COLCFG', ["<serviceRack type=\"flaxActivity\" ", @$fa[0], "=\"", @$fa[1], "\" ", @$fa[2], "=\"", @$fa[3], "\" ", @$fa[4], "=\"", @$fa[5], "\" />"]);
[15600]783        }
[14741]784    } 
[15600]785   
786    &write_line('COLCFG', ["</serviceRackList>"]);
787    &write_line('COLCFG', ["</buildConfig>"]);
788
789    close (COLCFG);
790  }
791
792
793#########################################################
794
7951;
Note: See TracBrowser for help on using the browser.