[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'};
|
---|
| 82 | $a->{'deft'} = eval "$eval_expr";
|
---|
[22861] | 83 | last;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
[22709] | 86 |
|
---|
[22861] | 87 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 88 | my $cbf_self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[31492] | 89 | my $self = BaseImporter::merge_inheritance($auto_converter_self, $cbf_self);
|
---|
[22709] | 90 |
|
---|
| 91 |
|
---|
[10580] | 92 | if ($self->{'info_only'}) {
|
---|
| 93 | # don't worry about any options etc
|
---|
| 94 | return bless $self, $class;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[22861] | 97 | $self = bless $self, $class;
|
---|
[15872] | 98 | $self->{'file_type'} = "Excel";
|
---|
| 99 |
|
---|
[22597] | 100 | my $outhandle = $self->{'outhandle'};
|
---|
| 101 |
|
---|
| 102 | # check convert_to
|
---|
| 103 | if ($self->{'convert_to'} eq "auto") {
|
---|
| 104 | $self->{'convert_to'} = "html";
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | # set convert_to_plugin and convert_to_ext
|
---|
[22639] | 108 | $self->set_standard_convert_settings();
|
---|
[22597] | 109 |
|
---|
| 110 | my $secondary_plugin_name = $self->{'convert_to_plugin'};
|
---|
[10424] | 111 | my $secondary_plugin_options = $self->{'secondary_plugin_options'};
|
---|
[22597] | 112 |
|
---|
| 113 | if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
|
---|
| 114 | $secondary_plugin_options->{$secondary_plugin_name} = [];
|
---|
[10424] | 115 | }
|
---|
[22597] | 116 | my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
|
---|
[18406] | 117 |
|
---|
[22597] | 118 | push(@$specific_options,"-extract_language") if $self->{'extract_language'};
|
---|
| 119 | push(@$specific_options, "-file_rename_method", "none");
|
---|
[20790] | 120 |
|
---|
[22597] | 121 | if ($secondary_plugin_name eq "HTMLPlugin") {
|
---|
| 122 | push(@$specific_options, "-processing_tmp_files");
|
---|
| 123 | }
|
---|
[10424] | 124 |
|
---|
| 125 | $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
|
---|
[22639] | 126 | return $self;
|
---|
[2990] | 127 | }
|
---|
| 128 |
|
---|
[22639] | 129 |
|
---|
[22861] | 130 | sub get_default_process_exp {
|
---|
| 131 | my $self = shift (@_);
|
---|
| 132 |
|
---|
| 133 | if ($openoffice_available) {
|
---|
| 134 | return q^(?i)\.(xls|xlsx|ods)$^;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | return q^(?i)\.xls$^;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | sub init {
|
---|
| 141 | my $self = shift (@_);
|
---|
| 142 |
|
---|
| 143 | # ConvertBinaryFile init
|
---|
| 144 | $self->SUPER::init(@_);
|
---|
[23751] | 145 | $self->AutoLoadConverters::init(@_);
|
---|
[22861] | 146 |
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | sub begin {
|
---|
| 150 | my $self = shift (@_);
|
---|
| 151 |
|
---|
[23751] | 152 | $self->AutoLoadConverters::begin(@_);
|
---|
[22861] | 153 | $self->SUPER::begin(@_);
|
---|
| 154 |
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | sub deinit {
|
---|
| 158 | my $self = shift (@_);
|
---|
| 159 |
|
---|
[23751] | 160 | $self->AutoLoadConverters::deinit(@_);
|
---|
[22861] | 161 | $self->SUPER::deinit(@_);
|
---|
| 162 |
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | sub tmp_area_convert_file {
|
---|
| 166 |
|
---|
| 167 | my $self = shift (@_);
|
---|
| 168 | return $self->AutoLoadConverters::tmp_area_convert_file(@_);
|
---|
| 169 |
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[15872] | 172 | sub convert_post_process_old
|
---|
[10465] | 173 | {
|
---|
| 174 | my $self = shift (@_);
|
---|
| 175 | my ($conv_filename) = @_;
|
---|
| 176 |
|
---|
| 177 | my $outhandle=$self->{'outhandle'};
|
---|
| 178 |
|
---|
| 179 | my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
|
---|
| 180 |
|
---|
| 181 | # read in file ($text will be in utf8)
|
---|
| 182 | my $text = "";
|
---|
| 183 | $self->read_file ($conv_filename, $encoding, $language, \$text);
|
---|
| 184 |
|
---|
| 185 | # turn any high bytes that aren't valid utf-8 into utf-8.
|
---|
| 186 | #unicode::ensure_utf8(\$text);
|
---|
| 187 |
|
---|
| 188 | # Write it out again!
|
---|
| 189 | #$self->utf8_write_file (\$text, $conv_filename);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[2990] | 192 | 1;
|
---|