source: main/trunk/greenstone2/perllib/plugins/ExcelPlugin.pm--for-gs311@ 34690

Last change on this file since 34690 was 34690, checked in by davidb, 3 years ago

When using an orthogonal index, the constructor is run for a second time. The -process_exp is no longer a function (&default_...) all, but resolved as the string/regular expression to use, meaning the eval call should not be run

File size: 5.5 KB
Line 
1###########################################################################
2#
3# ExcelPlugin.pm -- plugin for importing Microsoft Excel files.
4# (basic version supports versions 95 and 97)
5# (through OpenOffice extension, supports all contempoary formats)
6#
7# A component of the Greenstone digital library software
8# from the New Zealand Digital Library Project at the
9# University of Waikato, New Zealand.
10#
11# Copyright (C) 2002 New Zealand Digital Library Project
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2 of the License, or
16# (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#
27###########################################################################
28
29package ExcelPlugin;
30
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33no strict 'subs';
34use gsprintf 'gsprintf';
35
36use AutoLoadConverters;
37use ConvertBinaryFile;
38
39sub BEGIN {
40 @ExcelPlugin::ISA = ('ConvertBinaryFile', 'AutoLoadConverters');
41}
42
43my $openoffice_available = 0;
44
45my $arguments =
46 [ { 'name' => "process_exp",
47 'desc' => "{BaseImporter.process_exp}",
48 'type' => "regexp",
49 'reqd' => "no",
50 'deft' => "&get_default_process_exp()" # delayed (see below)
51 }
52 ];
53
54my $options = { 'name' => "ExcelPlugin",
55 'desc' => "{ExcelPlugin.desc}",
56 'abstract' => "no",
57 'inherits' => "yes",
58 'srcreplaceable' => "yes", # Source docs in Excel format can be replaced with GS-generated html
59 'args' => $arguments };
60
61sub new {
62 my ($class) = shift (@_);
63 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
64 push(@$pluginlist, $class);
65
66 # this bit needs to happen later after the arguments array has been
67 # finished - used for parsing the input args.
68 # push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
69 # this one needs to go in first, to get the print info in the right order
70 push(@{$hashArgOptLists->{"OptList"}},$options);
71
72 my $auto_converter_self = new AutoLoadConverters($pluginlist,$inputargs,$hashArgOptLists,["OpenOfficeConverter"],1);
73
74 if ($auto_converter_self->{'openoffice_available'}) {
75 $openoffice_available = 1;
76 }
77
78 # evaluate the default for process_exp - it needs to be delayed till here so we know if openoffice is available or not. But needs to be done before parsing the args.
79 foreach my $a (@$arguments) {
80 if ($a->{'name'} eq "process_exp") {
81 my $eval_expr = $a->{'deft'};
82 if ($eval_expr =~ m/^&/) {
83 $a->{'deft'} = eval "$eval_expr";
84 }
85 last;
86 }
87 }
88
89 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
90 my $cbf_self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
91 my $self = BaseImporter::merge_inheritance($auto_converter_self, $cbf_self);
92
93
94 if ($self->{'info_only'}) {
95 # don't worry about any options etc
96 return bless $self, $class;
97 }
98
99 $self = bless $self, $class;
100 $self->{'file_type'} = "Excel";
101
102 my $outhandle = $self->{'outhandle'};
103
104 # check convert_to
105 if ($self->{'convert_to'} eq "auto") {
106 $self->{'convert_to'} = "html";
107 }
108
109 # set convert_to_plugin and convert_to_ext
110 $self->set_standard_convert_settings();
111
112 my $secondary_plugin_name = $self->{'convert_to_plugin'};
113 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
114
115 if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
116 $secondary_plugin_options->{$secondary_plugin_name} = [];
117 }
118 my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
119
120 push(@$specific_options,"-extract_language") if $self->{'extract_language'};
121 push(@$specific_options, "-file_rename_method", "none");
122
123 if ($secondary_plugin_name eq "HTMLPlugin") {
124 push(@$specific_options, "-processing_tmp_files");
125 }
126
127 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
128 return $self;
129}
130
131
132sub get_default_process_exp {
133 my $self = shift (@_);
134
135 if ($openoffice_available) {
136 return q^(?i)\.(xls|xlsx|ods)$^;
137 }
138
139 return q^(?i)\.xls$^;
140}
141
142sub init {
143 my $self = shift (@_);
144
145 # ConvertBinaryFile init
146 $self->SUPER::init(@_);
147 $self->AutoLoadConverters::init(@_);
148
149}
150
151sub begin {
152 my $self = shift (@_);
153
154 $self->AutoLoadConverters::begin(@_);
155 $self->SUPER::begin(@_);
156
157}
158
159sub deinit {
160 my $self = shift (@_);
161
162 $self->AutoLoadConverters::deinit(@_);
163 $self->SUPER::deinit(@_);
164
165}
166
167sub tmp_area_convert_file {
168
169 my $self = shift (@_);
170 return $self->AutoLoadConverters::tmp_area_convert_file(@_);
171
172}
173
174sub convert_post_process_old
175{
176 my $self = shift (@_);
177 my ($conv_filename) = @_;
178
179 my $outhandle=$self->{'outhandle'};
180
181 my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
182
183 # read in file ($text will be in utf8)
184 my $text = "";
185 $self->read_file ($conv_filename, $encoding, $language, \$text);
186
187 # turn any high bytes that aren't valid utf-8 into utf-8.
188 #unicode::ensure_utf8(\$text);
189
190 # Write it out again!
191 #$self->utf8_write_file (\$text, $conv_filename);
192}
193
1941;
Note: See TracBrowser for help on using the repository browser.