source: gs2-extensions/parallel-building/trunk/src/perllib/plugouts/MARCXMLPlugout.pm@ 24626

Last change on this file since 24626 was 24626, checked in by jmt12, 13 years ago

An (almost) complete copy of the perllib directory from a (circa SEP2011) head checkout from Greenstone 2 trunk - in order to try and make merging in this extension a little easier later on (as there have been some major changes to buildcol.pl commited in the main trunk but not in the x64 branch)

File size: 5.1 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';
30
31eval {require bytes};
32use util;
33use BasePlugout;
34use docprint; # for escape_text
35
36
37sub BEGIN {
38 @MARCXMLPlugout::ISA = ('BasePlugout');
39}
40
41my $arguments = [
42 { 'name' => "group",
43 'desc' => "{MARCXMLPlugout.group}",
44 'type' => "flag",
45 'deft' => "0",
46 'reqd' => "no",
47 'hiddengli' => "no"},
48 { 'name' => "mapping_file",
49 'desc' => "{MARCXMLPlugout.mapping_file}",
50 'type' => "string",
51 'deft' => "dc2marc-mapping.xml",
52 'reqd' => "yes",
53 'hiddengli' => "no"},
54 { 'name' => "xslt_file",
55 'desc' => "{BasPlugout.xslt_file}",
56 'type' => "string",
57 'reqd' => "no",
58 'deft' => "dc2marc.xsl",
59 'hiddengli' => "no"}
60
61 ];
62
63my $options = { 'name' => "MARCXMLPlugout",
64 'desc' => "{MARCXMLPlugout.desc}",
65 'abstract' => "no",
66 'inherits' => "yes",
67 'args' => $arguments
68 };
69
70sub new {
71 my ($class) = shift (@_);
72 my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
73 push(@$plugoutlist, $class);
74
75 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
76 push(@{$hashArgOptLists->{"OptList"}},$options);
77
78 my $self = new BasePlugout($plugoutlist,$inputargs,$hashArgOptLists);
79
80 $self->{'buffered_output'} ="";
81
82 my $full_path_to_mapping_file = &util::locate_config_file($self->{'mapping_file'});
83 if (! defined $full_path_to_mapping_file) {
84 print STDERR "Can not find $self->{'mapping_file'}, please make sure you have supplied the correct file path\n";
85 die "\n";
86 }
87 $self->{'mapping_file'} = $full_path_to_mapping_file;
88
89 return bless $self, $class;
90}
91
92sub saveas {
93 my $self = shift (@_);
94 my ($doc_obj,$doc_dir) = @_;
95
96
97 if ($self->{'group'}){
98 $self->{buffered_output} .= $self->get_top_metadata_list($doc_obj)."\n";
99 return;
100 }
101
102 $self->process_metafiles_metadata ($doc_obj);
103
104 my $output_dir = $self->get_output_dir();
105 &util::mk_all_dir ($output_dir) unless -e $output_dir;
106
107 my $working_dir = &util::filename_cat ($output_dir, $doc_dir);
108 &util::mk_all_dir ($working_dir) unless -e $working_dir;
109
110 my $output_file = util::filename_cat ($working_dir, "marc.xml");
111
112 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
113
114 my $outhandler = $self->{'xslt_writer'};
115
116 $self->output_xml_header($outhandler, "MARCXML", 1);
117 print $outhandler $self->get_top_metadata_list($doc_obj);
118 $self->output_xml_footer($outhandler,"MARCXML");
119 $self->close_xslt_pipe();
120
121 $self->{'short_doc_file'} = util::filename_cat ($doc_dir, "marc.xml");
122
123 $self->store_output_info_reference($doc_obj);
124}
125
126# returns a xml element of the form <MetadataList><Metadata name="metadata-name">metadata_value</Metadata>...</MetadataList>
127
128sub get_top_metadata_list {
129
130 my $self = shift (@_);
131 my ($doc_obj) = @_;
132
133 my @topmetadata =$doc_obj->get_all_metadata($doc_obj->get_top_section());
134 my $metadatalist ='<MetadataList>';
135
136 foreach my $i (@topmetadata){
137 foreach my $j (@$i){
138 my %metaMap = @$j;
139 foreach my $key (keys %metaMap){
140 $metadatalist .='<Metadata name='."\"$key\"".'>'.&docprint::escape_text($metaMap{$key}).'</Metadata>'."\n";
141 }
142 }
143 }
144
145 $metadatalist .='</MetadataList>';
146 return $metadatalist;
147}
148
149
150sub close_group_output{
151 my $self = shift (@_);
152
153 return unless $self->{'group'} and $self->{buffered_output};
154
155 my $output_dir = $self->get_output_dir();
156 &util::mk_all_dir ($output_dir) unless -e $output_dir;
157
158 my $output_file = util::filename_cat($output_dir, "marc.xml");
159
160 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
161
162 my $outhandler = $self->{'xslt_writer'};
163
164 $self->output_xml_header($outhandler, "MARCXML", 1);
165 print $outhandler $self->{buffered_output};
166 $self->output_xml_footer($outhandler,"MARCXML");
167 $self->close_xslt_pipe();
168}
169
170
171sub is_group{
172 my $self = shift (@_);
173 return $self->{'group'};
174}
175
1761;
Note: See TracBrowser for help on using the repository browser.