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