[2990] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15872] | 3 | # ExcelPlugin.pm -- plugin for importing Microsoft Excel files.
|
---|
[22709] | 4 | # (basic version supports versions 95 and 97)
|
---|
| 5 | # (through OpenOffice extension, supports all contempoary formats)
|
---|
[2990] | 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 |
|
---|
[15872] | 29 | package ExcelPlugin;
|
---|
[2990] | 30 |
|
---|
[10254] | 31 | use strict;
|
---|
| 32 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[22515] | 33 | no strict 'subs';
|
---|
| 34 | use gsprintf 'gsprintf';
|
---|
[2990] | 35 |
|
---|
[22861] | 36 | use AutoLoadConverters;
|
---|
| 37 | use ConvertBinaryFile;
|
---|
[2990] | 38 |
|
---|
[22861] | 39 | sub BEGIN {
|
---|
| 40 | @ExcelPlugin::ISA = ('ConvertBinaryFile', 'AutoLoadConverters');
|
---|
| 41 | }
|
---|
[22705] | 42 |
|
---|
[22861] | 43 | my $openoffice_available = 0;
|
---|
[22705] | 44 |
|
---|
[6408] | 45 | my $arguments =
|
---|
| 46 | [ { 'name' => "process_exp",
|
---|
[31492] | 47 | 'desc' => "{BaseImporter.process_exp}",
|
---|
[6408] | 48 | 'type' => "regexp",
|
---|
| 49 | 'reqd' => "no",
|
---|
[22861] | 50 | 'deft' => "&get_default_process_exp()" # delayed (see below)
|
---|
[22709] | 51 | }
|
---|
[6408] | 52 | ];
|
---|
| 53 |
|
---|
[15872] | 54 | my $options = { 'name' => "ExcelPlugin",
|
---|
| 55 | 'desc' => "{ExcelPlugin.desc}",
|
---|
[6408] | 56 | 'abstract' => "no",
|
---|
| 57 | 'inherits' => "yes",
|
---|
[15114] | 58 | 'srcreplaceable' => "yes", # Source docs in Excel format can be replaced with GS-generated html
|
---|
[6408] | 59 | 'args' => $arguments };
|
---|
[4744] | 60 |
|
---|
[2990] | 61 | sub new {
|
---|
[10218] | 62 | my ($class) = shift (@_);
|
---|
| 63 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 64 | push(@$pluginlist, $class);
|
---|
[22515] | 65 |
|
---|
[22861] | 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
|
---|
[15918] | 70 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[2990] | 71 |
|
---|
[22861] | 72 | my $auto_converter_self = new AutoLoadConverters($pluginlist,$inputargs,$hashArgOptLists,["OpenOfficeConverter"],1);
|
---|
[22709] | 73 |
|
---|
[22865] | 74 | if ($auto_converter_self->{'openoffice_available'}) {
|
---|
| 75 | $openoffice_available = 1;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[22861] | 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) {
|
---|
[22709] | 80 | if ($a->{'name'} eq "process_exp") {
|
---|
| 81 | my $eval_expr = $a->{'deft'};
|
---|
[34997] | 82 | if ($eval_expr =~ m/^&/) {
|
---|
| 83 | $a->{'deft'} = eval "$eval_expr";
|
---|
| 84 | }
|
---|
[22861] | 85 | last;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
[22709] | 88 |
|
---|
[22861] | 89 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 90 | my $cbf_self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[31492] | 91 | my $self = BaseImporter::merge_inheritance($auto_converter_self, $cbf_self);
|
---|
[22709] | 92 |
|
---|
| 93 |
|
---|
[10580] | 94 | if ($self->{'info_only'}) {
|
---|
| 95 | # don't worry about any options etc
|
---|
| 96 | return bless $self, $class;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[22861] | 99 | $self = bless $self, $class;
|
---|
[15872] | 100 | $self->{'file_type'} = "Excel";
|
---|
| 101 |
|
---|
[22597] | 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
|
---|
[22639] | 110 | $self->set_standard_convert_settings();
|
---|
[22597] | 111 |
|
---|
| 112 | my $secondary_plugin_name = $self->{'convert_to_plugin'};
|
---|
[10424] | 113 | my $secondary_plugin_options = $self->{'secondary_plugin_options'};
|
---|
[22597] | 114 |
|
---|
| 115 | if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
|
---|
| 116 | $secondary_plugin_options->{$secondary_plugin_name} = [];
|
---|
[10424] | 117 | }
|
---|
[22597] | 118 | my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
|
---|
[18406] | 119 |
|
---|
[22597] | 120 | push(@$specific_options,"-extract_language") if $self->{'extract_language'};
|
---|
| 121 | push(@$specific_options, "-file_rename_method", "none");
|
---|
[20790] | 122 |
|
---|
[22597] | 123 | if ($secondary_plugin_name eq "HTMLPlugin") {
|
---|
| 124 | push(@$specific_options, "-processing_tmp_files");
|
---|
| 125 | }
|
---|
[10424] | 126 |
|
---|
| 127 | $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
|
---|
[22639] | 128 | return $self;
|
---|
[2990] | 129 | }
|
---|
| 130 |
|
---|
[22639] | 131 |
|
---|
[22861] | 132 | sub 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 |
|
---|
| 142 | sub init {
|
---|
| 143 | my $self = shift (@_);
|
---|
| 144 |
|
---|
| 145 | # ConvertBinaryFile init
|
---|
| 146 | $self->SUPER::init(@_);
|
---|
[23751] | 147 | $self->AutoLoadConverters::init(@_);
|
---|
[22861] | 148 |
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | sub begin {
|
---|
| 152 | my $self = shift (@_);
|
---|
| 153 |
|
---|
[23751] | 154 | $self->AutoLoadConverters::begin(@_);
|
---|
[22861] | 155 | $self->SUPER::begin(@_);
|
---|
| 156 |
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | sub deinit {
|
---|
| 160 | my $self = shift (@_);
|
---|
| 161 |
|
---|
[23751] | 162 | $self->AutoLoadConverters::deinit(@_);
|
---|
[22861] | 163 | $self->SUPER::deinit(@_);
|
---|
| 164 |
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | sub tmp_area_convert_file {
|
---|
| 168 |
|
---|
| 169 | my $self = shift (@_);
|
---|
| 170 | return $self->AutoLoadConverters::tmp_area_convert_file(@_);
|
---|
| 171 |
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[15872] | 174 | sub convert_post_process_old
|
---|
[10465] | 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 |
|
---|
[2990] | 194 | 1;
|
---|