root/main/trunk/greenstone2/perllib/plugins/OOConvertBinaryFile.pm @ 22673

Revision 22673, 3.9 KB (checked in by sjm84, 9 years ago)

Dr. Bainbridge added a begin method to OOConvertBinaryFile

Line 
1package OOConvertBinaryFile;
2
3use ConvertBinaryFile;
4
5
6use gsprintf 'gsprintf';
7# @ISA dynamically configured to be either OpenOfficeConverter or ConvertBinaryFile
8
9# do not initialise these variables
10my $openoffice_ext_installed;
11my $openoffice_ext_working;
12sub BEGIN {
13    eval("require OpenOfficeConverter");
14    if ($@) {
15    # Useful debugging statement if there is a syntax error in OpenOfficeConverter:
16    # print STDERR "$@\n";
17    $openoffice_ext_installed = 0;
18    $openoffice_ext_working = 0;
19    }
20    else {
21    # Successfully found
22    $openoffice_ext_installed = 1;
23    # now check whether it can run soffice
24    if ($OpenOfficeConverter::openoffice_conversion_available) {
25        $openoffice_ext_working = 1;
26       
27    } else {
28        $openoffice_ext_working = 0;
29    }
30    }
31
32    if ($openoffice_ext_working) {
33    @OOConvertBinaryFile::ISA = ('ConvertBinaryFile', 'OpenOfficeConverter');
34    } else {
35    @OOConvertBinaryFile::ISA = ('ConvertBinaryFile');
36    }
37}
38
39my $opt_openoffice_args =
40    [ { 'name' => "openoffice_scripting",
41    'desc' => "{OpenOfficeConverter.openoffice_scripting}",
42    'type' => "flag",
43    'reqd' => "no" } ];
44
45my $arguments = [];
46
47my $options = { 'name'     => "OOConvertBinaryFile",
48        'desc'     => "{OOConvertBinaryFile.desc}",
49        'abstract' => "yes",
50        'inherits' => "yes",
51        'args'     => $arguments };
52
53sub new {
54    my ($class) = shift (@_);
55    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
56    push(@$pluginlist, $class);
57
58    if ($openoffice_ext_installed) {
59    print STDERR "$class: OpenOffice Extension to Greenstone detected\n";
60    if ($openoffice_ext_working) {
61        print STDERR "... and it appears to be working\n";
62    } else {
63        print STDERR "... but it appears to be broken\n";
64        &gsprintf(STDERR, "OpenOfficeConverter: {OpenOfficeConverter.noconversionavailable} ({OpenOfficeConverter.$OpenOfficeConverter::no_openoffice_conversion_reason})\n");
65    }
66    }
67
68    if ($openoffice_ext_working) {
69    push(@$arguments,@$opt_openoffice_args);
70    }
71
72    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
73    push(@{$hashArgOptLists->{"OptList"}},$options);
74
75    if ($openoffice_ext_working) {
76   
77    #$self = new OpenOfficeConverter($pluginlist, $inputargs, $hashArgOptLists);
78    my $ooc_self = new OpenOfficeConverter($pluginlist, $inputargs, $hashArgOptLists);
79    my $cbf_self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
80    $self = BasePlugin::merge_inheritance($ooc_self, $cbf_self);
81    $self->{'openoffice_available'} = 1;
82    }
83    else {
84    $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
85    $self->{'openoffice_available'} = 0;
86   }
87
88#    if ($self->{'info_only'}) {
89    # don't worry about any options etc
90    return bless $self, $class;
91#    }
92}
93
94sub init {
95    my $self = shift (@_);
96    my ($verbosity, $outhandle, $failhandle) = @_;
97   
98    $self->SUPER::init($verbosity,$outhandle,$failhandle);
99    if ($openoffice_ext_working) {
100    $self->OpenOfficeConverter::init();
101    }
102}
103
104sub begin {
105    my $self = shift (@_);
106
107    if ($openoffice_ext_working) {
108    $self->OpenOfficeConverter::begin(@_);
109    }
110    $self->SUPER::begin(@_);
111}
112
113sub deinit {
114    # called only once, after all plugin passes have been done
115    my ($self) = @_;
116   
117    if ($openoffice_ext_working) {
118    $self->OpenOfficeConverter::deinit();
119    }
120    $self->SUPER::deinit();
121}
122
123# if we are using open office, we use OpenOfficeConverter's convert method, otherwise fall back to ConvertBinaryFile method.
124sub tmp_area_convert_file {
125    my $self = shift (@_);
126    my ($output_ext, $input_filename, $textref) = @_;
127
128    if ($openoffice_ext_working && $self->{'openoffice_scripting'}) {
129    my ($result, $result_str, $new_filename) = $self->OpenOfficeConverter::convert($input_filename, $output_ext);
130    if ($result != 0) {
131        return $new_filename;
132    }
133    my $outhandle=$self->{'outhandle'};
134    print $outhandle "Open Office Conversion error\n";
135    print $outhandle $result_str;
136    return "";
137    }
138    else {
139    return $self->ConvertBinaryFile::tmp_area_convert_file(@_);
140    }
141}
Note: See TracBrowser for help on using the browser.