[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';
|
---|
[28706] | 30 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
[12330] | 31 |
|
---|
| 32 | eval {require bytes};
|
---|
| 33 | use util;
|
---|
[28562] | 34 | use FileUtils;
|
---|
[17203] | 35 | use BasePlugout;
|
---|
[13172] | 36 | use docprint; # for escape_text
|
---|
[12330] | 37 |
|
---|
[13172] | 38 |
|
---|
[12330] | 39 | sub BEGIN {
|
---|
[17203] | 40 | @MARCXMLPlugout::ISA = ('BasePlugout');
|
---|
[12330] | 41 | }
|
---|
| 42 |
|
---|
| 43 | my $arguments = [
|
---|
| 44 | { 'name' => "group",
|
---|
| 45 | 'desc' => "{MARCXMLPlugout.group}",
|
---|
| 46 | 'type' => "flag",
|
---|
| 47 | 'reqd' => "no",
|
---|
[12605] | 48 | 'hiddengli' => "no"},
|
---|
| 49 | { 'name' => "mapping_file",
|
---|
| 50 | 'desc' => "{MARCXMLPlugout.mapping_file}",
|
---|
| 51 | 'type' => "string",
|
---|
[20321] | 52 | 'deft' => "dc2marc-mapping.xml",
|
---|
[28706] | 53 | 'reqd' => "no",
|
---|
[20321] | 54 | 'hiddengli' => "no"},
|
---|
| 55 | { 'name' => "xslt_file",
|
---|
| 56 | 'desc' => "{BasPlugout.xslt_file}",
|
---|
| 57 | 'type' => "string",
|
---|
| 58 | 'reqd' => "no",
|
---|
| 59 | 'deft' => "dc2marc.xsl",
|
---|
[12330] | 60 | 'hiddengli' => "no"}
|
---|
[20321] | 61 |
|
---|
[12330] | 62 | ];
|
---|
| 63 |
|
---|
| 64 | my $options = { 'name' => "MARCXMLPlugout",
|
---|
| 65 | 'desc' => "{MARCXMLPlugout.desc}",
|
---|
| 66 | 'abstract' => "no",
|
---|
| 67 | 'inherits' => "yes",
|
---|
| 68 | 'args' => $arguments
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | sub new {
|
---|
| 72 | my ($class) = shift (@_);
|
---|
| 73 | my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
|
---|
| 74 | push(@$plugoutlist, $class);
|
---|
| 75 |
|
---|
[17203] | 76 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 77 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[12330] | 78 |
|
---|
[17203] | 79 | my $self = new BasePlugout($plugoutlist,$inputargs,$hashArgOptLists);
|
---|
[32511] | 80 |
|
---|
| 81 | if ($self->{'info_only'}) {
|
---|
| 82 | # don't worry about any options etc
|
---|
| 83 | return bless $self, $class;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[17203] | 86 | $self->{'buffered_output'} ="";
|
---|
[20321] | 87 |
|
---|
[28706] | 88 | # xslt_file is checked in BasePlugout
|
---|
| 89 | # check the mapping file here
|
---|
[20321] | 90 | my $full_path_to_mapping_file = &util::locate_config_file($self->{'mapping_file'});
|
---|
| 91 | if (! defined $full_path_to_mapping_file) {
|
---|
[28706] | 92 | print STDERR "Can not find mapping file $self->{'mapping_file'}, please make sure you have supplied the correct file path or put the file into the collection's etc or greenstone's etc folder\n";
|
---|
[20321] | 93 | die "\n";
|
---|
[12605] | 94 | }
|
---|
[20321] | 95 | $self->{'mapping_file'} = $full_path_to_mapping_file;
|
---|
[12605] | 96 |
|
---|
[28706] | 97 | return bless $self, $class;
|
---|
[12330] | 98 | }
|
---|
| 99 |
|
---|
[28706] | 100 | sub begin {
|
---|
| 101 |
|
---|
| 102 | my $self= shift (@_);
|
---|
| 103 | if ($self->{'group'}) {
|
---|
| 104 | # all output goes into this file
|
---|
| 105 | my $output_dir = $self->get_output_dir();
|
---|
| 106 | &FileUtils::makeAllDirectories ($output_dir) unless -e $output_dir;
|
---|
| 107 |
|
---|
| 108 | $self->{'short_doc_file'} = "marc.xml";
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | # override BasePlugout process
|
---|
| 112 | sub process {
|
---|
[12330] | 113 | my $self = shift (@_);
|
---|
[28706] | 114 | my ($doc_obj) = @_;
|
---|
[12605] | 115 |
|
---|
[28706] | 116 | my $output_info = $self->{'output_info'};
|
---|
| 117 | return if (!defined $output_info);
|
---|
| 118 |
|
---|
| 119 | $self->process_metafiles_metadata ($doc_obj);
|
---|
| 120 |
|
---|
[12330] | 121 | if ($self->{'group'}){
|
---|
[13469] | 122 | $self->{buffered_output} .= $self->get_top_metadata_list($doc_obj)."\n";
|
---|
[12330] | 123 | }
|
---|
[28706] | 124 | else {
|
---|
| 125 | # find out which directory to save to
|
---|
| 126 | my $doc_dir = $self->get_doc_dir($doc_obj);
|
---|
| 127 | my $output_file = &FileUtils::filenameConcatenate ($self->get_output_dir(), $doc_dir, "marc.xml");
|
---|
| 128 | $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
|
---|
| 129 |
|
---|
| 130 | my $outhandler = $self->{'xslt_writer'};
|
---|
| 131 | $self->output_xml_header($outhandler, "MARCXML", 1);
|
---|
| 132 | print $outhandler $self->get_top_metadata_list($doc_obj);
|
---|
| 133 | $self->output_xml_footer($outhandler,"MARCXML");
|
---|
| 134 | $self->close_xslt_pipe();
|
---|
| 135 | $self->{'short_doc_file'} = &FileUtils::filenameConcatenate ($doc_dir, "marc.xml");
|
---|
| 136 | }
|
---|
[20651] | 137 |
|
---|
[12330] | 138 |
|
---|
[28706] | 139 | # write out data to archiveinf-doc.db
|
---|
| 140 | if ($self->{'generate_databases'}) {
|
---|
| 141 | $self->store_output_info_reference($doc_obj);
|
---|
| 142 | $self->archiveinf_db($doc_obj);
|
---|
| 143 | }
|
---|
| 144 | if ($self->{'group'}){
|
---|
| 145 | $self->{'gs_count'}++;
|
---|
| 146 | $self->{'group_position'}++;
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
[12330] | 149 |
|
---|
| 150 |
|
---|
[13172] | 151 | # returns a xml element of the form <MetadataList><Metadata name="metadata-name">metadata_value</Metadata>...</MetadataList>
|
---|
[12330] | 152 |
|
---|
[13172] | 153 | sub get_top_metadata_list {
|
---|
[12330] | 154 |
|
---|
[13172] | 155 | my $self = shift (@_);
|
---|
| 156 | my ($doc_obj) = @_;
|
---|
| 157 |
|
---|
| 158 | my @topmetadata =$doc_obj->get_all_metadata($doc_obj->get_top_section());
|
---|
| 159 | my $metadatalist ='<MetadataList>';
|
---|
| 160 |
|
---|
| 161 | foreach my $i (@topmetadata){
|
---|
| 162 | foreach my $j (@$i){
|
---|
| 163 | my %metaMap = @$j;
|
---|
| 164 | foreach my $key (keys %metaMap){
|
---|
| 165 | $metadatalist .='<Metadata name='."\"$key\"".'>'.&docprint::escape_text($metaMap{$key}).'</Metadata>'."\n";
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | $metadatalist .='</MetadataList>';
|
---|
| 171 | return $metadatalist;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
[12330] | 175 | sub close_group_output{
|
---|
| 176 | my $self = shift (@_);
|
---|
| 177 |
|
---|
| 178 | return unless $self->{'group'} and $self->{buffered_output};
|
---|
| 179 |
|
---|
[28706] | 180 | my $output_file = &FileUtils::filenameConcatenate($self->get_output_dir(), $self->{'short_doc_file'});
|
---|
[12330] | 181 |
|
---|
| 182 | $self->open_xslt_pipe($output_file,$self->{'xslt_file'});
|
---|
| 183 |
|
---|
| 184 | my $outhandler = $self->{'xslt_writer'};
|
---|
| 185 |
|
---|
[20962] | 186 | $self->output_xml_header($outhandler, "MARCXML", 1);
|
---|
[12330] | 187 | print $outhandler $self->{buffered_output};
|
---|
| 188 | $self->output_xml_footer($outhandler,"MARCXML");
|
---|
| 189 | $self->close_xslt_pipe();
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[14971] | 192 |
|
---|
[12330] | 193 | sub is_group{
|
---|
| 194 | my $self = shift (@_);
|
---|
| 195 | return $self->{'group'};
|
---|
| 196 | }
|
---|
| 197 |
|
---|
[28706] | 198 |
|
---|
[12330] | 199 | 1;
|
---|