[12330] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # DSpacePlugout.pm -- the plugout module for DSpace archives
|
---|
| 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) 2006 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 | package DSpacePlugout;
|
---|
| 27 |
|
---|
| 28 | use strict;
|
---|
| 29 | no strict 'refs';
|
---|
| 30 |
|
---|
| 31 | eval {require bytes};
|
---|
| 32 | use util;
|
---|
[17203] | 33 | use BasePlugout;
|
---|
[12330] | 34 |
|
---|
| 35 | sub BEGIN {
|
---|
[17203] | 36 | @DSpacePlugout::ISA = ('BasePlugout');
|
---|
[12330] | 37 | }
|
---|
| 38 |
|
---|
| 39 | my $arguments = [];
|
---|
| 40 |
|
---|
| 41 | my $options = { 'name' => "DSpacePlugout",
|
---|
| 42 | 'desc' => "{DSpacePlugout.desc}",
|
---|
| 43 | 'abstract' => "no",
|
---|
| 44 | 'inherits' => "yes" };
|
---|
| 45 |
|
---|
| 46 | sub new {
|
---|
| 47 | my ($class) = shift (@_);
|
---|
| 48 | my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
|
---|
| 49 | push(@$plugoutlist, $class);
|
---|
| 50 |
|
---|
[17203] | 51 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 52 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[12330] | 53 |
|
---|
[17203] | 54 | my $self = new BasePlugout($plugoutlist,$inputargs,$hashArgOptLists);
|
---|
[12330] | 55 |
|
---|
[17203] | 56 | return bless $self, $class;
|
---|
[12330] | 57 | }
|
---|
| 58 |
|
---|
| 59 | sub saveas {
|
---|
| 60 | my $self = shift (@_);
|
---|
| 61 | my ($doc_obj,$doc_dir) = @_;
|
---|
| 62 |
|
---|
| 63 | my $output_dir = $self->get_output_dir();
|
---|
| 64 | &util::mk_all_dir ($output_dir) unless -e $output_dir;
|
---|
| 65 |
|
---|
| 66 | my $working_dir = &util::filename_cat ($output_dir, $doc_dir);
|
---|
| 67 | &util::mk_all_dir ($working_dir, $doc_dir);
|
---|
| 68 |
|
---|
| 69 | #########################
|
---|
| 70 | # save the handle file
|
---|
| 71 | #########################
|
---|
| 72 | my $outhandle = $self->{'output_handle'};
|
---|
| 73 |
|
---|
| 74 | # Genereate handle file
|
---|
| 75 | # (Note: this section of code would benefit from being restructured)
|
---|
| 76 | my $doc_handle_file = &util::filename_cat ($working_dir, "handle");
|
---|
| 77 |
|
---|
| 78 | my $env_hp = $ENV{'DSPACE_HANDLE_PREFIX'};
|
---|
| 79 | my $handle_prefix = (defined $env_hp) ? $env_hp : "123456789";
|
---|
| 80 |
|
---|
| 81 | my $outhandler = $self->get_output_handler($doc_handle_file);
|
---|
| 82 |
|
---|
[20536] | 83 | my ($handle) = ($doc_dir =~ m/^(.*)(:?\.dir)?$/);
|
---|
[12330] | 84 |
|
---|
| 85 | print $outhandler "$handle_prefix/$handle\n";
|
---|
| 86 |
|
---|
| 87 | close ($outhandler);
|
---|
| 88 |
|
---|
| 89 | #########################
|
---|
| 90 | # save the content file
|
---|
| 91 | #########################
|
---|
| 92 | my $doc_contents_file = &util::filename_cat ($working_dir, "contents");
|
---|
| 93 |
|
---|
| 94 | $outhandler = $self->get_output_handler($doc_contents_file);
|
---|
| 95 |
|
---|
| 96 | $self->process_assoc_files ($doc_obj, $doc_dir, $outhandler);
|
---|
| 97 |
|
---|
[20642] | 98 | $self->process_metafiles_metadata ($doc_obj);
|
---|
| 99 |
|
---|
[12330] | 100 | close($outhandler);
|
---|
| 101 |
|
---|
| 102 | #############################
|
---|
| 103 | # save the dublin_core.xml file
|
---|
| 104 | ###############################
|
---|
| 105 | my $doc_dc_file = &util::filename_cat ($working_dir, "dublin_core.xml");
|
---|
| 106 | $self->open_xslt_pipe($doc_dc_file,$self->{'xslt_file'});
|
---|
| 107 |
|
---|
| 108 | if (defined $self->{'xslt_writer'}){
|
---|
| 109 | $outhandler = $self->{'xslt_writer'};
|
---|
| 110 | }
|
---|
| 111 | else{
|
---|
| 112 | $outhandler = $self->get_output_handler($doc_dc_file);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | $self->output_xml_header($outhandler, "dublin_core",1);
|
---|
[13172] | 116 |
|
---|
| 117 | my $all_text = $self->get_dc_metadata($doc_obj, $doc_obj->get_top_section());
|
---|
| 118 | print $outhandler $all_text;
|
---|
| 119 |
|
---|
[12330] | 120 | $self->output_xml_footer($outhandler,"dublin_core");
|
---|
| 121 |
|
---|
| 122 | if (defined $self->{'xslt_writer'}){
|
---|
| 123 | $self->close_xslt_pipe();
|
---|
| 124 | }
|
---|
| 125 | else{
|
---|
| 126 | close($outhandler);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | $self->{'short_doc_file'} = &util::filename_cat ($doc_dir, "dublin_core.xml");
|
---|
[12363] | 130 | $self->store_output_info_reference($doc_obj);
|
---|
[12330] | 131 | }
|
---|
| 132 |
|
---|
| 133 | sub process_assoc_files {
|
---|
| 134 | my $self = shift (@_);
|
---|
| 135 | my ($doc_obj, $doc_dir, $handle) = @_;
|
---|
| 136 |
|
---|
| 137 | my $outhandler = $self->{'output_handle'};
|
---|
| 138 |
|
---|
| 139 | my $output_dir = $self->get_output_dir();
|
---|
| 140 | return if (!defined $output_dir);
|
---|
| 141 |
|
---|
| 142 | my $working_dir = &util::filename_cat($output_dir, $doc_dir);
|
---|
| 143 |
|
---|
| 144 | my @assoc_files = ();
|
---|
| 145 | my $filename;;
|
---|
| 146 |
|
---|
| 147 | my $source_filename = $doc_obj->get_source_filename();
|
---|
| 148 |
|
---|
| 149 | my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
|
---|
| 150 |
|
---|
| 151 | if (defined $collect_dir) {
|
---|
| 152 | my $dirsep_regexp = &util::get_os_dirsep();
|
---|
| 153 |
|
---|
| 154 | if ($collect_dir !~ /$dirsep_regexp$/) {
|
---|
| 155 | $collect_dir .= &util::get_dirsep(); # ensure there is a slash at the end
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | # This test is never going to fail on Windows -- is this a problem?
|
---|
| 159 | if ($source_filename !~ /^$dirsep_regexp/) {
|
---|
| 160 | $source_filename = &util::filename_cat($collect_dir, $source_filename);
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[20903] | 164 | my ($tail_filename) = ($source_filename =~ m/([^\/\\]*)$/);
|
---|
[12330] | 165 |
|
---|
| 166 | print $handle "$tail_filename\n";
|
---|
| 167 |
|
---|
| 168 | $filename = &util::filename_cat($working_dir, $tail_filename);
|
---|
[18463] | 169 | &util::hard_link ($source_filename, $filename, $self->{'verbosity'});
|
---|
[12330] | 170 |
|
---|
| 171 | # set the assocfile path (even if we have no assoc files - need this for lucene)
|
---|
| 172 | $doc_obj->set_utf8_metadata_element ($doc_obj->get_top_section(),
|
---|
| 173 | "assocfilepath",
|
---|
| 174 | "$doc_dir");
|
---|
| 175 | foreach my $assoc_file_rec (@{$doc_obj->get_assoc_files()}) {
|
---|
| 176 | my ($dir, $afile) = $assoc_file_rec->[1] =~ /^(.*?)([^\/\\]+)$/;
|
---|
| 177 | $dir = "" unless defined $dir;
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | my $real_filename = $assoc_file_rec->[0];
|
---|
| 181 | # for some reasons the image associate file has / before the full path
|
---|
| 182 | $real_filename =~ s/^\\(.*)/$1/i;
|
---|
| 183 | if (-e $real_filename) {
|
---|
| 184 |
|
---|
| 185 | if ($real_filename =~ m/$source_filename$/) {
|
---|
| 186 | next;
|
---|
| 187 | }
|
---|
| 188 | else {
|
---|
| 189 | my $bundle = "bundle:ORIGINAL";
|
---|
| 190 |
|
---|
| 191 | if ($afile =~ m/^thumbnail\./) {
|
---|
| 192 | $bundle = "bundle:THUMBNAIL";
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | # Store the associated file to the "contents" file
|
---|
| 196 | print $handle "$assoc_file_rec->[1]\t$bundle\n";
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | $filename = &util::filename_cat($working_dir, $afile);
|
---|
| 201 |
|
---|
| 202 |
|
---|
[18463] | 203 | &util::hard_link ($real_filename, $filename, $self->{'verbosity'});
|
---|
[12330] | 204 |
|
---|
| 205 | $doc_obj->add_utf8_metadata ($doc_obj->get_top_section(),
|
---|
| 206 | "gsdlassocfile",
|
---|
| 207 | "$afile:$assoc_file_rec->[2]:$dir");
|
---|
| 208 | } elsif ($self->{'verbosity'} > 2) {
|
---|
| 209 | print $outhandler "DSpacePlugout::process couldn't copy the associated file " .
|
---|
| 210 | "$real_filename to $afile\n";
|
---|
| 211 | }
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 |
|
---|
| 216 | sub get_new_doc_dir{
|
---|
| 217 | my $self = shift (@_);
|
---|
| 218 | my($working_info,$working_dir,$OID) = @_;
|
---|
| 219 |
|
---|
| 220 | return $OID;
|
---|
| 221 |
|
---|
| 222 | }
|
---|