source: main/trunk/greenstone2/perllib/plugins/ExcelPlugin.pm@ 22658

Last change on this file since 22658 was 22639, checked in by kjdon, 14 years ago

now uses new OOConvertBinaryFile as super class

  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
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
28package ExcelPlugin;
29
30use OOConvertBinaryFile;
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33no strict 'subs';
34use gsprintf 'gsprintf';
35
36sub BEGIN {
37 @ExcelPlugin::ISA = ('OOConvertBinaryFile');
38}
39
40my $arguments =
41 [ { 'name' => "process_exp",
42 'desc' => "{BasePlugin.process_exp}",
43 'type' => "regexp",
44 'reqd' => "no",
45 'deft' => &get_default_process_exp() }
46 ];
47
48my $options = { 'name' => "ExcelPlugin",
49 'desc' => "{ExcelPlugin.desc}",
50 'abstract' => "no",
51 'inherits' => "yes",
52 'srcreplaceable' => "yes", # Source docs in Excel format can be replaced with GS-generated html
53 'args' => $arguments };
54
55sub new {
56 my ($class) = shift (@_);
57 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
58 push(@$pluginlist, $class);
59
60 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
61 push(@{$hashArgOptLists->{"OptList"}},$options);
62
63 my $self = new OOConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
64
65 if ($self->{'info_only'}) {
66 # don't worry about any options etc
67 return bless $self, $class;
68 }
69
70 $self->{'filename_extension'} = "xls";
71 $self->{'file_type'} = "Excel";
72
73 my $outhandle = $self->{'outhandle'};
74
75 # check convert_to
76 if ($self->{'convert_to'} eq "auto") {
77 $self->{'convert_to'} = "html";
78 }
79
80 $self = bless $self, $class;
81 # set convert_to_plugin and convert_to_ext
82 $self->set_standard_convert_settings();
83
84 my $secondary_plugin_name = $self->{'convert_to_plugin'};
85 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
86
87 if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
88 $secondary_plugin_options->{$secondary_plugin_name} = [];
89 }
90 my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
91
92 push(@$specific_options,"-extract_language") if $self->{'extract_language'};
93 push(@$specific_options, "-file_rename_method", "none");
94
95 if ($secondary_plugin_name eq "HTMLPlugin") {
96 push(@$specific_options, "-processing_tmp_files");
97 }
98
99 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
100 return $self;
101}
102
103
104sub convert_post_process_old
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
124sub get_default_process_exp {
125 my $self = shift (@_);
126 return q^(?i)\.xls$^;
127}
128
129
1301;
Note: See TracBrowser for help on using the repository browser.