source: gsdl/trunk/perllib/plugouts/DSpacePlugout.pm@ 17203

Last change on this file since 17203 was 17203, checked in by kjdon, 16 years ago

BasPlugout renamed to BasePlugout. And tidied up the constructors

  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
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
26package DSpacePlugout;
27
28use strict;
29no strict 'refs';
30
31eval {require bytes};
32use util;
33use BasePlugout;
34
35sub BEGIN {
36 @DSpacePlugout::ISA = ('BasePlugout');
37}
38
39my $arguments = [];
40
41my $options = { 'name' => "DSpacePlugout",
42 'desc' => "{DSpacePlugout.desc}",
43 'abstract' => "no",
44 'inherits' => "yes" };
45
46sub new {
47 my ($class) = shift (@_);
48 my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
49 push(@$plugoutlist, $class);
50
51 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
52 push(@{$hashArgOptLists->{"OptList"}},$options);
53
54 my $self = new BasePlugout($plugoutlist,$inputargs,$hashArgOptLists);
55
56 return bless $self, $class;
57}
58
59sub 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
83 my ($handle) = ($doc_dir =~ m/^(.*)\.dir$/);
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
98 close($outhandler);
99
100 #############################
101 # save the dublin_core.xml file
102 ###############################
103 my $doc_dc_file = &util::filename_cat ($working_dir, "dublin_core.xml");
104 $self->open_xslt_pipe($doc_dc_file,$self->{'xslt_file'});
105
106 if (defined $self->{'xslt_writer'}){
107 $outhandler = $self->{'xslt_writer'};
108 }
109 else{
110 $outhandler = $self->get_output_handler($doc_dc_file);
111 }
112
113 $self->output_xml_header($outhandler, "dublin_core",1);
114
115 my $all_text = $self->get_dc_metadata($doc_obj, $doc_obj->get_top_section());
116 print $outhandler $all_text;
117
118 $self->output_xml_footer($outhandler,"dublin_core");
119
120 if (defined $self->{'xslt_writer'}){
121 $self->close_xslt_pipe();
122 }
123 else{
124 close($outhandler);
125 }
126
127 $self->{'short_doc_file'} = &util::filename_cat ($doc_dir, "dublin_core.xml");
128 $self->store_output_info_reference($doc_obj);
129}
130
131 sub process_assoc_files {
132 my $self = shift (@_);
133 my ($doc_obj, $doc_dir, $handle) = @_;
134
135 my $outhandler = $self->{'output_handle'};
136
137 my $output_dir = $self->get_output_dir();
138 return if (!defined $output_dir);
139
140 my $working_dir = &util::filename_cat($output_dir, $doc_dir);
141
142 my @assoc_files = ();
143 my $filename;;
144
145 my $source_filename = $doc_obj->get_source_filename();
146
147 my $collect_dir = $ENV{'GSDLCOLLECTDIR'};
148
149 if (defined $collect_dir) {
150 my $dirsep_regexp = &util::get_os_dirsep();
151
152 if ($collect_dir !~ /$dirsep_regexp$/) {
153 $collect_dir .= &util::get_dirsep(); # ensure there is a slash at the end
154 }
155
156 # This test is never going to fail on Windows -- is this a problem?
157 if ($source_filename !~ /^$dirsep_regexp/) {
158 $source_filename = &util::filename_cat($collect_dir, $source_filename);
159 }
160 }
161
162 my ($tail_filename) = ($source_filename =~ m/\/([^\/\\]*)$/);
163
164 print $handle "$tail_filename\n";
165
166 $filename = &util::filename_cat($working_dir, $tail_filename);
167 &util::hard_link ($source_filename, $filename);
168
169 # set the assocfile path (even if we have no assoc files - need this for lucene)
170 $doc_obj->set_utf8_metadata_element ($doc_obj->get_top_section(),
171 "assocfilepath",
172 "$doc_dir");
173 foreach my $assoc_file_rec (@{$doc_obj->get_assoc_files()}) {
174 my ($dir, $afile) = $assoc_file_rec->[1] =~ /^(.*?)([^\/\\]+)$/;
175 $dir = "" unless defined $dir;
176
177
178 my $real_filename = $assoc_file_rec->[0];
179 # for some reasons the image associate file has / before the full path
180 $real_filename =~ s/^\\(.*)/$1/i;
181 if (-e $real_filename) {
182
183 if ($real_filename =~ m/$source_filename$/) {
184 next;
185 }
186 else {
187 my $bundle = "bundle:ORIGINAL";
188
189 if ($afile =~ m/^thumbnail\./) {
190 $bundle = "bundle:THUMBNAIL";
191 }
192
193 # Store the associated file to the "contents" file
194 print $handle "$assoc_file_rec->[1]\t$bundle\n";
195 }
196
197
198 $filename = &util::filename_cat($working_dir, $afile);
199
200
201 &util::hard_link ($real_filename, $filename);
202
203 $doc_obj->add_utf8_metadata ($doc_obj->get_top_section(),
204 "gsdlassocfile",
205 "$afile:$assoc_file_rec->[2]:$dir");
206 } elsif ($self->{'verbosity'} > 2) {
207 print $outhandler "DSpacePlugout::process couldn't copy the associated file " .
208 "$real_filename to $afile\n";
209 }
210 }
211}
212
213
214sub get_new_doc_dir{
215 my $self = shift (@_);
216 my($working_info,$working_dir,$OID) = @_;
217
218 return $OID;
219
220}
Note: See TracBrowser for help on using the repository browser.