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