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

Last change on this file since 22853 was 22709, checked in by davidb, 14 years ago

Fixed up -process_exp so it now dynamically configures itself properly, based on whether OpenOfficeConverter is found or not

  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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 AutoloadConverterScripting;
37
38@ExcelPlugin::ISA = ('AutoloadConverterScripting');
39
40
41my $arguments =
42 [ { 'name' => "process_exp",
43 'desc' => "{BasePlugin.process_exp}",
44 'type' => "regexp",
45 'reqd' => "no",
46 'deft' => "&get_default_process_exp(\$self)" # delayed (see below)
47 }
48 ];
49
50my $options = { 'name' => "ExcelPlugin",
51 'desc' => "{ExcelPlugin.desc}",
52 'abstract' => "no",
53 'inherits' => "yes",
54 'srcreplaceable' => "yes", # Source docs in Excel format can be replaced with GS-generated html
55 'args' => $arguments };
56
57sub new {
58 my ($class) = shift (@_);
59 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
60 push(@$pluginlist, $class);
61
62 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
63 push(@{$hashArgOptLists->{"OptList"}},$options);
64
65 my $self
66 = new AutoloadConverterScripting("OpenOfficeConverter",$pluginlist,
67 $inputargs, $hashArgOptLists);
68
69 # plugin's process_exp can only be correctly determined once autoloading
70 # has taken place
71 my $plug_options = $self->{'option_list'}->[0];
72 my $plug_args = $plug_options->{'args'};
73
74 foreach my $a (@$plug_args) {
75 # consider changing this to search for all values that are
76 # tagged as 'deft-delayed' = 1 ?!?
77
78 if ($a->{'name'} eq "process_exp") {
79 my $eval_expr = $a->{'deft'};
80 $a->{'deft'} = eval "$eval_expr";
81
82 # Now see if process_exp needs updating
83 my $process_exp = $self->{'process_exp'};
84 if (!$self->{'info_only'} && ($process_exp eq $eval_expr)) {
85 # process_exp is only defined if not 'info_only'
86 #
87 # if it does exist and it equals the unevaluated $eval_expr
88 # then it was set to the default (rather than overriden by
89 # the collect.cfg file)
90
91 $self->{'process_exp'} = $a->{'deft'};
92 }
93 }
94 }
95
96 if ($self->{'info_only'}) {
97 # don't worry about any options etc
98 return bless $self, $class;
99 }
100
101 $self->{'filename_extension'} = "xls";
102 $self->{'file_type'} = "Excel";
103
104 my $outhandle = $self->{'outhandle'};
105
106 # check convert_to
107 if ($self->{'convert_to'} eq "auto") {
108 $self->{'convert_to'} = "html";
109 }
110
111 $self = bless $self, $class;
112 # set convert_to_plugin and convert_to_ext
113 $self->set_standard_convert_settings();
114
115 my $secondary_plugin_name = $self->{'convert_to_plugin'};
116 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
117
118 if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
119 $secondary_plugin_options->{$secondary_plugin_name} = [];
120 }
121 my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
122
123 push(@$specific_options,"-extract_language") if $self->{'extract_language'};
124 push(@$specific_options, "-file_rename_method", "none");
125
126 if ($secondary_plugin_name eq "HTMLPlugin") {
127 push(@$specific_options, "-processing_tmp_files");
128 }
129
130 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
131 return $self;
132}
133
134
135sub convert_post_process_old
136{
137 my $self = shift (@_);
138 my ($conv_filename) = @_;
139
140 my $outhandle=$self->{'outhandle'};
141
142 my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
143
144 # read in file ($text will be in utf8)
145 my $text = "";
146 $self->read_file ($conv_filename, $encoding, $language, \$text);
147
148 # turn any high bytes that aren't valid utf-8 into utf-8.
149 #unicode::ensure_utf8(\$text);
150
151 # Write it out again!
152 #$self->utf8_write_file (\$text, $conv_filename);
153}
154
155sub get_default_process_exp {
156 my $self = shift (@_);
157
158 if ($self->{'scripting_ext_working'}) {
159 return q^(?i)\.(xls|xlsx|ods)$^;
160 }
161
162 return q^(?i)\.xls$^;
163}
164
165
1661;
Note: See TracBrowser for help on using the repository browser.