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