source: main/trunk/greenstone2/perllib/plugouts/MARCXMLPlugout.pm@ 28706

Last change on this file since 28706 was 28706, checked in by kjdon, 10 years ago

tidied this up a bit, can't really remember exactly what I have done and I am in a hurry

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1###########################################################################
2#
3# MARCXMLPlugout.pm -- the plugout module for MARC xml recored
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 MARCXMLPlugout;
27
28use strict;
29no strict 'refs';
30no strict 'subs'; # allow barewords (eg STDERR) as function arguments
31
32eval {require bytes};
33use util;
34use FileUtils;
35use BasePlugout;
36use docprint; # for escape_text
37
38
39sub BEGIN {
40 @MARCXMLPlugout::ISA = ('BasePlugout');
41}
42
43my $arguments = [
44 { 'name' => "group",
45 'desc' => "{MARCXMLPlugout.group}",
46 'type' => "flag",
47 'reqd' => "no",
48 'hiddengli' => "no"},
49 { 'name' => "mapping_file",
50 'desc' => "{MARCXMLPlugout.mapping_file}",
51 'type' => "string",
52 'deft' => "dc2marc-mapping.xml",
53 'reqd' => "no",
54 'hiddengli' => "no"},
55 { 'name' => "xslt_file",
56 'desc' => "{BasPlugout.xslt_file}",
57 'type' => "string",
58 'reqd' => "no",
59 'deft' => "dc2marc.xsl",
60 'hiddengli' => "no"}
61
62 ];
63
64my $options = { 'name' => "MARCXMLPlugout",
65 'desc' => "{MARCXMLPlugout.desc}",
66 'abstract' => "no",
67 'inherits' => "yes",
68 'args' => $arguments
69 };
70
71sub new {
72 my ($class) = shift (@_);
73 my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
74 push(@$plugoutlist, $class);
75
76 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
77 push(@{$hashArgOptLists->{"OptList"}},$options);
78
79 my $self = new BasePlugout($plugoutlist,$inputargs,$hashArgOptLists);
80
81 $self->{'buffered_output'} ="";
82
83 # xslt_file is checked in BasePlugout
84 # check the mapping file here
85 my $full_path_to_mapping_file = &util::locate_config_file($self->{'mapping_file'});
86 if (! defined $full_path_to_mapping_file) {
87 print STDERR "Can not find mapping file $self->{'mapping_file'}, please make sure you have supplied the correct file path or put the file into the collection's etc or greenstone's etc folder\n";
88 die "\n";
89 }
90 $self->{'mapping_file'} = $full_path_to_mapping_file;
91
92 return bless $self, $class;
93}
94
95sub begin {
96
97 my $self= shift (@_);
98 if ($self->{'group'}) {
99 # all output goes into this file
100 my $output_dir = $self->get_output_dir();
101 &FileUtils::makeAllDirectories ($output_dir) unless -e $output_dir;
102
103 $self->{'short_doc_file'} = "marc.xml";
104 }
105}
106# override BasePlugout process
107sub process {
108 my $self = shift (@_);
109 my ($doc_obj) = @_;
110
111 my $output_info = $self->{'output_info'};
112 return if (!defined $output_info);
113
114 $self->process_metafiles_metadata ($doc_obj);
115
116 if ($self->{'group'}){
117 $self->{buffered_output} .= $self->get_top_metadata_list($doc_obj)."\n";
118 }
119 else {
120 # find out which directory to save to
121 my $doc_dir = $self->get_doc_dir($doc_obj);
122 my $output_file = &FileUtils::filenameConcatenate ($self->get_output_dir(), $doc_dir, "marc.xml");
123 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
124
125 my $outhandler = $self->{'xslt_writer'};
126 $self->output_xml_header($outhandler, "MARCXML", 1);
127 print $outhandler $self->get_top_metadata_list($doc_obj);
128 $self->output_xml_footer($outhandler,"MARCXML");
129 $self->close_xslt_pipe();
130 $self->{'short_doc_file'} = &FileUtils::filenameConcatenate ($doc_dir, "marc.xml");
131 }
132
133
134 # write out data to archiveinf-doc.db
135 if ($self->{'generate_databases'}) {
136 $self->store_output_info_reference($doc_obj);
137 $self->archiveinf_db($doc_obj);
138 }
139 if ($self->{'group'}){
140 $self->{'gs_count'}++;
141 $self->{'group_position'}++;
142 }
143}
144
145
146# returns a xml element of the form <MetadataList><Metadata name="metadata-name">metadata_value</Metadata>...</MetadataList>
147
148sub get_top_metadata_list {
149
150 my $self = shift (@_);
151 my ($doc_obj) = @_;
152
153 my @topmetadata =$doc_obj->get_all_metadata($doc_obj->get_top_section());
154 my $metadatalist ='<MetadataList>';
155
156 foreach my $i (@topmetadata){
157 foreach my $j (@$i){
158 my %metaMap = @$j;
159 foreach my $key (keys %metaMap){
160 $metadatalist .='<Metadata name='."\"$key\"".'>'.&docprint::escape_text($metaMap{$key}).'</Metadata>'."\n";
161 }
162 }
163 }
164
165 $metadatalist .='</MetadataList>';
166 return $metadatalist;
167}
168
169
170sub close_group_output{
171 my $self = shift (@_);
172
173 return unless $self->{'group'} and $self->{buffered_output};
174
175 my $output_file = &FileUtils::filenameConcatenate($self->get_output_dir(), $self->{'short_doc_file'});
176
177 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
178
179 my $outhandler = $self->{'xslt_writer'};
180
181 $self->output_xml_header($outhandler, "MARCXML", 1);
182 print $outhandler $self->{buffered_output};
183 $self->output_xml_footer($outhandler,"MARCXML");
184 $self->close_xslt_pipe();
185}
186
187
188sub is_group{
189 my $self = shift (@_);
190 return $self->{'group'};
191}
192
193
1941;
Note: See TracBrowser for help on using the repository browser.