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

Last change on this file since 32511 was 32511, checked in by ak19, 6 years ago

Running plugoutinfo.pl with describeall or listall flag would break on FedoraMETSPlugout when either FEDORA_HOME or FEDORA_VERSION aren't set (as is often the case), as there's a die statement in the BEGIN of FedoraMETSPlugout. Needed to run die if either FEDORA env var is not set only if the plugout is NOT in info_only mode in plugout constructor. However, info_only mode was never set in any of the plugouts, so had to add set up the infrastructure for it in plugoutinfo.pl and plugout.pm. Then added the info_only test to all teh plugouts, even though it's redundant in most of them for making sure future changes to any plugout's constructors does not break plugoutinfo.pl.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 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 if ($self->{'info_only'}) {
82 # don't worry about any options etc
83 return bless $self, $class;
84 }
85
86 $self->{'buffered_output'} ="";
87
88 # xslt_file is checked in BasePlugout
89 # check the mapping file here
90 my $full_path_to_mapping_file = &util::locate_config_file($self->{'mapping_file'});
91 if (! defined $full_path_to_mapping_file) {
92 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";
93 die "\n";
94 }
95 $self->{'mapping_file'} = $full_path_to_mapping_file;
96
97 return bless $self, $class;
98}
99
100sub begin {
101
102 my $self= shift (@_);
103 if ($self->{'group'}) {
104 # all output goes into this file
105 my $output_dir = $self->get_output_dir();
106 &FileUtils::makeAllDirectories ($output_dir) unless -e $output_dir;
107
108 $self->{'short_doc_file'} = "marc.xml";
109 }
110}
111# override BasePlugout process
112sub process {
113 my $self = shift (@_);
114 my ($doc_obj) = @_;
115
116 my $output_info = $self->{'output_info'};
117 return if (!defined $output_info);
118
119 $self->process_metafiles_metadata ($doc_obj);
120
121 if ($self->{'group'}){
122 $self->{buffered_output} .= $self->get_top_metadata_list($doc_obj)."\n";
123 }
124 else {
125 # find out which directory to save to
126 my $doc_dir = $self->get_doc_dir($doc_obj);
127 my $output_file = &FileUtils::filenameConcatenate ($self->get_output_dir(), $doc_dir, "marc.xml");
128 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
129
130 my $outhandler = $self->{'xslt_writer'};
131 $self->output_xml_header($outhandler, "MARCXML", 1);
132 print $outhandler $self->get_top_metadata_list($doc_obj);
133 $self->output_xml_footer($outhandler,"MARCXML");
134 $self->close_xslt_pipe();
135 $self->{'short_doc_file'} = &FileUtils::filenameConcatenate ($doc_dir, "marc.xml");
136 }
137
138
139 # write out data to archiveinf-doc.db
140 if ($self->{'generate_databases'}) {
141 $self->store_output_info_reference($doc_obj);
142 $self->archiveinf_db($doc_obj);
143 }
144 if ($self->{'group'}){
145 $self->{'gs_count'}++;
146 $self->{'group_position'}++;
147 }
148}
149
150
151# returns a xml element of the form <MetadataList><Metadata name="metadata-name">metadata_value</Metadata>...</MetadataList>
152
153sub get_top_metadata_list {
154
155 my $self = shift (@_);
156 my ($doc_obj) = @_;
157
158 my @topmetadata =$doc_obj->get_all_metadata($doc_obj->get_top_section());
159 my $metadatalist ='<MetadataList>';
160
161 foreach my $i (@topmetadata){
162 foreach my $j (@$i){
163 my %metaMap = @$j;
164 foreach my $key (keys %metaMap){
165 $metadatalist .='<Metadata name='."\"$key\"".'>'.&docprint::escape_text($metaMap{$key}).'</Metadata>'."\n";
166 }
167 }
168 }
169
170 $metadatalist .='</MetadataList>';
171 return $metadatalist;
172}
173
174
175sub close_group_output{
176 my $self = shift (@_);
177
178 return unless $self->{'group'} and $self->{buffered_output};
179
180 my $output_file = &FileUtils::filenameConcatenate($self->get_output_dir(), $self->{'short_doc_file'});
181
182 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
183
184 my $outhandler = $self->{'xslt_writer'};
185
186 $self->output_xml_header($outhandler, "MARCXML", 1);
187 print $outhandler $self->{buffered_output};
188 $self->output_xml_footer($outhandler,"MARCXML");
189 $self->close_xslt_pipe();
190}
191
192
193sub is_group{
194 my $self = shift (@_);
195 return $self->{'group'};
196}
197
198
1991;
Note: See TracBrowser for help on using the repository browser.