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