1 | # This document processor saves a document in the
|
---|
2 | # archives directory of a collection
|
---|
3 |
|
---|
4 |
|
---|
5 | package docsave;
|
---|
6 |
|
---|
7 | use arcinfo;
|
---|
8 | use docproc;
|
---|
9 | use util;
|
---|
10 |
|
---|
11 |
|
---|
12 | sub BEGIN {
|
---|
13 | @ISA = ('docproc');
|
---|
14 | }
|
---|
15 |
|
---|
16 | sub new {
|
---|
17 | my ($class, $collection, $archive_info) = @_;
|
---|
18 | my $self = new docproc ();
|
---|
19 |
|
---|
20 | $self->{'collection'} = $collection;
|
---|
21 | $self->{'archive_info'} = $archive_info;
|
---|
22 |
|
---|
23 | return bless $self, $class;
|
---|
24 | }
|
---|
25 |
|
---|
26 | sub process {
|
---|
27 | my $self = shift (@_);
|
---|
28 | my ($doc_obj) = @_;
|
---|
29 |
|
---|
30 | my $archive_dir = "$ENV{'GSDLHOME'}/collect/$self->{'collection'}/archives";
|
---|
31 | my $OID = $doc_obj->get_OID();
|
---|
32 | $OID = "NULL" unless defined $OID;
|
---|
33 |
|
---|
34 | # get the document's directory by inserting a / every 1-8 characters
|
---|
35 | # and removing the last /
|
---|
36 | my $doc_dir = $OID;
|
---|
37 | $doc_dir =~ s/(.{1,8})/$1\//g;
|
---|
38 | $doc_dir =~ s/\/$//;
|
---|
39 | $doc_dir .= ".dir";
|
---|
40 | &util::mk_all_dir ("$archive_dir/$doc_dir");
|
---|
41 |
|
---|
42 | # copy all the associated files, add this information as metadata
|
---|
43 | # to the document
|
---|
44 | my @assoc_files = ();
|
---|
45 | foreach $assoc_file (@{$doc_obj->get_assoc_files()}) {
|
---|
46 | if (-e $assoc_file->[0]) {
|
---|
47 | &util::cp ($assoc_file->[0], "$archive_dir/$doc_dir/$assoc_file->[1]");
|
---|
48 | $doc_obj->add_metadata ($doc_obj->get_top_section(),
|
---|
49 | "gsdlassocfile",
|
---|
50 | "$assoc_file->[1]:$assoc_file->[2]");
|
---|
51 | } else {
|
---|
52 | print STDERR "docsave::process couldn't copy the associated file " .
|
---|
53 | "$assoc_file->[0] to $archive_dir/$doc_dir/$assoc_file->[1]\n"
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | # save this document
|
---|
58 | if (!open (OUTDOC, ">$archive_dir/$doc_dir/doc.gml")) {
|
---|
59 | print STDERR "docsave::process could not write to file " .
|
---|
60 | "$archive_dir/$doc_dir/doc.gml\n";
|
---|
61 | return;
|
---|
62 | }
|
---|
63 | $doc_obj->output_section('docsave::OUTDOC', $doc_obj->get_top_section());
|
---|
64 | close OUTDOC;
|
---|
65 |
|
---|
66 | # store reference in the archive_info
|
---|
67 | $self->{'archive_info'}->add_info($OID,
|
---|
68 | "$doc_dir/doc.gml");
|
---|
69 |
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | 1;
|
---|