[2990] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15872] | 3 | # ExcelPlugin.pm -- plugin for importing Microsoft Excel files.
|
---|
[2990] | 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 |
|
---|
[15872] | 28 | package ExcelPlugin;
|
---|
[2990] | 29 |
|
---|
[10254] | 30 | use strict;
|
---|
| 31 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[22515] | 32 | no strict 'subs';
|
---|
| 33 | use gsprintf 'gsprintf';
|
---|
[2990] | 34 |
|
---|
[22705] | 35 | use AutoloadConverterScripting;
|
---|
[2990] | 36 |
|
---|
[22705] | 37 | @ExcelPlugin::ISA = ('AutoloadConverterScripting');
|
---|
| 38 |
|
---|
| 39 |
|
---|
[6408] | 40 | my $arguments =
|
---|
| 41 | [ { 'name' => "process_exp",
|
---|
[15872] | 42 | 'desc' => "{BasePlugin.process_exp}",
|
---|
[6408] | 43 | 'type' => "regexp",
|
---|
| 44 | 'reqd' => "no",
|
---|
| 45 | 'deft' => &get_default_process_exp() }
|
---|
| 46 | ];
|
---|
| 47 |
|
---|
[15872] | 48 | my $options = { 'name' => "ExcelPlugin",
|
---|
| 49 | 'desc' => "{ExcelPlugin.desc}",
|
---|
[6408] | 50 | 'abstract' => "no",
|
---|
| 51 | 'inherits' => "yes",
|
---|
[15114] | 52 | 'srcreplaceable' => "yes", # Source docs in Excel format can be replaced with GS-generated html
|
---|
[6408] | 53 | 'args' => $arguments };
|
---|
[4744] | 54 |
|
---|
[2990] | 55 | sub new {
|
---|
[10218] | 56 | my ($class) = shift (@_);
|
---|
| 57 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 58 | push(@$pluginlist, $class);
|
---|
[22515] | 59 |
|
---|
[15918] | 60 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 61 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[2990] | 62 |
|
---|
[22705] | 63 | my $self = new AutoloadConverterScripting("OpenOfficeConverter",$pluginlist, $inputargs, $hashArgOptLists);
|
---|
[22639] | 64 |
|
---|
[10580] | 65 | if ($self->{'info_only'}) {
|
---|
| 66 | # don't worry about any options etc
|
---|
| 67 | return bless $self, $class;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[15872] | 70 | $self->{'filename_extension'} = "xls";
|
---|
| 71 | $self->{'file_type'} = "Excel";
|
---|
| 72 |
|
---|
[22597] | 73 | my $outhandle = $self->{'outhandle'};
|
---|
| 74 |
|
---|
| 75 | # check convert_to
|
---|
| 76 | if ($self->{'convert_to'} eq "auto") {
|
---|
| 77 | $self->{'convert_to'} = "html";
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[22639] | 80 | $self = bless $self, $class;
|
---|
[22597] | 81 | # set convert_to_plugin and convert_to_ext
|
---|
[22639] | 82 | $self->set_standard_convert_settings();
|
---|
[22597] | 83 |
|
---|
| 84 | my $secondary_plugin_name = $self->{'convert_to_plugin'};
|
---|
[10424] | 85 | my $secondary_plugin_options = $self->{'secondary_plugin_options'};
|
---|
[22597] | 86 |
|
---|
| 87 | if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
|
---|
| 88 | $secondary_plugin_options->{$secondary_plugin_name} = [];
|
---|
[10424] | 89 | }
|
---|
[22597] | 90 | my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
|
---|
[18406] | 91 |
|
---|
[22597] | 92 | push(@$specific_options,"-extract_language") if $self->{'extract_language'};
|
---|
| 93 | push(@$specific_options, "-file_rename_method", "none");
|
---|
[20790] | 94 |
|
---|
[22597] | 95 | if ($secondary_plugin_name eq "HTMLPlugin") {
|
---|
| 96 | push(@$specific_options, "-processing_tmp_files");
|
---|
| 97 | }
|
---|
[10424] | 98 |
|
---|
| 99 | $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
|
---|
[22639] | 100 | return $self;
|
---|
[2990] | 101 | }
|
---|
| 102 |
|
---|
[22639] | 103 |
|
---|
[15872] | 104 | sub convert_post_process_old
|
---|
[10465] | 105 | {
|
---|
| 106 | my $self = shift (@_);
|
---|
| 107 | my ($conv_filename) = @_;
|
---|
| 108 |
|
---|
| 109 | my $outhandle=$self->{'outhandle'};
|
---|
| 110 |
|
---|
| 111 | my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
|
---|
| 112 |
|
---|
| 113 | # read in file ($text will be in utf8)
|
---|
| 114 | my $text = "";
|
---|
| 115 | $self->read_file ($conv_filename, $encoding, $language, \$text);
|
---|
| 116 |
|
---|
| 117 | # turn any high bytes that aren't valid utf-8 into utf-8.
|
---|
| 118 | #unicode::ensure_utf8(\$text);
|
---|
| 119 |
|
---|
| 120 | # Write it out again!
|
---|
| 121 | #$self->utf8_write_file (\$text, $conv_filename);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[2990] | 124 | sub get_default_process_exp {
|
---|
| 125 | my $self = shift (@_);
|
---|
| 126 | return q^(?i)\.xls$^;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | 1;
|
---|