1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # ExcelPlugin.pm -- plugin for importing Microsoft Excel files.
|
---|
4 | # (currently only versions 95 and 97)
|
---|
5 | #
|
---|
6 | # A component of the Greenstone digital library software
|
---|
7 | # from the New Zealand Digital Library Project at the
|
---|
8 | # University of Waikato, New Zealand.
|
---|
9 | #
|
---|
10 | # Copyright (C) 2002 New Zealand Digital Library Project
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or modify
|
---|
13 | # it under the terms of the GNU General Public License as published by
|
---|
14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
15 | # (at your option) any later version.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful,
|
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | # GNU General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, write to the Free Software
|
---|
24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | #
|
---|
26 | ###########################################################################
|
---|
27 |
|
---|
28 | package ExcelPlugin;
|
---|
29 |
|
---|
30 | use ConvertBinaryFile;
|
---|
31 | use strict;
|
---|
32 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
33 | no strict 'subs';
|
---|
34 | use gsprintf 'gsprintf';
|
---|
35 |
|
---|
36 | #sub BEGIN {
|
---|
37 | # @ExcelPlugin::ISA = ('ConvertBinaryFile');
|
---|
38 | #}
|
---|
39 |
|
---|
40 | # @ISA dynamically configured to be either OpenOfficeConverter or ConvertBinaryFile
|
---|
41 |
|
---|
42 | # do not initialise these variables
|
---|
43 | my $openoffice_ext_installed;
|
---|
44 | my $openoffice_ext_working;
|
---|
45 | sub BEGIN {
|
---|
46 | eval("require OpenOfficeConverter");
|
---|
47 | if ($@) {
|
---|
48 | # Useful debugging statement if there is a syntax error in OpenOfficeConverter
|
---|
49 | #print STDERR "$@\n";
|
---|
50 | @ExcelPlugin::ISA = ('ConvertBinaryFile');
|
---|
51 | $openoffice_ext_installed = 0;
|
---|
52 | $openoffice_ext_working = 0;
|
---|
53 | }
|
---|
54 | else {
|
---|
55 | # Successfully found
|
---|
56 | $openoffice_ext_installed = 1;
|
---|
57 | # now check whether it can run soffice
|
---|
58 | if ($OpenOfficeConverter::openoffice_conversion_available) {
|
---|
59 | @ExcelPlugin::ISA = ('OpenOfficeConverter');
|
---|
60 | $openoffice_ext_working = 1;
|
---|
61 |
|
---|
62 | } else {
|
---|
63 | @ExcelPlugin::ISA = ('ConvertBinaryFile');
|
---|
64 | $openoffice_ext_working = 0;
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | my $arguments =
|
---|
70 | [ { 'name' => "process_exp",
|
---|
71 | 'desc' => "{BasePlugin.process_exp}",
|
---|
72 | 'type' => "regexp",
|
---|
73 | 'reqd' => "no",
|
---|
74 | 'deft' => &get_default_process_exp() }
|
---|
75 | ];
|
---|
76 |
|
---|
77 | my $opt_openoffice_args =
|
---|
78 | [ { 'name' => "openoffice_scripting",
|
---|
79 | 'desc' => "{OpenOfficeConverter.openoffice_scripting}",
|
---|
80 | 'type' => "flag",
|
---|
81 | 'reqd' => "no" } ];
|
---|
82 |
|
---|
83 |
|
---|
84 | my $options = { 'name' => "ExcelPlugin",
|
---|
85 | 'desc' => "{ExcelPlugin.desc}",
|
---|
86 | 'abstract' => "no",
|
---|
87 | 'inherits' => "yes",
|
---|
88 | 'srcreplaceable' => "yes", # Source docs in Excel format can be replaced with GS-generated html
|
---|
89 | 'args' => $arguments };
|
---|
90 |
|
---|
91 | sub new {
|
---|
92 | my ($class) = shift (@_);
|
---|
93 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
94 | push(@$pluginlist, $class);
|
---|
95 |
|
---|
96 | #my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
97 | if ($openoffice_ext_installed) {
|
---|
98 | print STDERR "ExcelPlugin: OpenOffice Extension to Greenstone detected\n";
|
---|
99 | if ($openoffice_ext_working) {
|
---|
100 | print STDERR "... and it appears to be working\n";
|
---|
101 | } else {
|
---|
102 | print STDERR "... but it appears to be broken\n";
|
---|
103 | &gsprintf(STDERR, "OpenOfficeConverter: {OpenOfficeConverter.noconversionavailable} ({OpenOfficeConverter.$OpenOfficeConverter::no_openoffice_conversion_reason})\n");
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | if ($openoffice_ext_working) {
|
---|
108 | push(@$arguments,@$opt_openoffice_args);
|
---|
109 | }
|
---|
110 |
|
---|
111 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
112 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
113 |
|
---|
114 | my $self = {};
|
---|
115 |
|
---|
116 | if ($openoffice_ext_working) {
|
---|
117 | $self = new OpenOfficeConverter($pluginlist, $inputargs, $hashArgOptLists);
|
---|
118 | }
|
---|
119 | else {
|
---|
120 | $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
121 | }
|
---|
122 |
|
---|
123 | if ($self->{'info_only'}) {
|
---|
124 | # don't worry about any options etc
|
---|
125 | return bless $self, $class;
|
---|
126 | }
|
---|
127 |
|
---|
128 | my $outhandle = $self->{'outhandle'};
|
---|
129 |
|
---|
130 | $self->{'filename_extension'} = "xls";
|
---|
131 | $self->{'file_type'} = "Excel";
|
---|
132 |
|
---|
133 | $self->{'convert_options'} = "-openoffice_scripting" if $self->{'openoffice_scripting'};
|
---|
134 |
|
---|
135 | # other options for HTML if using open office???
|
---|
136 | my $secondary_plugin_options = $self->{'secondary_plugin_options'};
|
---|
137 | if (!defined $secondary_plugin_options->{'HTMLPlugin'}) {
|
---|
138 | $secondary_plugin_options->{'HTMLPlugin'} = [];
|
---|
139 | }
|
---|
140 | if (!defined $secondary_plugin_options->{'TextPlugin'}) {
|
---|
141 | $secondary_plugin_options->{'TextPlugin'} = [];
|
---|
142 | }
|
---|
143 | my $html_options = $secondary_plugin_options->{'HTMLPlugin'};
|
---|
144 | my $text_options = $secondary_plugin_options->{'TextPlugin'};
|
---|
145 |
|
---|
146 | # xslhtml doesn't output utf8, let Greenstone work out the encoding
|
---|
147 | #push(@$html_options, "-input_encoding", "utf8");
|
---|
148 | push(@$html_options,"-extract_language") if $self->{'extract_language'};
|
---|
149 | push(@$html_options, "-file_rename_method", "none");
|
---|
150 | push(@$html_options, "-processing_tmp_files");
|
---|
151 |
|
---|
152 | #push(@$text_options, "-input_encoding", "utf8");
|
---|
153 | push(@$text_options,"-extract_language") if $self->{'extract_language'};
|
---|
154 | push(@$text_options, "-file_rename_method", "none");
|
---|
155 |
|
---|
156 | $self = bless $self, $class;
|
---|
157 |
|
---|
158 | $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
|
---|
159 | return bless $self;
|
---|
160 | }
|
---|
161 |
|
---|
162 | sub convert_post_process_old
|
---|
163 | {
|
---|
164 | my $self = shift (@_);
|
---|
165 | my ($conv_filename) = @_;
|
---|
166 |
|
---|
167 | my $outhandle=$self->{'outhandle'};
|
---|
168 |
|
---|
169 | my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
|
---|
170 |
|
---|
171 | # read in file ($text will be in utf8)
|
---|
172 | my $text = "";
|
---|
173 | $self->read_file ($conv_filename, $encoding, $language, \$text);
|
---|
174 |
|
---|
175 | # turn any high bytes that aren't valid utf-8 into utf-8.
|
---|
176 | #unicode::ensure_utf8(\$text);
|
---|
177 |
|
---|
178 | # Write it out again!
|
---|
179 | #$self->utf8_write_file (\$text, $conv_filename);
|
---|
180 | }
|
---|
181 |
|
---|
182 | sub get_default_process_exp {
|
---|
183 | my $self = shift (@_);
|
---|
184 | return q^(?i)\.xls$^;
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | 1;
|
---|