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

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

changing some util:: methods to FileUtils:: methods

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 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 FileUtils;
34use BasePlugout;
35use docprint; # for escape_text
36
37
38sub BEGIN {
39 @MARCXMLPlugout::ISA = ('BasePlugout');
40}
41
42my $arguments = [
43 { 'name' => "group",
44 'desc' => "{MARCXMLPlugout.group}",
45 'type' => "flag",
46 'deft' => "0",
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' => "yes",
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 my $full_path_to_mapping_file = &util::locate_config_file($self->{'mapping_file'});
84 if (! defined $full_path_to_mapping_file) {
85 print STDERR "Can not find $self->{'mapping_file'}, please make sure you have supplied the correct file path\n";
86 die "\n";
87 }
88 $self->{'mapping_file'} = $full_path_to_mapping_file;
89
90 return bless $self, $class;
91}
92
93sub saveas {
94 my $self = shift (@_);
95 my ($doc_obj,$doc_dir) = @_;
96
97
98 if ($self->{'group'}){
99 $self->{buffered_output} .= $self->get_top_metadata_list($doc_obj)."\n";
100 return;
101 }
102
103 $self->process_metafiles_metadata ($doc_obj);
104
105 my $output_dir = $self->get_output_dir();
106 &FileUtils::makeAllDirectories ($output_dir) unless -e $output_dir;
107
108 my $working_dir = &FileUtils::filenameConcatenate ($output_dir, $doc_dir);
109 &FileUtils::makeAllDirectories ($working_dir) unless -e $working_dir;
110
111 my $output_file = &FileUtils::filenameConcatenate ($working_dir, "marc.xml");
112
113 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
114
115 my $outhandler = $self->{'xslt_writer'};
116
117 $self->output_xml_header($outhandler, "MARCXML", 1);
118 print $outhandler $self->get_top_metadata_list($doc_obj);
119 $self->output_xml_footer($outhandler,"MARCXML");
120 $self->close_xslt_pipe();
121
122 $self->{'short_doc_file'} = &FileUtils::filenameConcatenate ($doc_dir, "marc.xml");
123
124 $self->store_output_info_reference($doc_obj);
125}
126
127# returns a xml element of the form <MetadataList><Metadata name="metadata-name">metadata_value</Metadata>...</MetadataList>
128
129sub get_top_metadata_list {
130
131 my $self = shift (@_);
132 my ($doc_obj) = @_;
133
134 my @topmetadata =$doc_obj->get_all_metadata($doc_obj->get_top_section());
135 my $metadatalist ='<MetadataList>';
136
137 foreach my $i (@topmetadata){
138 foreach my $j (@$i){
139 my %metaMap = @$j;
140 foreach my $key (keys %metaMap){
141 $metadatalist .='<Metadata name='."\"$key\"".'>'.&docprint::escape_text($metaMap{$key}).'</Metadata>'."\n";
142 }
143 }
144 }
145
146 $metadatalist .='</MetadataList>';
147 return $metadatalist;
148}
149
150
151sub close_group_output{
152 my $self = shift (@_);
153
154 return unless $self->{'group'} and $self->{buffered_output};
155
156 my $output_dir = $self->get_output_dir();
157 &FileUtils::makeAllDirectories ($output_dir) unless -e $output_dir;
158
159 my $output_file = &FileUtils::filenameConcatenate($output_dir, "marc.xml");
160
161 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
162
163 my $outhandler = $self->{'xslt_writer'};
164
165 $self->output_xml_header($outhandler, "MARCXML", 1);
166 print $outhandler $self->{buffered_output};
167 $self->output_xml_footer($outhandler,"MARCXML");
168 $self->close_xslt_pipe();
169}
170
171
172sub is_group{
173 my $self = shift (@_);
174 return $self->{'group'};
175}
176
1771;
Note: See TracBrowser for help on using the repository browser.