[3688] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | BEGIN {
|
---|
| 4 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
[6307] | 5 | die "GSDL3HOME not set\n" unless defined $ENV{'GSDL3HOME'};
|
---|
[10326] | 6 | die "GSDL3SRCHOME not set\n" unless defined $ENV{'GSDL3SRCHOME'};
|
---|
[3688] | 7 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
| 8 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
[10326] | 9 | unshift (@INC, "$ENV{'GSDL3SRCHOME'}/lib/perl/cpan");
|
---|
[3688] | 10 | }
|
---|
| 11 |
|
---|
| 12 | use colcfg;
|
---|
| 13 | use util;
|
---|
| 14 | use parsargv;
|
---|
| 15 | use FileHandle;
|
---|
| 16 | use XML::Writer;
|
---|
[10658] | 17 | #can't get this to work on windows
|
---|
| 18 | #use GDBM_File;
|
---|
[3688] | 19 |
|
---|
[10360] | 20 | use strict;
|
---|
| 21 |
|
---|
[3688] | 22 | &main();
|
---|
| 23 | sub print_usage() {
|
---|
| 24 | print STDOUT "Usage: convert_coll_from_gs2.pl [options] coll-name\n";
|
---|
| 25 | print STDOUT "options:\n";
|
---|
| 26 |
|
---|
[3872] | 27 | print STDOUT " -collectdir Directory where collection lives.\n";
|
---|
[4969] | 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";
|
---|
[3688] | 30 | }
|
---|
| 31 |
|
---|
[13828] | 32 |
|
---|
[3688] | 33 | sub main {
|
---|
| 34 |
|
---|
[4969] | 35 | my ($defaultlang, $verbosity, $collectdir);
|
---|
[3688] | 36 | # note that no defaults are passed for most options as they're set
|
---|
| 37 | # later (after we check the collect.cfg file)
|
---|
[4969] | 38 | if (!&parsargv::parse(\@ARGV,
|
---|
| 39 | 'verbosity/\d+/', \$verbosity,
|
---|
| 40 | 'collectdir/.*/', \$collectdir,
|
---|
| 41 | 'defaultlang/.*/', \$defaultlang)) {
|
---|
[3688] | 42 | &print_usage();
|
---|
| 43 | die "\n";
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | # get and check the collection name
|
---|
[4969] | 47 | my ($collection) = @ARGV;
|
---|
| 48 | if (!defined($collection) || $collection eq "") {
|
---|
| 49 | die "No collection specified\n";
|
---|
[3688] | 50 | }
|
---|
[4969] | 51 | if ($collection eq "gs2model") {
|
---|
| 52 | die "You cant convert the model collection\n";
|
---|
| 53 | }
|
---|
[4184] | 54 |
|
---|
[4969] | 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 |
|
---|
[10360] | 65 | my $collconfigfilename = &util::filename_cat ($collectdir, "etc", "collect.cfg");
|
---|
[4969] | 66 | print STDOUT "coll config=$collconfigfilename\n";
|
---|
[3688] | 67 | my $collectcfg;
|
---|
| 68 | if (-e $collconfigfilename) {
|
---|
| 69 | $collectcfg = &colcfg::read_collect_cfg ($collconfigfilename);
|
---|
| 70 |
|
---|
[3983] | 71 | } else {
|
---|
| 72 | print STDERR "collect.cfg not found!!";
|
---|
| 73 | die "\n";
|
---|
[3688] | 74 | }
|
---|
[4184] | 75 |
|
---|
[3872] | 76 |
|
---|
[10360] | 77 | my $buildconfigfilename = &util::filename_cat ($collectdir, "index", "build.cfg");
|
---|
[3688] | 78 | my $buildcfg;
|
---|
| 79 | if (-e $buildconfigfilename) {
|
---|
| 80 | $buildcfg = &colcfg::read_build_cfg ($buildconfigfilename);
|
---|
| 81 |
|
---|
[3983] | 82 | } else {
|
---|
| 83 | print STDERR "build.cfg not found!!";
|
---|
| 84 | die "\n";
|
---|
[3688] | 85 | }
|
---|
[4184] | 86 |
|
---|
[3688] | 87 |
|
---|
[3979] | 88 |
|
---|
[4969] | 89 | my $colloutfile = &util::filename_cat ($collectdir, "etc", "collectionConfig.xml");
|
---|
[3979] | 90 | if (-e $colloutfile) {
|
---|
| 91 | print STDOUT "collectionConfig file already exists! overwriting it!\n";
|
---|
| 92 |
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[4969] | 95 | my $buildoutfile = &util::filename_cat ($collectdir, "index", "buildConfig.xml");
|
---|
[3979] | 96 | if (-e $buildoutfile) {
|
---|
[3688] | 97 | print STDOUT "buildConfig file already exists! overwriting it!\n";
|
---|
| 98 |
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[10658] | 101 | # my $db_file = &util::filename_cat ($collectdir, "index", "text", "$collection.ldb");
|
---|
[9899] | 102 | my $database;
|
---|
[10658] | 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 | # }
|
---|
[9899] | 109 |
|
---|
[3688] | 110 | my $buildtype;
|
---|
[4886] | 111 | if (defined $buildcfg->{'buildtype'}) {
|
---|
| 112 | $buildtype = $buildcfg->{'buildtype'};
|
---|
[3688] | 113 | } else {
|
---|
| 114 | $buildtype = 'mg';
|
---|
| 115 | }
|
---|
[4184] | 116 |
|
---|
[10653] | 117 | my $indexstem = undef;
|
---|
| 118 | if (defined $buildcfg->{'indexstem'}) {
|
---|
| 119 | $indexstem = $buildcfg->{'indexstem'};
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[3979] | 122 | my $buildoutput = new IO::File(">$buildoutfile");
|
---|
[4184] | 123 | my $buildwriter = new XML::Writer(OUTPUT => $buildoutput, NEWLINES => 1);
|
---|
[3979] | 124 |
|
---|
[9874] | 125 | $buildwriter->startTag('buildConfig', 'xmlns:gsf'=>"http://www.greenstone.org/greenstone3/schema/ConfigFormat");
|
---|
[4184] | 126 |
|
---|
[3979] | 127 | my $colloutput = new IO::File(">$colloutfile");
|
---|
[4184] | 128 | my $collwriter = new XML::Writer(OUTPUT => $colloutput, NEWLINES => 1);
|
---|
| 129 |
|
---|
[14754] | 130 | $collwriter->startTag('CollectionConfig', 'xmlns:gsf'=>"http://www.greenstone.org/greenstone3/schema/ConfigFormat", 'xmlns:xsl'=>'http://www.w3.org/1999/XSL/Transform');
|
---|
[4184] | 131 |
|
---|
[3979] | 132 | #output the collection metadata to the collectionConfig file
|
---|
| 133 | $collwriter->startTag('metadataList');
|
---|
| 134 |
|
---|
[4969] | 135 | my $creator = $collectcfg->{'creator'};
|
---|
[14754] | 136 | &output_metadata($collwriter,'default', 'creator', $creator);
|
---|
[13836] | 137 | my $public =$collectcfg->{'public'};
|
---|
[14754] | 138 | &output_metadata($collwriter,'default', 'public', $public);
|
---|
| 139 |
|
---|
[4969] | 140 | $collwriter->endTag('metadataList');
|
---|
| 141 |
|
---|
| 142 | #output the display collectionmeta to collectionConfig.xml
|
---|
[3979] | 143 |
|
---|
[4969] | 144 | my $collectionmeta = $collectcfg->{'collectionmeta'};
|
---|
[3979] | 145 | if (defined $collectionmeta) {
|
---|
[10360] | 146 | my %name_map = ('collectionname', 'name',
|
---|
[4969] | 147 | 'collectionextra', 'description',
|
---|
| 148 | 'iconcollection', 'icon',
|
---|
| 149 | 'iconcollectionsmall', 'smallicon');
|
---|
| 150 |
|
---|
| 151 | $collwriter->startTag('displayItemList');
|
---|
[10360] | 152 | foreach my $entry ( keys %$collectionmeta) {
|
---|
[3979] | 153 | if (defined $name_map{$entry}) {
|
---|
[10360] | 154 | my $name= $name_map{$entry};
|
---|
| 155 | foreach my $lang (keys %{$collectionmeta->{$entry}}) {
|
---|
| 156 | my $value = $collectionmeta->{$entry}->{$lang};
|
---|
[4184] | 157 | if ($entry =~ /^icon/) {
|
---|
| 158 | $value = format_icon_value($value);
|
---|
[12678] | 159 | } else {
|
---|
[13828] | 160 | $value = tidy_up_display_item($value);
|
---|
[4184] | 161 | }
|
---|
[4969] | 162 | &output_display($collwriter, $name, $lang, $value);
|
---|
[3979] | 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
[4969] | 166 | $collwriter->endTag('displayItemList');
|
---|
[3979] | 167 | }
|
---|
| 168 |
|
---|
[4969] | 169 | # output building metadata to build config file
|
---|
[3872] | 170 | my $numdocs = $buildcfg->{'numdocs'};
|
---|
[3979] | 171 | $buildwriter->startTag('metadataList');
|
---|
[14754] | 172 | &output_metadata($buildwriter,'', 'numDocs', $numdocs);
|
---|
| 173 | &output_metadata($buildwriter,'', 'buildType', $buildtype);
|
---|
[3979] | 174 | $buildwriter->endTag('metadataList');
|
---|
[3872] | 175 |
|
---|
| 176 |
|
---|
[3771] | 177 | #indexes
|
---|
[13912] | 178 | # maps index name to shortname
|
---|
[3771] | 179 | my $indexmap = {};
|
---|
[13912] | 180 | # keeps the order for indexes
|
---|
| 181 | my @indexlist = ();
|
---|
[13917] | 182 | my $defaultindex = "";
|
---|
[4886] | 183 | my $first = 1;
|
---|
[13912] | 184 | my $maptype = "indexfieldmap";
|
---|
| 185 | if ($buildtype eq "mg") {
|
---|
| 186 | $maptype = "indexmap";
|
---|
| 187 | }
|
---|
| 188 | if (defined $buildcfg->{$maptype}) {
|
---|
| 189 | my $indexmap_t = $buildcfg->{$maptype};
|
---|
[10360] | 190 | foreach my $i (@$indexmap_t) {
|
---|
[3771] | 191 | my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
|
---|
| 192 | $indexmap->{$k} = $v;
|
---|
[13912] | 193 | push @indexlist, $k;
|
---|
[14754] | 194 | if ($first == 1) {
|
---|
| 195 | $defaultindex = $k;
|
---|
[4886] | 196 | $first = 0;
|
---|
| 197 | }
|
---|
[3771] | 198 | }
|
---|
| 199 | } else {
|
---|
[13912] | 200 | print STDERR "$maptype not defined";
|
---|
[3771] | 201 | }
|
---|
[13912] | 202 | # we use the shortname for default index
|
---|
| 203 | if (defined $collectcfg->{'defaultindex'}) {
|
---|
| 204 | $defaultindex = $collectcfg->{'defaultindex'};
|
---|
[14754] | 205 | #$defaultindex = $indexmap->{$defaultindex};
|
---|
[3771] | 206 | }
|
---|
| 207 |
|
---|
[13917] | 208 | # levels
|
---|
| 209 | my $levelmap = {};
|
---|
| 210 | my @levellist = ();
|
---|
| 211 | my $default_search_level = "";
|
---|
[14754] | 212 | my $default_search_level_shortname = "";
|
---|
[13917] | 213 | my $default_retrieve_level = "Sec";
|
---|
| 214 | $first = 1;
|
---|
| 215 | if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
|
---|
| 216 | if (defined $buildcfg->{'levelmap'}) {
|
---|
| 217 | my $levelmap_t = $buildcfg->{'levelmap'};
|
---|
| 218 | foreach my $l (@$levelmap_t) {
|
---|
| 219 | my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
|
---|
| 220 | $levelmap->{$k} = $v;
|
---|
| 221 | push @levellist, $k;
|
---|
| 222 | if ($first) {
|
---|
[14754] | 223 | $default_search_level = $k;
|
---|
| 224 | $default_search_level_shortname = $v;
|
---|
[13917] | 225 | $first = 0;
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | if (defined $collectcfg->{'defaultlevel'}) {
|
---|
| 231 | $default_search_level = $collectcfg->{'defaultlevel'};
|
---|
[14754] | 232 | #$default_search_level = $levelmap->{$default_search_level};
|
---|
| 233 | $default_search_level_shortname = $levelmap->{$default_search_level};
|
---|
[13917] | 234 | }
|
---|
| 235 | if (defined $buildcfg->{'textlevel'}) {
|
---|
| 236 | $default_retrieve_level = $buildcfg->{'textlevel'};
|
---|
| 237 | }
|
---|
| 238 | }
|
---|
[4184] | 239 | # format stuff
|
---|
| 240 | my $format = $collectcfg->{'format'};
|
---|
| 241 |
|
---|
| 242 | #output the search stuff to coll cfg
|
---|
[14754] | 243 | $collwriter->startTag('search','type'=>$buildtype);
|
---|
[10360] | 244 | foreach my $i (keys %$indexmap) {
|
---|
[13912] | 245 | $collwriter->startTag('index', 'name'=>$i);
|
---|
[4184] | 246 | #find the coll meta stuff
|
---|
[10360] | 247 | my $indexdisplay = ".$i";
|
---|
| 248 | foreach my $lang (keys %{$collectionmeta->{$indexdisplay}}) {
|
---|
| 249 | my $value = $collectionmeta->{$indexdisplay}->{$lang};
|
---|
[14754] | 250 | output_display($collwriter, 'name', $lang, $i);
|
---|
[4184] | 251 | }
|
---|
| 252 | $collwriter->endTag('index');
|
---|
| 253 | }
|
---|
| 254 |
|
---|
[14754] | 255 | #output the defaultIndex to coll cfg
|
---|
| 256 | $collwriter->emptyTag('defaultIndex','name'=>$defaultindex);
|
---|
| 257 |
|
---|
| 258 | #indexSubcollection
|
---|
| 259 | my $indexsubcollections = $collectcfg->{'indexsubcollections'};
|
---|
| 260 |
|
---|
| 261 | if (defined $indexsubcollections) {
|
---|
| 262 | my $indexsubcollections_t= $collectcfg->{'indexsubcollections'};
|
---|
| 263 | foreach my $i ( @$indexsubcollections_t) {
|
---|
| 264 | $collwriter->startTag('indexSubcollection', 'name'=>$i);
|
---|
| 265 | &output_display($collwriter, 'name', $defaultlang, $i);
|
---|
| 266 | $collwriter->endTag('indexSubcollection');
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | #subcollection
|
---|
| 271 | my $subcollection = $collectcfg->{'subcollection'};
|
---|
| 272 | if (defined $subcollection){
|
---|
| 273 | foreach my $entry (keys %$subcollection){
|
---|
| 274 | my $value = $subcollection->{$entry};
|
---|
| 275 | $collwriter->emptyTag('subcollection','filter'=>$value,'name'=>$entry);
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | #indexlanguage
|
---|
| 280 | my $languages = $collectcfg->{'languages'};
|
---|
| 281 | if (defined $languages){
|
---|
| 282 | my $languages_t = $collectcfg->{'languages'};
|
---|
| 283 | foreach my $i (@$languages_t){
|
---|
| 284 | $collwriter->startTag('indexLanguage','name'=>$i);
|
---|
| 285 | &output_display($collwriter, 'name', $defaultlang, $i);
|
---|
| 286 | $collwriter->endTag('indexLanguage');
|
---|
| 287 | }
|
---|
| 288 | }
|
---|
| 289 |
|
---|
[13917] | 290 | # level stuff for mgpp/lucene
|
---|
| 291 | if ($buildtype eq 'mgpp' || $buildtype eq 'lucene'){
|
---|
| 292 | foreach my $l (keys %$levelmap) {
|
---|
| 293 | $collwriter->startTag('level', 'name'=>$l);
|
---|
| 294 | #find the coll meta stuff
|
---|
| 295 | my $leveldisplay = ".$l";
|
---|
| 296 | foreach my $lang (keys %{$collectionmeta->{$leveldisplay}}) {
|
---|
| 297 | my $value = $collectionmeta->{$leveldisplay}->{$lang};
|
---|
| 298 | output_display($collwriter, 'name', $lang, $value);
|
---|
| 299 | }
|
---|
| 300 | $collwriter->endTag('level');
|
---|
| 301 | }
|
---|
[14754] | 302 | $collwriter->emptyTag('defaultLevel', 'name'=>$default_search_level);
|
---|
[13917] | 303 | }
|
---|
[14754] | 304 |
|
---|
| 305 | # add in the search type
|
---|
| 306 | if (defined $format->{'SearchTypes'}){
|
---|
| 307 | $collwriter->startTag('format', 'name'=>"searchType");
|
---|
| 308 | $collwriter->charactersXML($format->{'SearchTypes'});
|
---|
| 309 | $collwriter->endTag('format');
|
---|
| 310 | }
|
---|
| 311 |
|
---|
[4184] | 312 | # add in the format stuff
|
---|
| 313 | if (defined $format->{'SearchVList'}) {
|
---|
[4969] | 314 |
|
---|
[4184] | 315 | $collwriter->startTag('format');
|
---|
[10201] | 316 | write_format($collwriter, $format->{'SearchVList'}, "document");
|
---|
[4184] | 317 | $collwriter->endTag('format');
|
---|
| 318 | }
|
---|
[12979] | 319 | elsif (defined $format->{'VList'}) {
|
---|
| 320 | $collwriter->startTag('format');
|
---|
| 321 | write_format($collwriter, $format->{'VList'}, "document");
|
---|
| 322 | $collwriter->endTag('format');
|
---|
| 323 | }
|
---|
[3771] | 324 |
|
---|
[4184] | 325 | $collwriter->endTag('search');
|
---|
[14754] | 326 |
|
---|
| 327 | # import plugins
|
---|
| 328 |
|
---|
| 329 | my $plugins = $collectcfg->{'plugin'};
|
---|
[4184] | 330 |
|
---|
[14754] | 331 | if (defined $plugins){
|
---|
| 332 | $collwriter->startTag('import');
|
---|
| 333 | $collwriter->startTag('pluginList');
|
---|
| 334 | foreach my $pl (@$plugins) {
|
---|
| 335 | my ($pluginname) = @$pl[0];
|
---|
| 336 | $collwriter->startTag('plugin','name'=>$pluginname);
|
---|
| 337 |
|
---|
| 338 | for (my $i=1; $i<scalar(@$pl); $i++) {
|
---|
| 339 | my $arg =@$pl[$i];
|
---|
| 340 | if ($arg =~ /^-/){
|
---|
| 341 | my $option_name=@$pl[$i];
|
---|
| 342 | my $option_value=@$pl[$i+1];
|
---|
| 343 | if (defined $option_value){
|
---|
| 344 | if ($option_value =~ /^-/){
|
---|
| 345 | $collwriter->startTag('option','name'=>$option_name);
|
---|
| 346 | $collwriter->endTag('option');
|
---|
| 347 | }else{
|
---|
| 348 | $collwriter->startTag('option','name'=>$option_name,'value'=>$option_value);
|
---|
| 349 | $collwriter->endTag('option');
|
---|
| 350 | }
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
| 353 | }
|
---|
| 354 | $collwriter->endTag('plugin');
|
---|
| 355 | }
|
---|
| 356 | $collwriter->endTag('pluginList');
|
---|
| 357 | $collwriter->endTag('import');
|
---|
| 358 | }
|
---|
| 359 |
|
---|
[3979] | 360 | $buildwriter->startTag('serviceRackList');
|
---|
[3688] | 361 |
|
---|
[4886] | 362 | my @levels = ();
|
---|
| 363 | my $defaultlevel;
|
---|
[13912] | 364 | my $service_type = "MG";
|
---|
| 365 | if ($buildtype eq 'mgpp') {
|
---|
| 366 | $service_type = "MGPP";
|
---|
| 367 | } elsif ($buildtype eq "lucene") {
|
---|
| 368 | $service_type = "Lucene";
|
---|
| 369 | }
|
---|
| 370 |
|
---|
[14754] | 371 | #indexSubcollectionList
|
---|
| 372 |
|
---|
| 373 | my $subcollectionmap = $buildcfg->{'subcollectionmap'};
|
---|
| 374 | my $firstsubcollection = 1;
|
---|
| 375 | my $defaultsubcollection = "";
|
---|
| 376 | my @subcollist;
|
---|
| 377 | my $subcolmap = {};
|
---|
| 378 |
|
---|
| 379 | if (defined $buildcfg->{'subcollectionmap'}) {
|
---|
| 380 | my $subcolmap_t = $buildcfg->{'subcollectionmap'};
|
---|
| 381 |
|
---|
| 382 | foreach my $l (@$subcolmap_t) {
|
---|
| 383 | my @pair = split(/->/, $l);
|
---|
| 384 | $subcolmap->{$pair[0]} = $pair[1];
|
---|
| 385 | push @subcollist, $pair[0];
|
---|
| 386 | if ($firstsubcollection==1) {
|
---|
| 387 | $defaultsubcollection = $pair[1];
|
---|
| 388 | $firstsubcollection = 0;
|
---|
| 389 | }
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 |
|
---|
[3947] | 395 | #do the retrieve service
|
---|
[13917] | 396 | $buildwriter->startTag('serviceRack', 'name'=>"GS2".$service_type."Retrieve");
|
---|
[13228] | 397 | if ($buildtype eq 'mgpp' || $buildtype eq 'lucene') {
|
---|
[13917] | 398 | $buildwriter->emptyTag('defaultLevel', 'shortname'=>$default_retrieve_level);
|
---|
[13115] | 399 | } elsif ($buildtype eq "mg") {
|
---|
[13912] | 400 | $buildwriter->emptyTag('defaultIndex', 'shortname'=>$defaultindex);
|
---|
[3688] | 401 | }
|
---|
[14754] | 402 |
|
---|
| 403 | if ((defined $defaultsubcollection) && ($defaultsubcollection ne "")) {
|
---|
| 404 | $buildwriter->emptyTag('defaultIndexSubcollection', 'shortname'=>$defaultsubcollection);
|
---|
| 405 | }
|
---|
| 406 |
|
---|
[10653] | 407 | if (defined $indexstem) {
|
---|
| 408 | $buildwriter->emptyTag('indexStem', 'name'=>$indexstem);
|
---|
| 409 | }
|
---|
[8967] | 410 | # close off the Retrieve service
|
---|
| 411 | $buildwriter->endTag('serviceRack');
|
---|
[3688] | 412 |
|
---|
[3947] | 413 | # add in the classifiers if needed
|
---|
| 414 |
|
---|
[3688] | 415 | my $count = 1;
|
---|
| 416 | my $phind = 0;
|
---|
| 417 | my $started_classifiers = 0;
|
---|
| 418 | if (defined $collectcfg->{'classify'}) {
|
---|
[4184] | 419 | $collwriter->startTag('browse');
|
---|
[10360] | 420 | # add in default format if necessary
|
---|
| 421 | if (defined $format->{"VList"} || defined $format->{"HList"}) {
|
---|
| 422 | # global formats
|
---|
| 423 | $collwriter->startTag('format');
|
---|
| 424 | if (defined $format->{"VList"}) {
|
---|
| 425 | # VLIst applies to both classifier and doc nodes
|
---|
| 426 | write_format($collwriter, $format->{"VList"}, "document");
|
---|
| 427 | write_format($collwriter, $format->{"VList"}, "classifier");
|
---|
| 428 | }
|
---|
| 429 | if (defined $format->{"HList"}) {
|
---|
| 430 | # hlist is only for classifier nodes
|
---|
| 431 | write_format($collwriter, $format->{"HList"}, "horizontal");
|
---|
| 432 | }
|
---|
| 433 | $collwriter->endTag('format');
|
---|
| 434 | }
|
---|
[3688] | 435 | my $classifiers = $collectcfg->{'classify'};
|
---|
[10360] | 436 | foreach my $cl (@$classifiers) {
|
---|
| 437 | my $name = "CL$count";
|
---|
[3688] | 438 | $count++;
|
---|
| 439 | my ($classname) = @$cl[0];
|
---|
[4184] | 440 | if ($classname =~ /^phind$/i) {
|
---|
[3688] | 441 | $phind=1;
|
---|
[4184] | 442 | #should add it into coll config classifiers
|
---|
[3688] | 443 | next;
|
---|
| 444 | }
|
---|
| 445 |
|
---|
[9899] | 446 | my $horizontalAtTop = &isHorizontalClassifier($database, $name);
|
---|
[3688] | 447 | if (not $started_classifiers) {
|
---|
[8967] | 448 | $buildwriter->startTag('serviceRack', 'name'=>'GS2Browse');
|
---|
[10653] | 449 | if (defined $indexstem) {
|
---|
| 450 | $buildwriter->emptyTag('indexStem', 'name'=>$indexstem);
|
---|
| 451 | }
|
---|
| 452 |
|
---|
[10360] | 453 | $buildwriter->startTag('classifierList');
|
---|
[3688] | 454 | $started_classifiers = 1;
|
---|
| 455 | }
|
---|
[4969] | 456 | my $content = ''; #use buttonname first, then metadata
|
---|
[4184] | 457 | if ($classname eq "DateList") {
|
---|
| 458 | $content = "Date";
|
---|
| 459 | } else {
|
---|
[10360] | 460 | for (my $i=0; $i<scalar(@$cl); $i++) {
|
---|
| 461 | my $arg = @$cl[$i];
|
---|
[4235] | 462 | if ($arg eq "-buttonname"){
|
---|
[4184] | 463 | $content = @$cl[$i+1];
|
---|
| 464 | last;
|
---|
[4886] | 465 | } elsif ($arg eq "-metadata") {
|
---|
[4235] | 466 | $content = @$cl[$i+1];
|
---|
[4184] | 467 | }
|
---|
[4235] | 468 |
|
---|
[3688] | 469 | }
|
---|
| 470 | }
|
---|
[9899] | 471 | if ($horizontalAtTop) {
|
---|
| 472 | $buildwriter->emptyTag('classifier', 'name'=>$name, 'content'=>$content, 'horizontalAtTop'=>'true');
|
---|
[14754] | 473 |
|
---|
[9899] | 474 | } else {
|
---|
[4886] | 475 | $buildwriter->emptyTag('classifier', 'name'=>$name, 'content'=>$content);
|
---|
[9899] | 476 | }
|
---|
[3688] | 477 |
|
---|
[3947] | 478 |
|
---|
[14754] | 479 | # $collwriter->startTag('classifier', 'name'=>$name);
|
---|
| 480 | $collwriter->startTag('classifier', 'name'=>$classname);
|
---|
| 481 | for (my $i=1; $i<scalar(@$cl); $i++) {
|
---|
| 482 | my $arg =@$cl[$i];
|
---|
| 483 | if ($arg =~ /^-/){
|
---|
| 484 | my $option_name=@$cl[$i];
|
---|
| 485 | my $option_value=@$cl[$i+1];
|
---|
| 486 | if (defined $option_value){
|
---|
| 487 | if ($option_value=~ /^-/){
|
---|
| 488 | $collwriter->startTag('option','name'=>$option_name);
|
---|
| 489 | $collwriter->endTag('option');
|
---|
| 490 | }else{
|
---|
| 491 | $collwriter->startTag('option','name'=>$option_name,'value'=>$option_value);
|
---|
| 492 | $collwriter->endTag('option');
|
---|
| 493 | }
|
---|
| 494 | }
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
| 497 |
|
---|
[10360] | 498 | my $vlist = $name."VList";
|
---|
| 499 | my $hlist = $name."HList";
|
---|
| 500 | my $dlist = "";
|
---|
[4184] | 501 | if ($classname eq "DateList") {
|
---|
| 502 | $dlist = "DateList";
|
---|
| 503 | }
|
---|
[10201] | 504 | # need to work out how to split into classifier and document
|
---|
[10360] | 505 | if (defined $format->{$vlist} || defined $format->{$hlist} || defined $format->{$dlist}) {
|
---|
[4184] | 506 | $collwriter->startTag('format');
|
---|
| 507 | if (defined $format->{$vlist}) {
|
---|
[10201] | 508 | write_format($collwriter, $format->{$vlist}, "document");
|
---|
[10360] | 509 | write_format($collwriter, $format->{$vlist}, "classifier");
|
---|
| 510 | }
|
---|
[4184] | 511 | if (defined $format->{$hlist}) {
|
---|
[10201] | 512 | write_format($collwriter, $format->{$hlist}, "horizontal");
|
---|
[10360] | 513 | }
|
---|
| 514 |
|
---|
[4184] | 515 | if (defined $format->{$dlist}) {
|
---|
[10201] | 516 | write_format($collwriter, $format->{$dlist}, "document");
|
---|
[4184] | 517 | }
|
---|
| 518 | $collwriter->endTag('format');
|
---|
| 519 | }
|
---|
| 520 | $collwriter->endTag('classifier');
|
---|
[4969] | 521 | } #foreach classifier
|
---|
[3688] | 522 | if ($started_classifiers) {
|
---|
| 523 | # end the classifiers
|
---|
[3979] | 524 | $buildwriter->endTag('classifierList');
|
---|
[8967] | 525 | # close off the Browse service
|
---|
| 526 | $buildwriter->endTag('serviceRack');
|
---|
[3688] | 527 | }
|
---|
[3947] | 528 |
|
---|
[4184] | 529 | $collwriter->endTag('browse');
|
---|
[3947] | 530 | }
|
---|
[4184] | 531 |
|
---|
[8967] | 532 |
|
---|
[3947] | 533 | # the phind classifier is a separate service
|
---|
| 534 | if ($phind) {
|
---|
| 535 | # if phind classifier
|
---|
[3979] | 536 | $buildwriter->emptyTag('serviceRack', 'name'=>'PhindPhraseBrowse');
|
---|
[3947] | 537 | }
|
---|
| 538 |
|
---|
| 539 | # do the search service
|
---|
[13912] | 540 | $buildwriter->startTag('serviceRack', 'name'=>'GS2'.$service_type.'Search');
|
---|
[14754] | 541 | #$buildwriter->emptyTag('defaultIndex', 'shortname'=>$defaultindex);
|
---|
[13912] | 542 | $buildwriter->startTag('indexList');
|
---|
| 543 | #for each index
|
---|
| 544 | foreach my $i (@indexlist) {
|
---|
| 545 | my $index = $indexmap->{$i};
|
---|
| 546 | $buildwriter->emptyTag('index', 'name'=>$i, 'shortname'=>$index);
|
---|
| 547 | }
|
---|
| 548 | $buildwriter->endTag('indexList');
|
---|
| 549 | if (defined $indexstem) {
|
---|
| 550 | $buildwriter->emptyTag('indexStem', 'name'=>$indexstem);
|
---|
| 551 | }
|
---|
| 552 |
|
---|
| 553 | # index options
|
---|
| 554 | if ($buildtype eq 'mg' || $buildtype eq 'mgpp') {
|
---|
| 555 | $buildwriter->startTag('indexOptionList');
|
---|
| 556 | my $stemindexes = 3; # default is stem and casefold
|
---|
| 557 | if (defined $buildcfg->{'stemindexes'} && $buildcfg->{'stemindexes'} =~ /^\d+$/ ) {
|
---|
| 558 | $stemindexes = $buildcfg->{'stemindexes'};
|
---|
| 559 | }
|
---|
| 560 | $buildwriter->emptyTag('indexOption', 'name'=>'stemIndexes', 'value'=>$stemindexes);
|
---|
| 561 |
|
---|
| 562 | my $maxnumeric = 4; # default
|
---|
| 563 | if (defined $buildcfg->{'maxnumeric'} && $buildcfg->{'maxnumeric'} =~ /^\d+$/) {
|
---|
| 564 | $maxnumeric = $buildcfg->{'maxnumeric'};
|
---|
| 565 | }
|
---|
| 566 | $buildwriter->emptyTag('indexOption', 'name'=>'maxnumeric', 'value'=>$maxnumeric);
|
---|
| 567 |
|
---|
| 568 | $buildwriter->endTag('indexOptionList');
|
---|
| 569 | }
|
---|
| 570 |
|
---|
[13228] | 571 | if ($buildtype eq 'mgpp' || $buildtype eq 'lucene') {
|
---|
[3947] | 572 |
|
---|
[13912] | 573 | # level info
|
---|
[14754] | 574 | $buildwriter->emptyTag('defaultLevel', 'shortname'=>$default_search_level_shortname);
|
---|
[13917] | 575 | $buildwriter->emptyTag('defaultGDBMLevel', 'shortname'=>$default_retrieve_level);
|
---|
[3979] | 576 | $buildwriter->startTag('levelList');
|
---|
[13917] | 577 | foreach my $l (@levellist) {
|
---|
| 578 | my $level = $levelmap->{$l};
|
---|
| 579 | $buildwriter->emptyTag('level', 'name'=>$l, 'shortname'=>$level);
|
---|
| 580 | }
|
---|
[3979] | 581 | $buildwriter->endTag('levelList');
|
---|
[3688] | 582 |
|
---|
[5647] | 583 | # do the search types if there
|
---|
| 584 | if (defined $collectcfg->{'searchtype'}) {
|
---|
| 585 | $buildwriter->startTag('searchTypeList');
|
---|
[10360] | 586 | foreach my $st (@{$collectcfg->{'searchtype'}}) {
|
---|
[5647] | 587 | $buildwriter->emptyTag('searchType', 'name'=>$st);
|
---|
| 588 | }
|
---|
| 589 | $buildwriter->endTag('searchTypeList');
|
---|
[13228] | 590 | } elsif (defined $format->{'SearchTypes'}) {
|
---|
| 591 | #check format statement
|
---|
| 592 | my $searchtype = $format->{'SearchTypes'};
|
---|
| 593 | $buildwriter->startTag('searchTypeList');
|
---|
| 594 | if ($searchtype =~ /form/) {
|
---|
| 595 | $buildwriter->emptyTag('searchType', 'name'=>'form');
|
---|
| 596 | }
|
---|
| 597 | if ($searchtype =~ /plain/) {
|
---|
| 598 | $buildwriter->emptyTag('searchType', 'name'=>'plain');
|
---|
| 599 | }
|
---|
| 600 | $buildwriter->endTag('searchTypeList');
|
---|
[5647] | 601 | }
|
---|
[13912] | 602 | }
|
---|
[3947] | 603 |
|
---|
[14754] | 604 | #indexLanguageList
|
---|
| 605 | my $indexlanguages = $collectcfg->{'languages'};
|
---|
| 606 | my $firstindexlanguage = 1;
|
---|
| 607 | my $defaultindexlanguage_shortname;
|
---|
| 608 | if (defined $indexlanguages){
|
---|
| 609 | $buildwriter->startTag('indexLanguageList');
|
---|
| 610 | my $languages_t = $collectcfg->{'languages'};
|
---|
| 611 | foreach my $i (@$languages_t){
|
---|
| 612 | $buildwriter->startTag('indexLanguage','name'=>$i);
|
---|
| 613 | &output_display($buildwriter, 'name', $i, $i);
|
---|
| 614 | $buildwriter->endTag('indexLanguage');
|
---|
| 615 | if ($firstindexlanguage==1){
|
---|
| 616 | $defaultindexlanguage_shortname = $i;
|
---|
| 617 | $firstindexlanguage=0;
|
---|
| 618 | }
|
---|
| 619 | }
|
---|
| 620 | $buildwriter->endTag('indexLanguageList');
|
---|
| 621 | $buildwriter->startTag('defaultIndexLanguage', 'name'=>$defaultindexlanguage_shortname,'shortname'=>$defaultindexlanguage_shortname);
|
---|
| 622 | $buildwriter->endTag('defaultIndexLanguage');
|
---|
| 623 | }
|
---|
[13115] | 624 |
|
---|
[14754] | 625 | # my $defaultsubcollection = "";
|
---|
| 626 | # my @subcollist;
|
---|
| 627 |
|
---|
| 628 | if (scalar(@subcollist)>0){
|
---|
| 629 |
|
---|
| 630 | $buildwriter->startTag('indexSubcollectionList');
|
---|
| 631 | foreach my $i (keys %$subcolmap){
|
---|
| 632 | my $short_name = $subcolmap->{$i};
|
---|
| 633 | $buildwriter->emptyTag('indexSubcollection', 'name'=>$i, 'shortname'=>$short_name);
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | $buildwriter->endTag('indexSubcollectionList');
|
---|
| 637 | $buildwriter->emptyTag('defaultIndexSubcollection', 'shortname'=>$defaultsubcollection);
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 |
|
---|
[3979] | 641 | $buildwriter->endTag('serviceRack');
|
---|
[4969] | 642 |
|
---|
[3979] | 643 | $buildwriter->endTag('serviceRackList');
|
---|
| 644 | $buildwriter->endTag('buildConfig');
|
---|
[11274] | 645 |
|
---|
| 646 | # we add in the default replace list just in case we have macros in the
|
---|
| 647 | # collection
|
---|
| 648 | $collwriter->emptyTag('replaceListRef', 'id'=>'gs2-standard');
|
---|
[14754] | 649 | $collwriter->endTag('CollectionConfig');
|
---|
[4969] | 650 | $collwriter->end();
|
---|
[3979] | 651 | $buildwriter->end();
|
---|
| 652 | $buildoutput->close();
|
---|
| 653 | $colloutput->close();
|
---|
[9899] | 654 | &close_database($database);
|
---|
[3979] | 655 | }
|
---|
[3688] | 656 |
|
---|
[3979] | 657 |
|
---|
[4969] | 658 | sub output_metadata {
|
---|
[14754] | 659 | my ($writer, $lang, $metaname, $metavalue) = @_;
|
---|
| 660 | $lang = 'en' if $lang eq 'default';
|
---|
| 661 | if ($lang ne ""){
|
---|
| 662 | $writer->startTag('metadata', 'lang'=>$lang, 'name'=>$metaname);
|
---|
| 663 | }else{
|
---|
| 664 | $writer->startTag('metadata', 'name'=>$metaname);
|
---|
| 665 | }
|
---|
[4184] | 666 | $writer->characters($metavalue);
|
---|
| 667 | $writer->endTag('metadata');
|
---|
| 668 | }
|
---|
| 669 |
|
---|
| 670 | sub output_display {
|
---|
[4969] | 671 | my ($writer, $name, $lang, $value) = @_;
|
---|
[4184] | 672 | $lang = 'en' if $lang eq 'default';
|
---|
| 673 | if ($lang =~ /^\[/) {
|
---|
| 674 | ($lang) = $lang =~ /\[l=(.*)\]/;
|
---|
[3979] | 675 | }
|
---|
[14754] | 676 |
|
---|
[4969] | 677 | $writer->startTag('displayItem', 'name'=>$name, 'lang'=>$lang);
|
---|
[4184] | 678 | $writer->characters($value);
|
---|
[4969] | 679 | $writer->endTag('displayItem');
|
---|
[3688] | 680 | }
|
---|
[4184] | 681 | sub format_icon_value {
|
---|
| 682 | my ($value) = @_;
|
---|
| 683 | if ($value =~ /^_/) {
|
---|
[13828] | 684 | my ($newvalue) = $value =~ /images\/(.*)$/;
|
---|
[4184] | 685 | if ($newvalue) {
|
---|
| 686 | return $newvalue;
|
---|
| 687 | }
|
---|
| 688 | }
|
---|
| 689 | return $value;
|
---|
| 690 | }
|
---|
[3688] | 691 |
|
---|
[13828] | 692 | sub tidy_up_display_item {
|
---|
[12678] | 693 | my ($value) = @_;
|
---|
| 694 | # remove \n
|
---|
| 695 | $value =~ s/\\n//g;
|
---|
| 696 | # replace \' with '
|
---|
| 697 | $value =~ s/\\\'/\'/g;
|
---|
| 698 | # replace \" with "
|
---|
| 699 | $value =~ s/\\\"/\"/g;
|
---|
[13828] | 700 | # replace _httpprefix_ with _httpsite_
|
---|
[13843] | 701 | $value =~ s/_httpprefix_/_httpsite_/g;
|
---|
| 702 | $value =~ s/_gwcgi_//g;
|
---|
| 703 | $value =~ s/[a-z][a-z]?=_cgiarg[a-z][a-z]?_&?//g;
|
---|
| 704 | $value =~ s/&p=/&sa=/g;
|
---|
[12678] | 705 | return $value;
|
---|
| 706 | }
|
---|
| 707 |
|
---|
[4184] | 708 | sub write_format {
|
---|
[10201] | 709 | my ($writer, $old_format, $node_type) = @_;
|
---|
[7471] | 710 | # replace \' with '
|
---|
| 711 | $old_format =~ s/\\\'/\'/g;
|
---|
[12236] | 712 | # replace \" with "
|
---|
| 713 | $old_format =~ s/\\\"/\"/g;
|
---|
[4184] | 714 | #convert [] to <gsf:...>
|
---|
[10360] | 715 | # assume no nesting {If} or {Or} for now
|
---|
| 716 | $old_format =~ s/\{If\}\{([^\}]*)\}/&format_if($1, $node_type)/eg;
|
---|
| 717 | $old_format =~ s/\{Or\}\{([^\}]*)\}/&format_or($1)/eg;
|
---|
[4184] | 718 | $old_format =~ s/\[Text\]/\<gsf:text\/\>/g;
|
---|
| 719 | $old_format =~ s/\[num\]/\<gsf:num\/\>/g;
|
---|
[10782] | 720 | $old_format =~ s/\[link\]/\<gsf:link type=\'$node_type\'\>/g;
|
---|
[4184] | 721 | $old_format =~ s/\[\/link\]/\<\/gsf:link\>/g;
|
---|
| 722 | $old_format =~ s/\[srclink\]/\<gsf:link type=\'source\'\>/g;
|
---|
| 723 | $old_format =~ s/\[\/srclink\]/\<\/gsf:link\>/g;
|
---|
[10782] | 724 | $old_format =~ s/\[icon\]/\<gsf:icon type=\'$node_type\'\/\>/g;
|
---|
[4184] | 725 | $old_format =~ s/\[srcicon\]/\<gsf:icon type=\'source\'\/\>/g;
|
---|
[10360] | 726 |
|
---|
| 727 | # what to do with hightlight??
|
---|
| 728 | $old_format =~ s/\[\/?highlight\]//g;
|
---|
[4184] | 729 |
|
---|
[4969] | 730 | #now do the rest of the [] which are assumed to be metadata
|
---|
[10360] | 731 | $old_format =~ s/\[([^\]]*)\]/&format_metadata($1)/eg;
|
---|
| 732 |
|
---|
| 733 | # some html tidy
|
---|
[4184] | 734 | #turn <br> into <br />
|
---|
| 735 | $old_format =~ s/\<br\>/\<br \/\>/g;
|
---|
| 736 | #turn <p> into <p />
|
---|
| 737 | $old_format =~ s/\<p\>/\<p \/\>/g;
|
---|
| 738 |
|
---|
| 739 | #put quotes around any atts
|
---|
| 740 | $old_format =~ s/=([a-z]+)([> ])/=\'$1\'$2/g;
|
---|
| 741 |
|
---|
[10201] | 742 | if ($node_type eq "document") {
|
---|
| 743 | $writer->startTag('gsf:template', 'match'=>'documentNode');
|
---|
| 744 | $writer->charactersXML($old_format);
|
---|
| 745 | $writer->endTag('gsf:template');
|
---|
| 746 | } elsif ($node_type eq "classifier") {
|
---|
| 747 | $writer->startTag('gsf:template', 'match'=>'classifierNode');
|
---|
| 748 | $writer->charactersXML($old_format);
|
---|
| 749 | $writer->endTag('gsf:template');
|
---|
| 750 | } elsif ($node_type eq "horizontal") {
|
---|
| 751 | $writer->startTag('gsf:template', 'match'=>'classifierNode', 'mode'=>'horizontal');
|
---|
| 752 | $writer->charactersXML($old_format);
|
---|
| 753 | $writer->endTag('gsf:template');
|
---|
[4184] | 754 |
|
---|
[10201] | 755 | }
|
---|
[4184] | 756 | }
|
---|
| 757 |
|
---|
[10360] | 758 | sub format_metadata {
|
---|
| 759 | my ($metadata_string) = @_;
|
---|
| 760 |
|
---|
| 761 | #print STDERR "original meta = $metadata_string\n";
|
---|
| 762 |
|
---|
| 763 | # what shall we do with cgisafe??
|
---|
| 764 | my $cgisafe = $metadata_string =~ s/^cgisafe://;
|
---|
| 765 |
|
---|
| 766 | my ($select) = $metadata_string =~ /^(parent|sibling)/;
|
---|
| 767 | $metadata_string =~ s/^(parent|sibling)//;
|
---|
| 768 | my ($scope, $delim);
|
---|
| 769 |
|
---|
| 770 | if ($select) {
|
---|
| 771 | ($scope) = $metadata_string =~ /^\((Top|All)/;
|
---|
| 772 | $metadata_string =~ s/^\((Top|All)\)?//;
|
---|
| 773 | if ($scope) {
|
---|
[10782] | 774 | ($delim) = $metadata_string =~ /^\'([^\']*)\'\)/;
|
---|
| 775 | $metadata_string =~ s/^\'([^\']*)\'\)//;
|
---|
[10360] | 776 | }
|
---|
| 777 | }
|
---|
| 778 | $metadata_string =~ s/^://;
|
---|
| 779 | # remove ex.
|
---|
| 780 | $metadata_string =~ s/^ex\.//;
|
---|
| 781 |
|
---|
| 782 | #print STDERR "select=$select, scope=$scope, delim=|$delim|, meta = $metadata_string\n";
|
---|
| 783 |
|
---|
| 784 | my $new_format = "<gsf:metadata name='$metadata_string' ";
|
---|
| 785 | if (defined $select) {
|
---|
| 786 | if ($select eq "sibling") {
|
---|
| 787 | $new_format .= "multiple='true' ";
|
---|
| 788 | if (defined $delim) {
|
---|
| 789 | $new_format .= "separator='$delim' ";
|
---|
| 790 | }
|
---|
| 791 | } elsif ($select eq "parent"){
|
---|
| 792 | if (defined $scope) {
|
---|
| 793 | if ($scope eq "Top") {
|
---|
| 794 | $new_format .= "select='root' ";
|
---|
| 795 | } elsif ($scope eq "All") {
|
---|
| 796 | $new_format .= "select='ancestors' ";
|
---|
| 797 | if (defined $delim) {
|
---|
| 798 | $new_format .= "separator='$delim' ";
|
---|
| 799 | }
|
---|
| 800 | }
|
---|
| 801 | } else {
|
---|
| 802 | $new_format .= "select='parent' ";
|
---|
| 803 | }
|
---|
| 804 | }
|
---|
| 805 | }
|
---|
| 806 | $new_format .= "/>";
|
---|
| 807 | #print STDERR "$new_format\n";
|
---|
| 808 | return $new_format;
|
---|
| 809 |
|
---|
| 810 | }
|
---|
| 811 |
|
---|
| 812 | sub format_if {
|
---|
| 813 |
|
---|
| 814 | my ($if_string, $node_type) = @_;
|
---|
[10782] | 815 | #print STDERR "if string = $if_string\n";
|
---|
[10360] | 816 |
|
---|
[10782] | 817 | my @parts = split /,/, $if_string;
|
---|
| 818 | my $test = $parts[0];
|
---|
| 819 | my $true_option = $parts[1];
|
---|
| 820 | my $false_option;
|
---|
| 821 | if (scalar (@parts) == 3) {
|
---|
| 822 | $false_option = $parts[2];
|
---|
| 823 | }
|
---|
| 824 | $test =~ s/^\s*//;
|
---|
| 825 | $test =~ s/\s*$//;
|
---|
| 826 | my ($test_meta, $test_type, $test_value);
|
---|
| 827 | if ($test =~ /^(\[.+\])$/) {
|
---|
| 828 | $test_meta = $1;
|
---|
| 829 | $test_type = 'exists';
|
---|
| 830 | } else {
|
---|
| 831 | my ($lhs, $exp, $rhs) = $test =~ /^(.+)\s+(eq|ne|lt|gt|le|ge|sw|ew)\s+(.+)$/;
|
---|
| 832 | #print STDERR "lhs, exp, rhs = $lhs, $exp, $rhs\n";
|
---|
| 833 | if ($exp eq "eq") {
|
---|
| 834 | $test_type = "equals";
|
---|
| 835 | } elsif ($exp eq "sw") {
|
---|
| 836 | $test_type = "startsWith";
|
---|
| 837 | } elsif ($exp eq "ew") {
|
---|
| 838 | $test_type = "endsWith";
|
---|
| 839 | } elsif ($exp eq "ne") {
|
---|
| 840 | $test_type = "notEquals";
|
---|
| 841 | } elsif ($exp eq "lt") {
|
---|
| 842 | $test_type = "lessThan";
|
---|
| 843 | }elsif ($exp eq "gt") {
|
---|
| 844 | $test_type = "greaterThan";
|
---|
| 845 | }elsif ($exp eq "le") {
|
---|
| 846 | $test_type = "lessThanOrEquals";
|
---|
| 847 | }elsif ($exp eq "ge") {
|
---|
| 848 | $test_type = "greaterThanOrEquals";
|
---|
| 849 | }
|
---|
| 850 | if ($lhs =~ /^\[.+\]$/) {
|
---|
| 851 | $test_meta = $lhs;
|
---|
| 852 | $test_value = $rhs;
|
---|
| 853 | } else {
|
---|
| 854 | # assume rhs has meta
|
---|
| 855 | $test_meta = $rhs;
|
---|
| 856 | $test_value = $lhs;
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | #remove beginning and end quotes
|
---|
| 860 | $test_value =~ s/^[\'\"]//;
|
---|
| 861 | $test_value =~ s/[\'\"]$//;
|
---|
| 862 | }
|
---|
| 863 | my $test_atts = "test='$test_type' ";
|
---|
| 864 | if (defined $test_value) {
|
---|
| 865 | $test_atts .= "test-value='$test_value' ";
|
---|
| 866 | }
|
---|
| 867 | #print STDERR "test, true, false = $test, $true_option, $false_option\n";
|
---|
| 868 | my $new_format = "<gsf:switch>$test_meta";
|
---|
| 869 | $new_format .= "<gsf:when $test_atts>$true_option</gsf:when>";
|
---|
| 870 | if (defined $false_option) {
|
---|
| 871 | $new_format .="<gsf:otherwise>$false_option</gsf:otherwise>";
|
---|
| 872 | }
|
---|
| 873 | $new_format .= "</gsf:switch>";
|
---|
| 874 |
|
---|
| 875 | #print STDERR "new format = $new_format\n";
|
---|
| 876 | return $new_format;
|
---|
[10360] | 877 | }
|
---|
| 878 |
|
---|
| 879 | sub format_or {
|
---|
| 880 | my ($or_string) = @_;
|
---|
| 881 | my @meta_list = split (',', $or_string);
|
---|
| 882 | return "" unless scalar (@meta_list);
|
---|
| 883 | my $new_format = "<gsf:choose-metadata>";
|
---|
| 884 | foreach my $m (@meta_list) {
|
---|
| 885 | if ($m =~ /^\[(.*)\]$/) {
|
---|
| 886 | $new_format .= &format_metadata($1);
|
---|
| 887 | } else {
|
---|
| 888 | # a default value
|
---|
| 889 | $new_format .= "<gsf:default>$m</gsf:default>";
|
---|
| 890 | last;
|
---|
| 891 | }
|
---|
| 892 | }
|
---|
| 893 | $new_format .= "</gsf:choose-metadata>";
|
---|
| 894 | return $new_format;
|
---|
| 895 | }
|
---|
| 896 |
|
---|
[9899] | 897 | sub open_database {
|
---|
| 898 | my ($db_file) = @_;
|
---|
| 899 |
|
---|
| 900 | my $database = ();
|
---|
[10658] | 901 | # tie (%$database, 'GDBM_File', $db_file, GDBM_READER, 0400) ||
|
---|
| 902 | # die "Couldn't open database $db_file\n";
|
---|
[9899] | 903 |
|
---|
| 904 | return $database;
|
---|
| 905 | }
|
---|
| 906 |
|
---|
| 907 | sub close_database {
|
---|
| 908 | my ($database) = @_;
|
---|
[10360] | 909 | untie %$database;
|
---|
[9899] | 910 | }
|
---|
| 911 | sub isHorizontalClassifier {
|
---|
| 912 | my ($database, $name) = @_;
|
---|
| 913 |
|
---|
[10658] | 914 | return 0; # can't get this to work for windows
|
---|
[10360] | 915 | my $record = $database->{$name};
|
---|
[9899] | 916 | my ($childtype) = $record =~ /<childtype>(\w*)/;
|
---|
| 917 | if ($childtype eq "HList") {
|
---|
| 918 | return 1;
|
---|
| 919 | }
|
---|
| 920 | return 0;
|
---|
| 921 | }
|
---|
[3688] | 922 | #$writer->startTag('');
|
---|
| 923 | #$writer->endTag('');
|
---|
| 924 | #$writer->characters();
|
---|
| 925 | #$writer->emptyTag('');
|
---|
| 926 |
|
---|
| 927 | 1;
|
---|