[12330] | 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 |
|
---|
| 26 | package MARCXMLPlugout;
|
---|
| 27 |
|
---|
| 28 | use strict;
|
---|
| 29 | no strict 'refs';
|
---|
| 30 |
|
---|
| 31 | eval {require bytes};
|
---|
| 32 | use util;
|
---|
| 33 | use BasPlugout;
|
---|
[13172] | 34 | use docprint; # for escape_text
|
---|
[12330] | 35 |
|
---|
[13172] | 36 |
|
---|
[12330] | 37 | sub BEGIN {
|
---|
| 38 | @MARCXMLPlugout::ISA = ('BasPlugout');
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | my $arguments = [
|
---|
| 42 | { 'name' => "group",
|
---|
| 43 | 'desc' => "{MARCXMLPlugout.group}",
|
---|
| 44 | 'type' => "flag",
|
---|
| 45 | 'deft' => "0",
|
---|
| 46 | 'reqd' => "no",
|
---|
[12605] | 47 | 'hiddengli' => "no"},
|
---|
| 48 | { 'name' => "mapping_file",
|
---|
| 49 | 'desc' => "{MARCXMLPlugout.mapping_file}",
|
---|
| 50 | 'type' => "string",
|
---|
| 51 | 'deft' => "$ENV{'GSDLHOME'}/etc/dc2marc-mapping.xml",
|
---|
| 52 | 'reqd' => "yes",
|
---|
[12330] | 53 | 'hiddengli' => "no"}
|
---|
| 54 | ];
|
---|
| 55 |
|
---|
| 56 | my $options = { 'name' => "MARCXMLPlugout",
|
---|
| 57 | 'desc' => "{MARCXMLPlugout.desc}",
|
---|
| 58 | 'abstract' => "no",
|
---|
| 59 | 'inherits' => "yes",
|
---|
| 60 | 'args' => $arguments
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | sub new {
|
---|
| 64 | my ($class) = shift (@_);
|
---|
| 65 | my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
|
---|
| 66 | push(@$plugoutlist, $class);
|
---|
| 67 |
|
---|
| 68 | if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
|
---|
| 69 | if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
|
---|
| 70 |
|
---|
| 71 | my $self = (defined $hashArgOptLists)? new BasPlugout($plugoutlist,$inputargs,$hashArgOptLists): new BasPlugout($plugoutlist,$inputargs);
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | $self->{'buffered_output'} ="";
|
---|
| 75 |
|
---|
[12605] | 76 | if (!defined $self->{'mapping_file'} || (defined $self->{'mapping_file'} && $self->{'mapping_file'} eq "")){
|
---|
| 77 | $self->{'mapping_file'} = "$ENV{'GSDLHOME'}/etc/dc2marc-mapping.xml";
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | if (!defined $self->{'xslt_file'} || (defined $self->{'xslt_file'} && $self->{'xslt_file'} eq "")){
|
---|
| 81 | $self->{'xslt_file'} = "$ENV{'GSDLHOME'}/etc/dc2marc.xsl";
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | if(defined $self->{'mapping_file'} && $self->{'mapping_file'} ne "")
|
---|
| 85 | {
|
---|
| 86 | 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'});
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | if(defined $self->{'xslt_file'} && $self->{'xslt_file'} ne "")
|
---|
| 90 | {
|
---|
| 91 | 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'});
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[12330] | 94 | return bless $self, $class;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | sub saveas {
|
---|
| 98 | my $self = shift (@_);
|
---|
| 99 | my ($doc_obj,$doc_dir) = @_;
|
---|
[12605] | 100 |
|
---|
| 101 |
|
---|
[12330] | 102 | if ($self->{'group'}){
|
---|
[13469] | 103 | $self->{buffered_output} .= $self->get_top_metadata_list($doc_obj)."\n";
|
---|
[12330] | 104 | return;
|
---|
| 105 | }
|
---|
[12605] | 106 |
|
---|
[12330] | 107 |
|
---|
| 108 | my $output_dir = $self->get_output_dir();
|
---|
| 109 | &util::mk_all_dir ($output_dir) unless -e $output_dir;
|
---|
| 110 |
|
---|
| 111 | my $working_dir = &util::filename_cat ($output_dir, $doc_dir);
|
---|
| 112 | &util::mk_all_dir ($working_dir) unless -e $working_dir;
|
---|
| 113 |
|
---|
| 114 | my $output_file = util::filename_cat ($working_dir, "marc.xml");
|
---|
| 115 |
|
---|
| 116 | $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
|
---|
| 117 |
|
---|
| 118 | my $outhandler = $self->{'xslt_writer'};
|
---|
| 119 |
|
---|
| 120 | $self->output_xml_header($outhandler,"MARCXML");
|
---|
[13172] | 121 | print $outhandler $self->get_top_metadata_list($doc_obj);
|
---|
[12330] | 122 | $self->output_xml_footer($outhandler,"MARCXML");
|
---|
| 123 | $self->close_xslt_pipe();
|
---|
| 124 |
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[13172] | 127 | # returns a xml element of the form <MetadataList><Metadata name="metadata-name">metadata_value</Metadata>...</MetadataList>
|
---|
[12330] | 128 |
|
---|
[13172] | 129 | sub get_top_metadata_list {
|
---|
[12330] | 130 |
|
---|
[13172] | 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 |
|
---|
[12330] | 151 | sub 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 | &util::mk_all_dir ($output_dir) unless -e $output_dir;
|
---|
| 158 |
|
---|
| 159 | my $output_file = util::filename_cat($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");
|
---|
| 166 | print $outhandler $self->{buffered_output};
|
---|
| 167 | $self->output_xml_footer($outhandler,"MARCXML");
|
---|
| 168 | $self->close_xslt_pipe();
|
---|
| 169 | }
|
---|
| 170 |
|
---|
[14971] | 171 |
|
---|
[12330] | 172 | sub is_group{
|
---|
| 173 | my $self = shift (@_);
|
---|
| 174 | return $self->{'group'};
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | 1;
|
---|