[12330] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[17743] | 3 | # GreenstoneXMLPlugout.pm -- the plugout module for Greenstone Archives
|
---|
[12330] | 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 |
|
---|
[17743] | 26 | package GreenstoneXMLPlugout;
|
---|
[12330] | 27 |
|
---|
| 28 | use strict;
|
---|
| 29 | no strict 'refs';
|
---|
[13172] | 30 | no strict 'subs';
|
---|
[12330] | 31 |
|
---|
| 32 | eval {require bytes};
|
---|
| 33 | use util;
|
---|
[27306] | 34 | use FileUtils;
|
---|
[17203] | 35 | use BasePlugout;
|
---|
[13172] | 36 | use docprint;
|
---|
[12330] | 37 |
|
---|
| 38 | sub BEGIN {
|
---|
[17743] | 39 | @GreenstoneXMLPlugout::ISA = ('BasePlugout');
|
---|
[12330] | 40 | }
|
---|
| 41 |
|
---|
| 42 | my $arguments = [];
|
---|
| 43 |
|
---|
[17743] | 44 | my $options = { 'name' => "GreenstoneXMLPlugout",
|
---|
| 45 | 'desc' => "{GreenstoneXMLPlugout.desc}",
|
---|
[12330] | 46 | 'abstract' => "no",
|
---|
| 47 | 'inherits' => "yes" };
|
---|
| 48 |
|
---|
| 49 | sub new {
|
---|
| 50 | my ($class) = shift (@_);
|
---|
| 51 | my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
|
---|
| 52 | push(@$plugoutlist, $class);
|
---|
| 53 |
|
---|
[17203] | 54 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 55 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[12330] | 56 |
|
---|
[17203] | 57 | my $self = new BasePlugout($plugoutlist,$inputargs,$hashArgOptLists);
|
---|
[12330] | 58 |
|
---|
[17203] | 59 | return bless $self, $class;
|
---|
[12330] | 60 | }
|
---|
| 61 |
|
---|
| 62 | sub saveas {
|
---|
| 63 | my $self = shift (@_);
|
---|
| 64 | my ($doc_obj,$doc_dir) = @_;
|
---|
| 65 |
|
---|
[13172] | 66 | my $outhandler;
|
---|
[27522] | 67 | my $output_file;
|
---|
[13172] | 68 | if ($self->{'debug'}) {
|
---|
| 69 | $outhandler = STDOUT;
|
---|
| 70 | # can we do the xslt and still do debug mode?
|
---|
[27517] | 71 | }
|
---|
[13172] | 72 | else {
|
---|
| 73 | my $output_dir = $self->get_output_dir();
|
---|
[27517] | 74 | if (!&FileUtils::directoryExists($output_dir))
|
---|
| 75 | {
|
---|
| 76 | &FileUtils::makeAllDirectories($output_dir);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | my $working_dir = &FileUtils::filenameConcatenate($output_dir, $doc_dir);
|
---|
| 80 | if (!&FileUtils::directoryExists($working_dir))
|
---|
| 81 | {
|
---|
| 82 | &FileUtils::makeAllDirectories($working_dir);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[13172] | 85 | $self->process_assoc_files ($doc_obj, $doc_dir, '');
|
---|
[27517] | 86 |
|
---|
[19494] | 87 | $self->process_metafiles_metadata ($doc_obj);
|
---|
| 88 |
|
---|
[27522] | 89 | $output_file = &FileUtils::filenameConcatenate($working_dir, "doc.xml");
|
---|
[27517] | 90 |
|
---|
[13172] | 91 | $self->open_xslt_pipe($output_file, $self->{'xslt_file'});
|
---|
[27517] | 92 |
|
---|
[13172] | 93 | if (defined $self->{'xslt_writer'}){
|
---|
| 94 | $outhandler = $self->{'xslt_writer'};
|
---|
| 95 | }
|
---|
| 96 | else{
|
---|
| 97 | $outhandler = $self->get_output_handler($output_file);
|
---|
| 98 | }
|
---|
[12330] | 99 | }
|
---|
[27517] | 100 |
|
---|
[22839] | 101 | binmode($outhandler,":utf8");
|
---|
| 102 |
|
---|
[12330] | 103 | $self->output_xml_header($outhandler,"Archive");
|
---|
[13172] | 104 | my $section_output = &docprint::get_section_xml($doc_obj, $doc_obj->get_top_section());
|
---|
| 105 | print $outhandler $section_output;
|
---|
[12330] | 106 | $self->output_xml_footer($outhandler,"Archive");
|
---|
| 107 |
|
---|
[13172] | 108 | if (!$self->{'debug'}) {
|
---|
| 109 | if (defined $self->{'xslt_writer'}){
|
---|
| 110 | $self->close_xslt_pipe();
|
---|
| 111 | }
|
---|
| 112 | else {
|
---|
[27522] | 113 | &FileUtils::closeFileHandle($output_file, \$outhandler) if defined $output_file;
|
---|
[13172] | 114 | }
|
---|
| 115 |
|
---|
[27306] | 116 | $self->{'short_doc_file'} = &FileUtils::filenameConcatenate($doc_dir, "doc.xml");
|
---|
[13172] | 117 |
|
---|
| 118 | $self->store_output_info_reference($doc_obj);
|
---|
[12330] | 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[13172] | 122 |
|
---|
| 123 |
|
---|
[12330] | 124 | 1;
|
---|
| 125 |
|
---|