source: main/tags/2.71/gsdl/perllib/plugouts/MARCXMLPlugout.pm@ 25382

Last change on this file since 25382 was 12605, checked in by shaoqun, 18 years ago

added code that supports the mapping_file option

  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 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 BasPlugout;
34
35sub BEGIN {
36 @MARCXMLPlugout::ISA = ('BasPlugout');
37}
38
39my $arguments = [
40 { 'name' => "group",
41 'desc' => "{MARCXMLPlugout.group}",
42 'type' => "flag",
43 'deft' => "0",
44 'reqd' => "no",
45 'hiddengli' => "no"},
46 { 'name' => "mapping_file",
47 'desc' => "{MARCXMLPlugout.mapping_file}",
48 'type' => "string",
49 'deft' => "$ENV{'GSDLHOME'}/etc/dc2marc-mapping.xml",
50 'reqd' => "yes",
51 'hiddengli' => "no"}
52 ];
53
54my $options = { 'name' => "MARCXMLPlugout",
55 'desc' => "{MARCXMLPlugout.desc}",
56 'abstract' => "no",
57 'inherits' => "yes",
58 'args' => $arguments
59 };
60
61sub new {
62 my ($class) = shift (@_);
63 my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
64 push(@$plugoutlist, $class);
65
66 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
67 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
68
69 my $self = (defined $hashArgOptLists)? new BasPlugout($plugoutlist,$inputargs,$hashArgOptLists): new BasPlugout($plugoutlist,$inputargs);
70
71
72 $self->{'buffered_output'} ="";
73
74 if (!defined $self->{'mapping_file'} || (defined $self->{'mapping_file'} && $self->{'mapping_file'} eq "")){
75 $self->{'mapping_file'} = "$ENV{'GSDLHOME'}/etc/dc2marc-mapping.xml";
76 }
77
78 if (!defined $self->{'xslt_file'} || (defined $self->{'xslt_file'} && $self->{'xslt_file'} eq "")){
79 $self->{'xslt_file'} = "$ENV{'GSDLHOME'}/etc/dc2marc.xsl";
80 }
81
82 if(defined $self->{'mapping_file'} && $self->{'mapping_file'} ne "")
83 {
84 print STDERR "Can not find $self->{'mapping_file'}, please make sure you have supplied the correct file path\n" and die "\n" unless (-e $self->{'mapping_file'});
85 }
86
87 if(defined $self->{'xslt_file'} && $self->{'xslt_file'} ne "")
88 {
89 print STDERR "Can not find $self->{'xslt_file'}, please make sure you have supplied the correct file path\n" and die "\n" unless (-e $self->{'xslt_file'});
90 }
91
92 return bless $self, $class;
93}
94
95sub saveas {
96 my $self = shift (@_);
97 my ($doc_obj,$doc_dir) = @_;
98
99
100 if ($self->{'group'}){
101 $self->{buffered_output} .= $doc_obj->get_top_metadata_list()."\n";
102 return;
103 }
104
105
106 my $output_dir = $self->get_output_dir();
107 &util::mk_all_dir ($output_dir) unless -e $output_dir;
108
109 my $working_dir = &util::filename_cat ($output_dir, $doc_dir);
110 &util::mk_all_dir ($working_dir) unless -e $working_dir;
111
112 my $output_file = util::filename_cat ($working_dir, "marc.xml");
113
114 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
115
116 my $outhandler = $self->{'xslt_writer'};
117
118 $self->output_xml_header($outhandler,"MARCXML");
119 print $outhandler $doc_obj->get_top_metadata_list();
120 $self->output_xml_footer($outhandler,"MARCXML");
121 $self->close_xslt_pipe();
122
123}
124
125
126
127sub close_group_output{
128 my $self = shift (@_);
129
130 return unless $self->{'group'} and $self->{buffered_output};
131
132 my $output_dir = $self->get_output_dir();
133 &util::mk_all_dir ($output_dir) unless -e $output_dir;
134
135 my $output_file = util::filename_cat($output_dir, "marc.xml");
136
137 $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
138
139 my $outhandler = $self->{'xslt_writer'};
140
141 $self->output_xml_header($outhandler,"MARCXML");
142 print $outhandler $self->{buffered_output};
143 $self->output_xml_footer($outhandler,"MARCXML");
144 $self->close_xslt_pipe();
145}
146
147sub is_group{
148 my $self = shift (@_);
149 return $self->{'group'};
150}
151
1521;
Note: See TracBrowser for help on using the repository browser.