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

Revision 22666, 3.7 KB (checked in by davidb, 10 years ago)

Commented out debugging statement

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 deinit {
105    # called only once, after all plugin passes have been done
106    my ($self) = @_;
107   
108    if ($openoffice_ext_working) {
109    $self->OpenOfficeConverter::deinit();
110    }
111    $self->SUPER::deinit();
112}
113
114# if we are using open office, we use OpenOfficeConverter's convert method, otherwise fall back to ConvertBinaryFile method.
115sub tmp_area_convert_file {
116    my $self = shift (@_);
117    my ($output_ext, $input_filename, $textref) = @_;
118
119    if ($openoffice_ext_working && $self->{'openoffice_scripting'}) {
120    my ($result, $result_str, $new_filename) = $self->OpenOfficeConverter::convert($input_filename, $output_ext);
121    if ($result != 0) {
122        return $new_filename;
123    }
124    my $outhandle=$self->{'outhandle'};
125    print $outhandle "Open Office Conversion error\n";
126    print $outhandle $result_str;
127    return "";
128    }
129    else {
130    return $self->ConvertBinaryFile::tmp_area_convert_file(@_);
131    }
132}
Note: See TracBrowser for help on using the browser.