source: trunk/gsdl3/bin/script/convert_coll_from_gs2.pl@ 13228

Last change on this file since 13228 was 13228, checked in by kjdon, 17 years ago

added in support for Lucene collections

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 21.9 KB
Line 
1#!/usr/bin/perl -w
2
3BEGIN {
4 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
5 die "GSDL3HOME not set\n" unless defined $ENV{'GSDL3HOME'};
6 die "GSDL3SRCHOME not set\n" unless defined $ENV{'GSDL3SRCHOME'};
7 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
8 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
9 unshift (@INC, "$ENV{'GSDL3SRCHOME'}/lib/perl/cpan");
10}
11
12use colcfg;
13use util;
14use parsargv;
15use FileHandle;
16use XML::Writer;
17#can't get this to work on windows
18#use GDBM_File;
19
20use strict;
21
22&main();
23sub print_usage() {
24 print STDOUT "Usage: convert_coll_from_gs2.pl [options] coll-name\n";
25 print STDOUT "options:\n";
26
27 print STDOUT " -collectdir Directory where collection lives.\n";
28 print STDOUT " -verbosity Controls the amount of output.\n";
29 print STDOUT " -defaultlang The language that is considered the default (for display text etc). defaults to 'en'\n\n";
30}
31
32sub main {
33
34 my ($defaultlang, $verbosity, $collectdir);
35 # note that no defaults are passed for most options as they're set
36 # later (after we check the collect.cfg file)
37 if (!&parsargv::parse(\@ARGV,
38 'verbosity/\d+/', \$verbosity,
39 'collectdir/.*/', \$collectdir,
40 'defaultlang/.*/', \$defaultlang)) {
41 &print_usage();
42 die "\n";
43 }
44
45 # get and check the collection name
46 my ($collection) = @ARGV;
47 if (!defined($collection) || $collection eq "") {
48 die "No collection specified\n";
49 }
50 if ($collection eq "gs2model") {
51 die "You cant convert the model collection\n";
52 }
53
54 if (!defined $collectdir || $collectdir eq "") {
55 $collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect");
56 }
57
58 if (!defined $defaultlang || $defaultlang eq "") {
59 $defaultlang = 'en';
60 }
61 # add on the coll name
62 $collectdir = &util::filename_cat ($collectdir, $collection);
63
64 my $collconfigfilename = &util::filename_cat ($collectdir, "etc", "collect.cfg");
65 print STDOUT "coll config=$collconfigfilename\n";
66 my $collectcfg;
67 if (-e $collconfigfilename) {
68 $collectcfg = &colcfg::read_collect_cfg ($collconfigfilename);
69
70 } else {
71 print STDERR "collect.cfg not found!!";
72 die "\n";
73 }
74
75
76 my $buildconfigfilename = &util::filename_cat ($collectdir, "index", "build.cfg");
77 my $buildcfg;
78 if (-e $buildconfigfilename) {
79 $buildcfg = &colcfg::read_build_cfg ($buildconfigfilename);
80
81 } else {
82 print STDERR "build.cfg not found!!";
83 die "\n";
84 }
85
86
87
88 my $colloutfile = &util::filename_cat ($collectdir, "etc", "collectionConfig.xml");
89 if (-e $colloutfile) {
90 print STDOUT "collectionConfig file already exists! overwriting it!\n";
91
92 }
93
94 my $buildoutfile = &util::filename_cat ($collectdir, "index", "buildConfig.xml");
95 if (-e $buildoutfile) {
96 print STDOUT "buildConfig file already exists! overwriting it!\n";
97
98 }
99
100# my $db_file = &util::filename_cat ($collectdir, "index", "text", "$collection.ldb");
101 my $database;
102# if (-e $db_file) {
103# $database = &open_database($db_file);
104# } else {
105# print STDERR "gdbm database file $db_file not found!!";
106# die "\n";
107# }
108
109 my $buildtype;
110 if (defined $buildcfg->{'buildtype'}) {
111 $buildtype = $buildcfg->{'buildtype'};
112 } else {
113 $buildtype = 'mg';
114 }
115
116 my $indexstem = undef;
117 if (defined $buildcfg->{'indexstem'}) {
118 $indexstem = $buildcfg->{'indexstem'};
119 }
120
121 my $buildoutput = new IO::File(">$buildoutfile");
122 my $buildwriter = new XML::Writer(OUTPUT => $buildoutput, NEWLINES => 1);
123
124 $buildwriter->startTag('buildConfig', 'xmlns:gsf'=>"http://www.greenstone.org/greenstone3/schema/ConfigFormat");
125
126 my $colloutput = new IO::File(">$colloutfile");
127 my $collwriter = new XML::Writer(OUTPUT => $colloutput, NEWLINES => 1);
128
129 $collwriter->startTag('collectionConfig', 'xmlns:gsf'=>"http://www.greenstone.org/greenstone3/schema/ConfigFormat", 'xmlns:xsl'=>'http://www.w3.org/1999/XSL/Transform');
130
131 #output the collection metadata to the collectionConfig file
132 $collwriter->startTag('metadataList');
133
134 my $creator = $collectcfg->{'creator'};
135 &output_metadata($collwriter, 'creator', $creator);
136 $collwriter->endTag('metadataList');
137
138 #output the display collectionmeta to collectionConfig.xml
139
140 my $collectionmeta = $collectcfg->{'collectionmeta'};
141 if (defined $collectionmeta) {
142 my %name_map = ('collectionname', 'name',
143 'collectionextra', 'description',
144 'iconcollection', 'icon',
145 'iconcollectionsmall', 'smallicon');
146
147 $collwriter->startTag('displayItemList');
148 foreach my $entry ( keys %$collectionmeta) {
149 if (defined $name_map{$entry}) {
150 my $name= $name_map{$entry};
151 foreach my $lang (keys %{$collectionmeta->{$entry}}) {
152 my $value = $collectionmeta->{$entry}->{$lang};
153 if ($entry =~ /^icon/) {
154 $value = format_icon_value($value);
155 } else {
156 $value = tidy_up_metadata($value);
157 }
158 &output_display($collwriter, $name, $lang, $value);
159 }
160 }
161 }
162 $collwriter->endTag('displayItemList');
163 }
164
165 # output building metadata to build config file
166 my $numdocs = $buildcfg->{'numdocs'};
167 $buildwriter->startTag('metadataList');
168 &output_metadata($buildwriter, 'numDocs', $numdocs);
169 &output_metadata($buildwriter, 'buildType', $buildtype);
170 $buildwriter->endTag('metadataList');
171
172
173 #indexes
174 my $indexmap = {};
175 my $firstindex = "";
176 my $first = 1;
177 if (defined $buildcfg->{'indexmap'}) {
178 my $indexmap_t = $buildcfg->{'indexmap'};
179 foreach my $i (@$indexmap_t) {
180 my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
181 $indexmap->{$k} = $v;
182 if ($first) {
183 $firstindex = $v;
184 $first = 0;
185 }
186 }
187 } else {
188 print STDERR "indexmap not defined";
189 }
190 my $defaultindex;
191 if ($buildtype eq "mg") {
192 if (defined $collectcfg->{'defaultindex'}) {
193 $defaultindex = $collectcfg->{'defaultindex'};
194 $defaultindex = $indexmap->{$defaultindex};
195 } else {
196 # use the first one
197 $defaultindex = $firstindex;
198 }
199 }
200 elsif ($buildtype eq "mgpp") {
201 $defaultindex = "idx";
202 }
203 elsif ($buildtype eq "lucene") {
204 # lucene not implemented yet
205 $defaultindex = "idx";
206 }
207
208 # format stuff
209 my $format = $collectcfg->{'format'};
210
211 #output the search stuff to coll cfg
212 $collwriter->startTag('search');
213 foreach my $i (keys %$indexmap) {
214 my $shortname = $indexmap->{$i};
215 $collwriter->startTag('index', 'name'=>$shortname);
216 #find the coll meta stuff
217 my $indexdisplay = ".$i";
218 foreach my $lang (keys %{$collectionmeta->{$indexdisplay}}) {
219 my $value = $collectionmeta->{$indexdisplay}->{$lang};
220 output_display($collwriter, 'name', $lang, $value);
221 }
222 $collwriter->endTag('index');
223
224 }
225
226 # add in the format stuff
227 if (defined $format->{'SearchVList'}) {
228
229 $collwriter->startTag('format');
230 write_format($collwriter, $format->{'SearchVList'}, "document");
231 $collwriter->endTag('format');
232 }
233 elsif (defined $format->{'VList'}) {
234 $collwriter->startTag('format');
235 write_format($collwriter, $format->{'VList'}, "document");
236 $collwriter->endTag('format');
237 }
238
239 $collwriter->endTag('search');
240
241 $buildwriter->startTag('serviceRackList');
242
243 my @levels = ();
244 my $defaultlevel;
245 my $service_name = "";
246 #do the retrieve service
247 # assume mgpp or mg
248 if ($buildtype eq 'mgpp' || $buildtype eq 'lucene') {
249 #for each level
250 if (defined $buildcfg->{'indexlevels'}) {
251 push @levels, @{$buildcfg->{'indexlevels'}};
252
253 if (defined $buildcfg->{'textlevel'}) {
254 $defaultlevel = $buildcfg->{'textlevel'};
255 } else {
256 $defaultlevel = $levels[0];
257 }
258 } else { #use levels from collect.cfg - must be an old collection
259 @levels = ('Document');
260 $defaultlevel = 'Document';
261 if (defined $collectcfg->{'levels'}) {
262 foreach my $l (@{$collectcfg->{'levels'}}) {
263 if ($l eq "Section") {
264 $defaultlevel = 'Section';
265 }
266 push @levels, $l;
267 }
268 }
269 }
270 if ($buildtype eq 'mgpp') {
271 $service_name = "MGPP";
272 } else {
273 $service_name = "Lucene";
274 }
275 $buildwriter->startTag('serviceRack', 'name'=>"GS2".$service_name."Retrieve");
276 $buildwriter->emptyTag('defaultLevel', 'name'=>$defaultlevel);
277
278
279 } elsif ($buildtype eq "mg") {
280 $buildwriter->startTag('serviceRack', 'name'=>'GS2MGRetrieve');
281 $buildwriter->emptyTag('defaultIndex', 'name'=>$defaultindex);
282
283 }
284 if (defined $indexstem) {
285 $buildwriter->emptyTag('indexStem', 'name'=>$indexstem);
286 }
287 # close off the Retrieve service
288 $buildwriter->endTag('serviceRack');
289
290 # add in the classifiers if needed
291
292 my $count = 1;
293 my $phind = 0;
294 my $started_classifiers = 0;
295 if (defined $collectcfg->{'classify'}) {
296 $collwriter->startTag('browse');
297 # add in default format if necessary
298 if (defined $format->{"VList"} || defined $format->{"HList"}) {
299 # global formats
300 $collwriter->startTag('format');
301 if (defined $format->{"VList"}) {
302 # VLIst applies to both classifier and doc nodes
303 write_format($collwriter, $format->{"VList"}, "document");
304 write_format($collwriter, $format->{"VList"}, "classifier");
305 }
306 if (defined $format->{"HList"}) {
307 # hlist is only for classifier nodes
308 write_format($collwriter, $format->{"HList"}, "horizontal");
309 }
310 $collwriter->endTag('format');
311 }
312 my $classifiers = $collectcfg->{'classify'};
313 foreach my $cl (@$classifiers) {
314 my $name = "CL$count";
315 $count++;
316 my ($classname) = @$cl[0];
317 if ($classname =~ /^phind$/i) {
318 $phind=1;
319 #should add it into coll config classifiers
320 next;
321 }
322
323 my $horizontalAtTop = &isHorizontalClassifier($database, $name);
324 if (not $started_classifiers) {
325 $buildwriter->startTag('serviceRack', 'name'=>'GS2Browse');
326 if (defined $indexstem) {
327 $buildwriter->emptyTag('indexStem', 'name'=>$indexstem);
328 }
329
330 $buildwriter->startTag('classifierList');
331 $started_classifiers = 1;
332 }
333 my $content = ''; #use buttonname first, then metadata
334 if ($classname eq "DateList") {
335 $content = "Date";
336 } else {
337 for (my $i=0; $i<scalar(@$cl); $i++) {
338 my $arg = @$cl[$i];
339 if ($arg eq "-buttonname"){
340 $content = @$cl[$i+1];
341 last;
342 } elsif ($arg eq "-metadata") {
343 $content = @$cl[$i+1];
344 }
345
346 }
347 }
348 if ($horizontalAtTop) {
349 $buildwriter->emptyTag('classifier', 'name'=>$name, 'content'=>$content, 'horizontalAtTop'=>'true');
350 } else {
351 $buildwriter->emptyTag('classifier', 'name'=>$name, 'content'=>$content);
352 }
353
354
355 $collwriter->startTag('classifier', 'name'=>$name);
356 my $vlist = $name."VList";
357 my $hlist = $name."HList";
358 my $dlist = "";
359 if ($classname eq "DateList") {
360 $dlist = "DateList";
361 }
362 # need to work out how to split into classifier and document
363 if (defined $format->{$vlist} || defined $format->{$hlist} || defined $format->{$dlist}) {
364 $collwriter->startTag('format');
365 if (defined $format->{$vlist}) {
366 write_format($collwriter, $format->{$vlist}, "document");
367 write_format($collwriter, $format->{$vlist}, "classifier");
368 }
369 if (defined $format->{$hlist}) {
370 write_format($collwriter, $format->{$hlist}, "horizontal");
371 }
372
373 if (defined $format->{$dlist}) {
374 write_format($collwriter, $format->{$dlist}, "document");
375 }
376 $collwriter->endTag('format');
377 }
378 $collwriter->endTag('classifier');
379 } #foreach classifier
380 if ($started_classifiers) {
381 # end the classifiers
382 $buildwriter->endTag('classifierList');
383 # close off the Browse service
384 $buildwriter->endTag('serviceRack');
385 }
386
387 $collwriter->endTag('browse');
388 }
389
390
391 # the phind classifier is a separate service
392 if ($phind) {
393 # if phind classifier
394 $buildwriter->emptyTag('serviceRack', 'name'=>'PhindPhraseBrowse');
395 }
396
397 # do the search service
398 if ($buildtype eq 'mgpp' || $buildtype eq 'lucene') {
399
400 $buildwriter->startTag('serviceRack', 'name'=>'GS2'.$service_name.'Search');
401 $buildwriter->emptyTag('defaultLevel', 'name'=>$defaultlevel);
402 $buildwriter->startTag('levelList');
403 foreach my $level (@levels) {
404 $buildwriter->emptyTag('level', 'name'=>$level);
405 }
406 $buildwriter->endTag('levelList');
407
408 #fieldlist
409 my $fieldmap = {};
410 my $fieldlist = ();
411 if (defined $buildcfg->{'indexfields'}) {
412 push @$fieldlist, @{$buildcfg->{'indexfields'}};
413 if (defined $buildcfg->{'indexfieldmap'}) {
414 my $fieldmap_t = $buildcfg->{'indexfieldmap'};
415 foreach my $f (@$fieldmap_t) {
416 my ($k, $v) = $f =~ /^(.*)\-\>(.*)$/;
417 $fieldmap->{$k} = $v;
418 }
419 }
420 $buildwriter->startTag('fieldList');
421 foreach my $f (@$fieldlist) {
422 my $field = $fieldmap->{$f};
423 $buildwriter->emptyTag('field', 'shortname'=>$field, 'name'=>$f);
424 }
425 $buildwriter->endTag('fieldList');
426 } else {
427 print STDERR "indexfieldmap not defined";
428 }
429
430 # do the search types if there
431 if (defined $collectcfg->{'searchtype'}) {
432 $buildwriter->startTag('searchTypeList');
433 foreach my $st (@{$collectcfg->{'searchtype'}}) {
434 $buildwriter->emptyTag('searchType', 'name'=>$st);
435 }
436 $buildwriter->endTag('searchTypeList');
437 } elsif (defined $format->{'SearchTypes'}) {
438 #check format statement
439 my $searchtype = $format->{'SearchTypes'};
440 $buildwriter->startTag('searchTypeList');
441 if ($searchtype =~ /form/) {
442 $buildwriter->emptyTag('searchType', 'name'=>'form');
443 }
444 if ($searchtype =~ /plain/) {
445 $buildwriter->emptyTag('searchType', 'name'=>'plain');
446 }
447 $buildwriter->endTag('searchTypeList');
448 }
449 } elsif ($buildtype eq 'mg') {
450 $buildwriter->startTag('serviceRack', 'name'=>'GS2MGSearch');
451 }
452
453 if (defined $indexstem) {
454 $buildwriter->emptyTag('indexStem', 'name'=>$indexstem);
455 }
456
457 # index options
458 if ($buildtype eq 'mg' || $buildtype eq 'mgpp') {
459 $buildwriter->startTag('indexOptionList');
460 my $stemindexes = 3; # default is stem and casefold
461 if (defined $buildcfg->{'stemindexes'} && $buildcfg->{'stemindexes'} =~ /^\d+$/ ) {
462 $stemindexes = $buildcfg->{'stemindexes'};
463 }
464 $buildwriter->emptyTag('indexOption', 'name'=>'stemIndexes', 'value'=>$stemindexes);
465
466 my $maxnumeric = 4; # default
467 if (defined $buildcfg->{'maxnumeric'} && $buildcfg->{'maxnumeric'} =~ /^\d+$/) {
468 $maxnumeric = $buildcfg->{'maxnumeric'};
469 }
470 $buildwriter->emptyTag('indexOption', 'name'=>'maxnumeric', 'value'=>$maxnumeric);
471
472 $buildwriter->endTag('indexOptionList');
473 }
474 $buildwriter->emptyTag('defaultIndex', 'name'=>$defaultindex);
475 $buildwriter->startTag('indexList');
476 #for each index
477 foreach my $i (keys %$indexmap) {
478 my $index = $indexmap->{$i};
479 $buildwriter->emptyTag('index', 'name'=>$index);
480 }
481 $buildwriter->endTag('indexList');
482
483 $buildwriter->endTag('serviceRack');
484
485 $buildwriter->endTag('serviceRackList');
486 $buildwriter->endTag('buildConfig');
487
488 # we add in the default replace list just in case we have macros in the
489 # collection
490 $collwriter->emptyTag('replaceListRef', 'id'=>'gs2-standard');
491 $collwriter->endTag('collectionConfig');
492 $collwriter->end();
493 $buildwriter->end();
494 $buildoutput->close();
495 $colloutput->close();
496 &close_database($database);
497}
498
499
500sub output_metadata {
501 my ($writer, $metaname, $metavalue) = @_;
502 $writer->startTag('metadata', 'name'=>$metaname);
503 $writer->characters($metavalue);
504 $writer->endTag('metadata');
505}
506
507sub output_display {
508 my ($writer, $name, $lang, $value) = @_;
509 $lang = 'en' if $lang eq 'default';
510 if ($lang =~ /^\[/) {
511 ($lang) = $lang =~ /\[l=(.*)\]/;
512 }
513 $writer->startTag('displayItem', 'name'=>$name, 'lang'=>$lang);
514 $writer->characters($value);
515 $writer->endTag('displayItem');
516}
517sub format_icon_value {
518 my ($value) = @_;
519 if ($value =~ /^_/) {
520 my ($newvalue) = $value =~ /\/([^\/]*)$/;
521 if ($newvalue) {
522 return $newvalue;
523 }
524 }
525 return $value;
526}
527
528sub tidy_up_metadata {
529 my ($value) = @_;
530 # remove \n
531 $value =~ s/\\n//g;
532 # replace \' with '
533 $value =~ s/\\\'/\'/g;
534 # replace \" with "
535 $value =~ s/\\\"/\"/g;
536 return $value;
537}
538
539sub write_format {
540 my ($writer, $old_format, $node_type) = @_;
541 # replace \' with '
542 $old_format =~ s/\\\'/\'/g;
543 # replace \" with "
544 $old_format =~ s/\\\"/\"/g;
545 #convert [] to <gsf:...>
546 # assume no nesting {If} or {Or} for now
547 $old_format =~ s/\{If\}\{([^\}]*)\}/&format_if($1, $node_type)/eg;
548 $old_format =~ s/\{Or\}\{([^\}]*)\}/&format_or($1)/eg;
549 $old_format =~ s/\[Text\]/\<gsf:text\/\>/g;
550 $old_format =~ s/\[num\]/\<gsf:num\/\>/g;
551 $old_format =~ s/\[link\]/\<gsf:link type=\'$node_type\'\>/g;
552 $old_format =~ s/\[\/link\]/\<\/gsf:link\>/g;
553 $old_format =~ s/\[srclink\]/\<gsf:link type=\'source\'\>/g;
554 $old_format =~ s/\[\/srclink\]/\<\/gsf:link\>/g;
555 $old_format =~ s/\[icon\]/\<gsf:icon type=\'$node_type\'\/\>/g;
556 $old_format =~ s/\[srcicon\]/\<gsf:icon type=\'source\'\/\>/g;
557
558 # what to do with hightlight??
559 $old_format =~ s/\[\/?highlight\]//g;
560
561 #now do the rest of the [] which are assumed to be metadata
562 $old_format =~ s/\[([^\]]*)\]/&format_metadata($1)/eg;
563
564 # some html tidy
565 #turn <br> into <br />
566 $old_format =~ s/\<br\>/\<br \/\>/g;
567 #turn <p> into <p />
568 $old_format =~ s/\<p\>/\<p \/\>/g;
569
570 #put quotes around any atts
571 $old_format =~ s/=([a-z]+)([> ])/=\'$1\'$2/g;
572
573 if ($node_type eq "document") {
574 $writer->startTag('gsf:template', 'match'=>'documentNode');
575 $writer->charactersXML($old_format);
576 $writer->endTag('gsf:template');
577 } elsif ($node_type eq "classifier") {
578 $writer->startTag('gsf:template', 'match'=>'classifierNode');
579 $writer->charactersXML($old_format);
580 $writer->endTag('gsf:template');
581 } elsif ($node_type eq "horizontal") {
582 $writer->startTag('gsf:template', 'match'=>'classifierNode', 'mode'=>'horizontal');
583 $writer->charactersXML($old_format);
584 $writer->endTag('gsf:template');
585
586 }
587}
588
589sub format_metadata {
590 my ($metadata_string) = @_;
591
592 #print STDERR "original meta = $metadata_string\n";
593
594 # what shall we do with cgisafe??
595 my $cgisafe = $metadata_string =~ s/^cgisafe://;
596
597 my ($select) = $metadata_string =~ /^(parent|sibling)/;
598 $metadata_string =~ s/^(parent|sibling)//;
599 my ($scope, $delim);
600
601 if ($select) {
602 ($scope) = $metadata_string =~ /^\((Top|All)/;
603 $metadata_string =~ s/^\((Top|All)\)?//;
604 if ($scope) {
605 ($delim) = $metadata_string =~ /^\'([^\']*)\'\)/;
606 $metadata_string =~ s/^\'([^\']*)\'\)//;
607 }
608 }
609 $metadata_string =~ s/^://;
610 # remove ex.
611 $metadata_string =~ s/^ex\.//;
612
613 #print STDERR "select=$select, scope=$scope, delim=|$delim|, meta = $metadata_string\n";
614
615 my $new_format = "<gsf:metadata name='$metadata_string' ";
616 if (defined $select) {
617 if ($select eq "sibling") {
618 $new_format .= "multiple='true' ";
619 if (defined $delim) {
620 $new_format .= "separator='$delim' ";
621 }
622 } elsif ($select eq "parent"){
623 if (defined $scope) {
624 if ($scope eq "Top") {
625 $new_format .= "select='root' ";
626 } elsif ($scope eq "All") {
627 $new_format .= "select='ancestors' ";
628 if (defined $delim) {
629 $new_format .= "separator='$delim' ";
630 }
631 }
632 } else {
633 $new_format .= "select='parent' ";
634 }
635 }
636 }
637 $new_format .= "/>";
638 #print STDERR "$new_format\n";
639 return $new_format;
640
641}
642
643sub format_if {
644
645 my ($if_string, $node_type) = @_;
646 #print STDERR "if string = $if_string\n";
647
648 my @parts = split /,/, $if_string;
649 my $test = $parts[0];
650 my $true_option = $parts[1];
651 my $false_option;
652 if (scalar (@parts) == 3) {
653 $false_option = $parts[2];
654 }
655 $test =~ s/^\s*//;
656 $test =~ s/\s*$//;
657 my ($test_meta, $test_type, $test_value);
658 if ($test =~ /^(\[.+\])$/) {
659 $test_meta = $1;
660 $test_type = 'exists';
661 } else {
662 my ($lhs, $exp, $rhs) = $test =~ /^(.+)\s+(eq|ne|lt|gt|le|ge|sw|ew)\s+(.+)$/;
663 #print STDERR "lhs, exp, rhs = $lhs, $exp, $rhs\n";
664 if ($exp eq "eq") {
665 $test_type = "equals";
666 } elsif ($exp eq "sw") {
667 $test_type = "startsWith";
668 } elsif ($exp eq "ew") {
669 $test_type = "endsWith";
670 } elsif ($exp eq "ne") {
671 $test_type = "notEquals";
672 } elsif ($exp eq "lt") {
673 $test_type = "lessThan";
674 }elsif ($exp eq "gt") {
675 $test_type = "greaterThan";
676 }elsif ($exp eq "le") {
677 $test_type = "lessThanOrEquals";
678 }elsif ($exp eq "ge") {
679 $test_type = "greaterThanOrEquals";
680 }
681 if ($lhs =~ /^\[.+\]$/) {
682 $test_meta = $lhs;
683 $test_value = $rhs;
684 } else {
685 # assume rhs has meta
686 $test_meta = $rhs;
687 $test_value = $lhs;
688 }
689
690 #remove beginning and end quotes
691 $test_value =~ s/^[\'\"]//;
692 $test_value =~ s/[\'\"]$//;
693 }
694 my $test_atts = "test='$test_type' ";
695 if (defined $test_value) {
696 $test_atts .= "test-value='$test_value' ";
697 }
698 #print STDERR "test, true, false = $test, $true_option, $false_option\n";
699 my $new_format = "<gsf:switch>$test_meta";
700 $new_format .= "<gsf:when $test_atts>$true_option</gsf:when>";
701 if (defined $false_option) {
702 $new_format .="<gsf:otherwise>$false_option</gsf:otherwise>";
703 }
704 $new_format .= "</gsf:switch>";
705
706 #print STDERR "new format = $new_format\n";
707 return $new_format;
708}
709
710sub format_or {
711 my ($or_string) = @_;
712 my @meta_list = split (',', $or_string);
713 return "" unless scalar (@meta_list);
714 my $new_format = "<gsf:choose-metadata>";
715 foreach my $m (@meta_list) {
716 if ($m =~ /^\[(.*)\]$/) {
717 $new_format .= &format_metadata($1);
718 } else {
719 # a default value
720 $new_format .= "<gsf:default>$m</gsf:default>";
721 last;
722 }
723 }
724 $new_format .= "</gsf:choose-metadata>";
725 return $new_format;
726}
727
728sub open_database {
729 my ($db_file) = @_;
730
731 my $database = ();
732# tie (%$database, 'GDBM_File', $db_file, GDBM_READER, 0400) ||
733# die "Couldn't open database $db_file\n";
734
735 return $database;
736}
737
738sub close_database {
739 my ($database) = @_;
740 untie %$database;
741}
742sub isHorizontalClassifier {
743 my ($database, $name) = @_;
744
745 return 0; # can't get this to work for windows
746 my $record = $database->{$name};
747 my ($childtype) = $record =~ /<childtype>(\w*)/;
748 if ($childtype eq "HList") {
749 return 1;
750 }
751 return 0;
752}
753#$writer->startTag('');
754#$writer->endTag('');
755#$writer->characters();
756#$writer->emptyTag('');
757
7581;
Note: See TracBrowser for help on using the repository browser.