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

Last change on this file since 13172 was 13172, checked in by kjdon, 18 years ago

Moved all printing stuff out of doc.pm.
docprint now prints a GA representation of a doc obj - use &docprint::get_section_xml instead of $doc_obj->buffer_section_xml or $doc_obj->output_section.
Most of the code has been moved into plugouts, except for the bit thats gone to docprint.pm.

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