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

Last change on this file since 24404 was 24404, checked in by ak19, 10 years ago

Changes to perl code to do with removing the ex. prefix: ex. is only removed if it is the sole prefix (i.e. ex.dc.* prefixes are not removed).

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