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

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

still trying to fix up gs2 links. but giving up now

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