source: main/trunk/greenstone2/perllib/basebuildproc.pm

Last change on this file was 38299, checked in by davidb, 7 months ago

Away to have site name accessible in builderproc

  • Property svn:keywords set to Author Date Id Revision
File size: 23.7 KB
Line 
1##########################################################################
2#
3# basebuildproc.pm --
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26# This document processor outputs a document for indexing (should be
27# implemented by subclass) and storing in the database
28
29package basebuildproc;
30
31eval {require bytes};
32
33use classify;
34use dbutil;
35use doc;
36use docproc;
37use strict;
38no strict 'subs';
39no strict 'refs';
40use util;
41use FileUtils;
42
43BEGIN {
44 @basebuildproc::ISA = ('docproc');
45}
46
47sub new()
48 {
49 my ($class, $collection, $source_dir, $build_dir, $keepold, $verbosity, $outhandle) = @_;
50 my $self = new docproc ();
51
52 # outhandle is where all the debugging info goes
53 # output_handle is where the output of the plugins is piped
54 # to (i.e. mg, database etc.)
55 $outhandle = STDERR unless defined $outhandle;
56
57 $self->{'collection'} = $collection;
58 $self->{'source_dir'} = $source_dir;
59 $self->{'build_dir'} = $build_dir;
60 $self->{'keepold'} = $keepold;
61 $self->{'verbosity'} = $verbosity;
62 $self->{'outhandle'} = $outhandle;
63
64 $self->{'classifiers'} = [];
65 $self->{'mode'} = "text";
66 $self->{'assocdir'} = $build_dir;
67 $self->{'dontdb'} = {};
68 $self->{'store_metadata_coverage'} = "false";
69
70 $self->{'index'} = "section:text";
71 $self->{'indexexparr'} = [];
72
73 $self->{'separate_cjk'} = 0;
74
75 my $found_num_data = 0;
76 my $buildconfigfile = undef;
77
78 if ($keepold) {
79 # For incremental building need to seed num_docs etc from values
80 # stored in build.cfg (if present)
81 $buildconfigfile = &FileUtils::filenameConcatenate($build_dir, "build.cfg");
82 if (-e $buildconfigfile) {
83 $found_num_data = 1;
84 }
85 else {
86 # try the index dir
87 $buildconfigfile = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},
88 "index", "build.cfg");
89 if (-e $buildconfigfile) {
90 $found_num_data = 1;
91 }
92 }
93
94 }
95
96 if ($found_num_data)
97 {
98 #print STDERR "Found_Num_Data!\n";
99 my $buildcfg = &colcfg::read_build_cfg($buildconfigfile);
100 $self->{'starting_num_docs'} = $buildcfg->{'numdocs'};
101 #print STDERR "- num_docs: $self->{'starting_num_docs'}\n";
102 $self->{'starting_num_sections'} = $buildcfg->{'numsections'};
103 #print STDERR "- num_sections: $self->{'starting_num_sections'}\n";
104 $self->{'starting_num_bytes'} = $buildcfg->{'numbytes'};
105 #print STDERR "- num_bytes: $self->{'starting_num_bytes'}\n";
106 }
107 else
108 {
109 #print STDERR "NOT Found_Num_Data!\n";
110 $self->{'starting_num_docs'} = 0;
111 $self->{'starting_num_sections'} = 0;
112 $self->{'starting_num_bytes'} = 0;
113 }
114
115 $self->{'output_handle'} = "STDOUT";
116 $self->{'num_docs'} = $self->{'starting_num_docs'};
117 $self->{'num_sections'} = $self->{'starting_num_sections'};
118 $self->{'num_bytes'} = $self->{'starting_num_bytes'};
119
120 $self->{'num_processed_bytes'} = 0;
121 $self->{'store_text'} = 1;
122
123 # what level (section/document) the database - indexer intersection is
124 $self->{'db_level'} = "section";
125 #used by browse interface
126 $self->{'doclist'} = [];
127
128 $self->{'indexing_text'} = 0;
129
130 return bless $self, $class;
131
132}
133
134sub reset {
135 my $self = shift (@_);
136
137 $self->{'num_docs'} = $self->{'starting_num_docs'};
138 $self->{'num_sections'} = $self->{'starting_num_sections'};
139 $self->{'num_bytes'} = $self->{'starting_num_bytes'};
140
141 $self->{'num_processed_bytes'} = 0;
142}
143
144sub zero_reset {
145 my $self = shift (@_);
146
147 $self->{'num_docs'} = 0;
148 $self->{'num_sections'} = 0;
149 # reconstructed docs have no text, just metadata, so we need to
150 # remember how many bytes we had initially
151 #$self->{'num_bytes'} = $self->{'starting_num_bytes'};
152 $self->{'num_bytes'} = 0; # we'll store num bytes in db for reconstructed docs.
153 $self->{'num_processed_bytes'} = 0;
154}
155
156sub is_incremental_capable
157{
158 # By default we return 'no' as the answer
159 # Safer to assume non-incremental to start with, and then override in
160 # inherited classes that are.
161
162 return 0;
163}
164
165sub get_num_docs {
166 my $self = shift (@_);
167
168 return $self->{'num_docs'};
169}
170
171sub get_num_sections {
172 my $self = shift (@_);
173
174 return $self->{'num_sections'};
175}
176
177# num_bytes is the actual number of bytes in the collection
178# this is normally the same as what's processed during text compression
179sub get_num_bytes {
180 my $self = shift (@_);
181
182 return $self->{'num_bytes'};
183}
184
185# num_processed_bytes is the number of bytes actually passed
186# to mg for the current index
187sub get_num_processed_bytes {
188 my $self = shift (@_);
189
190 return $self->{'num_processed_bytes'};
191}
192
193sub set_output_handle {
194 my $self = shift (@_);
195 my ($handle) = @_;
196
197 $self->{'output_handle'} = $handle;
198 # The output handle isn't always an actual handle. In a couple of the
199 # database drivers (MSSQL and GDBMServer) it's actually a reference
200 # to an object. Thus we need to test the type before setting binmode.
201 # [jmt12]
202 if (ref $handle eq "GLOB")
203 {
204 binmode($handle,":utf8");
205 }
206}
207
208
209sub set_mode {
210 my $self = shift (@_);
211 my ($mode) = @_;
212
213 $self->{'mode'} = $mode;
214 $doc::processor_mode = $mode; # doc.pm needs to know what buildcol pass we're at
215}
216
217sub get_mode {
218 my $self = shift (@_);
219
220 return $self->{'mode'};
221}
222
223sub set_assocdir {
224 my $self = shift (@_);
225 my ($assocdir) = @_;
226
227 $self->{'assocdir'} = $assocdir;
228}
229
230sub set_dontdb {
231 my $self = shift (@_);
232 my ($dontdb) = @_;
233
234 $self->{'dontdb'} = $dontdb;
235}
236
237sub set_infodbtype
238{
239 my $self = shift(@_);
240 my $infodbtype = shift(@_);
241 $self->{'infodbtype'} = $infodbtype;
242}
243
244sub set_site
245{
246 my $self = shift(@_);
247 my $site = shift(@_);
248 $self->{'site'} = $site;
249}
250
251sub set_index {
252 my $self = shift (@_);
253 my ($index, $indexexparr) = @_;
254
255 $self->{'index'} = $index;
256 $self->{'indexexparr'} = $indexexparr if defined $indexexparr;
257}
258
259sub set_index_languages {
260 my $self = shift (@_);
261 my ($lang_meta, $langarr) = @_;
262 $lang_meta =~ s/^ex\.([^.]+)$/$1/; # strip any ex. namespace iff it's the only namespace prefix (will leave ex.dc.* intact)
263
264 $self->{'lang_meta'} = $lang_meta;
265 $self->{'langarr'} = $langarr;
266}
267
268sub get_index {
269 my $self = shift (@_);
270
271 return $self->{'index'};
272}
273
274sub set_classifiers {
275 my $self = shift (@_);
276 my ($classifiers) = @_;
277
278 $self->{'classifiers'} = $classifiers;
279}
280
281sub set_indexing_text {
282 my $self = shift (@_);
283 my ($indexing_text) = @_;
284
285 $self->{'indexing_text'} = $indexing_text;
286}
287
288sub get_indexing_text {
289 my $self = shift (@_);
290
291 return $self->{'indexing_text'};
292}
293
294sub set_store_text {
295 my $self = shift (@_);
296 my ($store_text) = @_;
297
298 $self->{'store_text'} = $store_text;
299}
300
301sub set_store_metadata_coverage {
302 my $self = shift (@_);
303 my ($store_metadata_coverage) = @_;
304
305 $self->{'store_metadata_coverage'} = $store_metadata_coverage || "";
306}
307
308sub get_doc_list {
309 my $self = shift(@_);
310
311 return @{$self->{'doclist'}};
312}
313
314# the standard database level is section, but you may want to change it to document
315sub set_db_level {
316 my $self= shift (@_);
317 my ($db_level) = @_;
318
319 $self->{'db_level'} = $db_level;
320}
321
322sub set_sections_index_document_metadata {
323 my $self= shift (@_);
324 my ($index_type) = @_;
325
326 $self->{'sections_index_document_metadata'} = $index_type;
327}
328
329sub set_separate_cjk {
330 my $self = shift (@_);
331 my ($sep_cjk) = @_;
332
333 $self->{'separate_cjk'} = $sep_cjk;
334}
335
336sub process {
337 my $self = shift (@_);
338 my $method = $self->{'mode'};
339
340 $self->$method(@_);
341}
342
343# post process text depending on field. Currently don't do anything here
344# except cjk separation, and only for indexing
345# should only do this for indexed text (if $self->{'indexing_text'}),
346# but currently search term highlighting doesn't work if you do that.
347# once thats fixed up, then fix this.
348sub filter_text {
349 my $self = shift (@_);
350 my ($field, $text) = @_;
351
352 # lets do cjk seg here
353 my $new_text =$text;
354 if ($self->{'separate_cjk'}) {
355 $new_text = &cnseg::segment($text);
356 }
357 return $new_text;
358}
359
360
361sub infodb_metadata_stats
362{
363 my $self = shift (@_);
364 my ($field,$edit_mode) = @_;
365
366 # Keep some statistics relating to metadata sets used and
367 # frequency of particular metadata fields within each set
368
369 # Union of metadata prefixes and frequency of fields
370 # (both scoped for this document alone, and across whole collection)
371
372 if ($field =~ m/^(.+)\.(.*)$/) {
373 my $prefix = $1;
374 my $core_field = $2;
375
376 if (($edit_mode eq "add") || ($edit_mode eq "update")) {
377 $self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}++;
378 $self->{'mdprefix_fields'}->{$prefix}->{$core_field}++;
379 }
380 else {
381 # delete
382 $self->{'doc_mdprefix_fields'}->{$prefix}->{$core_field}--;
383 $self->{'mdprefix_fields'}->{$prefix}->{$core_field}--;
384 }
385
386 }
387 elsif ($field =~ m/^[[:upper:]]/) {
388 # implicit 'ex' metadata set
389
390 if (($edit_mode eq "add") || ($edit_mode eq "update")) {
391
392 $self->{'doc_mdprefix_fields'}->{'ex'}->{$field}++;
393 $self->{'mdprefix_fields'}->{'ex'}->{$field}++;
394 }
395 else {
396 # delete
397 $self->{'doc_mdprefix_fields'}->{'ex'}->{$field}--;
398 $self->{'mdprefix_fields'}->{'ex'}->{$field}--;
399 }
400 }
401
402}
403
404
405sub infodbedit {
406 my $self = shift (@_);
407 my ($doc_obj, $filename, $edit_mode) = @_;
408
409 # print STDERR "**** basebuildproc::infodbedit(): $filename, $edit_mode\n";
410
411 # only output this document if it is a "indexed_doc" or "info_doc" (database only) document
412 my $doctype = $doc_obj->get_doc_type();
413 return if ($doctype ne "indexed_doc" && $doctype ne "info_doc");
414
415 my $archivedir = "";
416 if (defined $filename)
417 {
418 # doc_obj derived directly from file
419 my ($dir) = $filename =~ /^(.*?)(?:\/|\\)[^\/\\]*$/;
420 $dir = "" unless defined $dir;
421 $dir =~ s/\\/\//g;
422 $dir =~ s/^\/+//;
423 $dir =~ s/\/+$//;
424
425 $archivedir = $dir;
426
427 if ($edit_mode eq "delete") {
428 # record this doc so we don't process the reconstructed doc later
429 $self->{'dont_process_reconstructed'}->{$doc_obj->get_OID()} = 1;
430 # we don't need to do anything else for the info database for a deleted document. The infodb starts from scratch each time, so no deletion is necessary
431 $self->delete_assoc_files ($archivedir, "delete");
432 return;
433 }
434 if ($edit_mode eq "update") {
435 # we don't want to process the reconstructed doc later, but we will process this version now.
436 $self->{'dont_process_reconstructed'}->{$doc_obj->get_OID()} = 1;
437 # delete the old assoc files as they may have changed
438 $self->delete_assoc_files ($archivedir, "update");
439 }
440
441 # resolve the final filenames of the files associated with this document
442 # now save the new assoc files for an update/new doc.
443 $self->assoc_files ($doc_obj, $archivedir);
444 }
445 else
446 {
447 # doc_obj reconstructed from database (has metadata, doc structure but no text)
448 my $top_section = $doc_obj->get_top_section();
449 $archivedir = $doc_obj->get_metadata_element($top_section,"archivedir");
450 }
451
452 # rest of code used for add and update. In both cases, we add to the classifiers and to the info database.
453
454 #add this document to the browse structure
455 push(@{$self->{'doclist'}},$doc_obj->get_OID())
456 unless ($doctype eq "classification");
457 $self->{'num_docs'} += 1 unless ($doctype eq "classification");
458
459 if (!defined $filename) {
460 # a reconstructed doc
461 my $num_reconstructed_bytes = $doc_obj->get_metadata_element ($doc_obj->get_top_section (), "total_numbytes");
462 if (defined $num_reconstructed_bytes) {
463 $self->{'num_bytes'} += $num_reconstructed_bytes;
464 }
465 }
466 # classify the document
467 &classify::classify_doc ($self->{'classifiers'}, $doc_obj);
468
469 # now add all the sections to the infodb.
470
471 # is this a paged or a hierarchical document
472 my ($thistype, $childtype) = $self->get_document_type ($doc_obj);
473
474 my $section = $doc_obj->get_top_section ();
475 my $doc_OID = $doc_obj->get_OID();
476 my $first = 1;
477 my $infodb_handle = $self->{'output_handle'};
478
479 $self->{'doc_mdprefix_fields'} = {};
480
481 while (defined $section)
482 {
483 my $section_OID = $doc_OID;
484 if ($section ne "")
485 {
486 $section_OID = $doc_OID . "." . $section;
487 }
488 my %section_infodb = ();
489
490 # update a few statistics
491 $self->{'num_bytes'} += $doc_obj->get_text_length ($section);
492 $self->{'num_sections'} += 1 unless ($doctype eq "classification");
493
494 # output the fact that this document is a document (unless doctype
495 # has been set to something else from within a plugin
496 my $dtype = $doc_obj->get_metadata_element ($section, "doctype");
497 if (!defined $dtype || $dtype !~ /\w/) {
498 $section_infodb{"doctype"} = [ "doc" ];
499 }
500
501 if ($first && defined $filename) {
502 # if we are at the top level of the document, and we are not a reconstructed document, set the total_text_length - used to count bytes when we reconstruct later
503 my $length = $doc_obj->get_total_text_length();
504 $section_infodb{"total_numbytes"} = [ $length ];
505 }
506 # Output whether this node contains text
507 #
508 # If doc_obj reconstructed from database file then no need to
509 # explicitly add <hastxt> as this is preserved as metadata when
510 # the database file is loaded in
511 if (defined $filename)
512 {
513 # doc_obj derived directly from file
514 if ($doc_obj->get_text_length($section) > 0) {
515 $section_infodb{"hastxt"} = [ "1" ];
516 } else {
517 $section_infodb{"hastxt"} = [ "0" ];
518 }
519 }
520
521 # output all the section metadata
522 my $metadata = $doc_obj->get_all_metadata ($section);
523 foreach my $pair (@$metadata) {
524 my ($field, $value) = (@$pair);
525
526 if ($field ne "Identifier" && $field !~ /^gsdl/ &&
527 defined $value && $value ne "") {
528
529 # escape problematic stuff
530 $value =~ s/([^\\])\\([^\\])/$1\\\\$2/g;
531 $value =~ s/\n/\\n/g;
532 $value =~ s/\r/\\r/g;
533 # remove any ex. iff it's the only namespace prefix (will leave ex.dc.* intact)
534 $field =~ s/^ex\.([^.]+)$/$1/; # $field =~ s/^ex\.//;
535
536 # special case for UTF8URL metadata
537 if ($field =~ m/^UTF8URL$/i) {
538 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle,
539 $value, { 'section' => [ $section_OID ] });
540 }
541
542 if (!defined $self->{'dontdb'}->{$field}) {
543 push(@{$section_infodb{$field}}, $value);
544
545 if ($section eq ""
546 && (($self->{'store_metadata_coverage'} =~ /^true$/i)
547 || $self->{'store_metadata_coverage'} eq "1"))
548 {
549 $self->infodb_metadata_stats($field,$edit_mode);
550 }
551 }
552 }
553 }
554
555 if ($section eq "")
556 {
557 my $doc_mdprefix_fields = $self->{'doc_mdprefix_fields'};
558
559 foreach my $prefix (keys %$doc_mdprefix_fields)
560 {
561 push(@{$section_infodb{"metadataset"}}, $prefix);
562
563 foreach my $field (keys %{$doc_mdprefix_fields->{$prefix}})
564 {
565 push(@{$section_infodb{"metadatalist-$prefix"}}, $field);
566
567 my $val = $doc_mdprefix_fields->{$prefix}->{$field};
568 push(@{$section_infodb{"metadatafreq-$prefix-$field"}}, $val);
569 }
570 }
571 }
572
573 # If doc_obj reconstructed from database file then no need to
574 # explicitly add <archivedir> as this is preserved as metadata when
575 # the database file is loaded in
576 if (defined $filename)
577 {
578 # output archivedir if at top level
579 if ($section eq $doc_obj->get_top_section()) {
580 $section_infodb{"archivedir"} = [ $archivedir ];
581 }
582 }
583
584 # output document display type
585 if ($first) {
586 $section_infodb{"thistype"} = [ $thistype ];
587 }
588
589 if ($self->{'db_level'} eq "document") {
590 # doc num is num_docs not num_sections
591 # output the matching document number
592 $section_infodb{"docnum"} = [ $self->{'num_docs'} ];
593 }
594 else {
595 # output a list of children
596 my $children = $doc_obj->get_children ($section);
597 if (scalar(@$children) > 0) {
598 $section_infodb{"childtype"} = [ $childtype ];
599 my $contains = "";
600 foreach my $child (@$children)
601 {
602 $contains .= ";" unless ($contains eq "");
603 if ($child =~ /^.*?\.(\d+)$/)
604 {
605 $contains .= "\".$1";
606 }
607 else
608 {
609 $contains .= "\".$child";
610 }
611 }
612 $section_infodb{"contains"} = [ $contains ];
613 }
614 # output the matching doc number
615 $section_infodb{"docnum"} = [ $self->{'num_sections'} ];
616 }
617
618 if(defined $section_infodb{'assocfilepath'})
619 {
620 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_infodb{'assocfilepath'}[0], { 'contains' => [ $section_OID ]});
621 }
622 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $section_OID, \%section_infodb);
623
624 # output a database entry for the document number, unless we are incremental
625 unless ($self->is_incremental_capable())
626 {
627 if ($self->{'db_level'} eq "document") {
628 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_docs'}, { 'section' => [ $doc_OID ] });
629 }
630 else {
631 &dbutil::write_infodb_entry($self->{'infodbtype'}, $infodb_handle, $self->{'num_sections'}, { 'section' => [ $section_OID ] });
632 }
633 }
634
635 $first = 0;
636 $section = $doc_obj->get_next_section($section);
637 last if ($self->{'db_level'} eq "document"); # if no sections wanted, only add the docs
638 } # while defined section
639
640}
641
642
643
644
645sub infodb {
646 my $self = shift (@_);
647 my ($doc_obj, $filename) = @_;
648
649 $self->infodbedit($doc_obj,$filename,"add");
650}
651
652sub infodbreindex {
653 my $self = shift (@_);
654 my ($doc_obj, $filename) = @_;
655
656 $self->infodbedit($doc_obj,$filename,"update");
657}
658
659sub infodbdelete {
660 my $self = shift (@_);
661 my ($doc_obj, $filename) = @_;
662
663 $self->infodbedit($doc_obj,$filename,"delete");
664}
665
666
667sub text {
668 my $self = shift (@_);
669 my ($doc_obj) = @_;
670
671 my $handle = $self->{'outhandle'};
672 print $handle "basebuildproc::text function must be implemented in sub classes\n";
673 die "\n";
674}
675
676sub textreindex
677{
678 my $self = shift @_;
679
680 my $outhandle = $self->{'outhandle'};
681 print $outhandle "basebuildproc::textreindex function must be implemented in sub classes\n";
682 if (!$self->is_incremental_capable()) {
683
684 print $outhandle " This operation is only possible with indexing tools with that support\n";
685 print $outhandle " incremental building\n";
686 }
687 die "\n";
688}
689
690sub textdelete
691{
692 my $self = shift @_;
693
694 my $outhandle = $self->{'outhandle'};
695 print $outhandle "basebuildproc::textdelete function must be implemented in sub classes\n";
696 if (!$self->is_incremental_capable()) {
697
698 print $outhandle " This operation is only possible with indexing tools with that support\n";
699 print $outhandle " incremental building\n";
700 }
701 die "\n";
702}
703
704
705# should the document be indexed - according to the subcollection and language
706# specification.
707sub is_subcollection_doc {
708 my $self = shift (@_);
709 my ($doc_obj) = @_;
710
711 my $indexed_doc = 1;
712 foreach my $indexexp (@{$self->{'indexexparr'}}) {
713 $indexed_doc = 0;
714 my ($field, $exp, $options) = split /\//, $indexexp;
715 if (defined ($field) && defined ($exp)) {
716 my ($bool) = $field =~ /^(.)/;
717 $field =~ s/^.// if $bool eq '!';
718 my @metadata_values;
719 if ($field =~ /^filename$/i) {
720 push(@metadata_values, $doc_obj->get_source_filename());
721 }
722 else {
723 $field =~ s/^ex\.([^.]+)$/$1/; # remove any ex. iff it's the only namespace prefix (will leave ex.dc.* intact)
724 @metadata_values = @{$doc_obj->get_metadata($doc_obj->get_top_section(), $field)};
725 }
726 next unless @metadata_values;
727 foreach my $metadata_value (@metadata_values) {
728 if ($bool eq '!') {
729 if (defined $options && $options =~ /^i$/i) {
730 if ($metadata_value !~ /$exp/i) {$indexed_doc = 1; last;}
731 } else {
732 if ($metadata_value !~ /$exp/) {$indexed_doc = 1; last;}
733 }
734 } else {
735 if (defined $options && $options =~ /^i$/i) {
736 if ($metadata_value =~ /$exp/i) {$indexed_doc = 1; last;}
737 } else {
738 if ($metadata_value =~ /$exp/) {$indexed_doc = 1; last;}
739 }
740 }
741 }
742
743 last if ($indexed_doc == 1);
744 }
745 }
746
747 # if this doc is so far in the sub collection, and we have lang info,
748 # now we check the languages to see if it matches
749 if($indexed_doc && defined $self->{'lang_meta'}) {
750 $indexed_doc = 0;
751 my $field = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $self->{'lang_meta'});
752 if (defined $field) {
753 foreach my $lang (@{$self->{'langarr'}}) {
754 my ($bool) = $lang =~ /^(.)/;
755 if ($bool eq '!') {
756 $lang =~ s/^.//;
757 if ($field !~ /$lang/) {
758 $indexed_doc = 1; last;
759 }
760 } else {
761 if ($field =~ /$lang/) {
762 $indexed_doc = 1; last;
763 }
764 }
765 }
766 }
767 }
768 return $indexed_doc;
769
770}
771
772# use 'Paged' if document has no more than 2 levels
773# and each section at second level has a number for
774# Title metadata
775# also use Paged if gsdlthistype metadata is set to Paged
776sub get_document_type {
777 my $self = shift (@_);
778 my ($doc_obj) = @_;
779
780 my $thistype = "VList";
781 my $childtype = "VList";
782 my $title;
783 my @tmp = ();
784
785 my $section = $doc_obj->get_top_section ();
786
787 my $gsdlthistype = $doc_obj->get_metadata_element ($section, "gsdlthistype");
788 if (defined $gsdlthistype) {
789 if ($gsdlthistype =~ /^paged$/i) {
790 $childtype = "Paged";
791 if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
792 $thistype = "Paged";
793 } else {
794 $thistype = "Invisible";
795 }
796
797 return ($thistype, $childtype);
798 }
799 # gs3 pagedhierarchy option
800 elsif ($gsdlthistype =~ /^pagedhierarchy$/i) {
801 $childtype = "PagedHierarchy";
802 if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
803 $thistype = "PagedHierarchy";
804 } else {
805 $thistype = "Invisible";
806 }
807
808 return ($thistype, $childtype);
809 } elsif ($gsdlthistype =~ /^hierarchy$/i) {
810 return ($thistype, $childtype); # use VList, VList
811 }
812 }
813 my $first = 1;
814 while (defined $section) {
815 @tmp = split /\./, $section;
816 if (scalar(@tmp) > 1) {
817 return ($thistype, $childtype);
818 }
819 if (!$first) {
820 $title = $doc_obj->get_metadata_element ($section, "Title");
821 if (!defined $title || $title !~ /^\d+$/) {
822 return ($thistype, $childtype);
823 }
824 }
825 $first = 0;
826 $section = $doc_obj->get_next_section($section);
827 }
828 if ($doc_obj->get_text_length ($doc_obj->get_top_section())) {
829 $thistype = "Paged";
830 } else {
831 $thistype = "Invisible";
832 }
833 $childtype = "Paged";
834 return ($thistype, $childtype);
835}
836
837sub assoc_files
838{
839 my $self = shift (@_);
840 my ($doc_obj, $archivedir) = @_;
841 my ($afile);
842
843 foreach my $assoc_file (@{$doc_obj->get_assoc_files()}) {
844 #rint STDERR "Processing associated file - copy " . $assoc_file->[0] . " to " . $assoc_file->[1] . "\n";
845 # if assoc file starts with a slash, we put it relative to the assoc
846 # dir, otherwise it is relative to the HASH... directory
847 if ($assoc_file->[1] =~ m@^[/\\]@) {
848 $afile = &FileUtils::filenameConcatenate($self->{'assocdir'}, $assoc_file->[1]);
849 } else {
850 $afile = &FileUtils::filenameConcatenate($self->{'assocdir'}, $archivedir, $assoc_file->[1]);
851 }
852
853 &FileUtils::hardLink($assoc_file->[0], $afile, $self->{'verbosity'});
854 }
855}
856
857sub delete_assoc_files
858{
859 my $self = shift (@_);
860 my ($archivedir, $edit_mode) = @_;
861
862 my $assoc_dir = &FileUtils::filenameConcatenate($self->{'assocdir'}, $archivedir);
863 if (-d $assoc_dir) {
864 &FileUtils::removeFilesRecursive($assoc_dir);
865 }
866}
Note: See TracBrowser for help on using the repository browser.