source: gsdl/trunk/perllib/plugouts/MARCXMLPlugout.pm@ 20321

Last change on this file since 20321 was 20321, checked in by kjdon, 15 years ago

use util::locate_config_file instead of hard coding linux paths, for mapping_file and xslt_file. made it work on windows

  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 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
103 my $output_dir = $self->get_output_dir();
104 &util::mk_all_dir ($output_dir) unless -e $output_dir;
105
106 my $working_dir = &util::filename_cat ($output_dir, $doc_dir);
107 &util::mk_all_dir ($working_dir) unless -e $working_dir;
108
109 my $output_file = util::filename_cat ($working_dir, "marc.xml");
110
111 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
112
113 my $outhandler = $self->{'xslt_writer'};
114
115 $self->output_xml_header($outhandler,"MARCXML");
116 print $outhandler $self->get_top_metadata_list($doc_obj);
117 $self->output_xml_footer($outhandler,"MARCXML");
118 $self->close_xslt_pipe();
119
120}
121
122# returns a xml element of the form <MetadataList><Metadata name="metadata-name">metadata_value</Metadata>...</MetadataList>
123
124sub get_top_metadata_list {
125
126 my $self = shift (@_);
127 my ($doc_obj) = @_;
128
129 my @topmetadata =$doc_obj->get_all_metadata($doc_obj->get_top_section());
130 my $metadatalist ='<MetadataList>';
131
132 foreach my $i (@topmetadata){
133 foreach my $j (@$i){
134 my %metaMap = @$j;
135 foreach my $key (keys %metaMap){
136 $metadatalist .='<Metadata name='."\"$key\"".'>'.&docprint::escape_text($metaMap{$key}).'</Metadata>'."\n";
137 }
138 }
139 }
140
141 $metadatalist .='</MetadataList>';
142 return $metadatalist;
143}
144
145
146sub close_group_output{
147 my $self = shift (@_);
148
149 return unless $self->{'group'} and $self->{buffered_output};
150
151 my $output_dir = $self->get_output_dir();
152 &util::mk_all_dir ($output_dir) unless -e $output_dir;
153
154 my $output_file = util::filename_cat($output_dir, "marc.xml");
155
156 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
157
158 my $outhandler = $self->{'xslt_writer'};
159
160 $self->output_xml_header($outhandler,"MARCXML");
161 print $outhandler $self->{buffered_output};
162 $self->output_xml_footer($outhandler,"MARCXML");
163 $self->close_xslt_pipe();
164}
165
166
167sub is_group{
168 my $self = shift (@_);
169 return $self->{'group'};
170}
171
1721;
Note: See TracBrowser for help on using the repository browser.