source: gsdl/trunk/perllib/plugins/ExcelPlugin.pm@ 18406

Last change on this file since 18406 was 18406, checked in by ak19, 15 years ago

Modified srcreplaceable plugins (plugins which operate on docs where the source file can be replaced with their converted htmls) to set the file_rename_method to none for secondary plugins (for Text, HTML, and PagedImage plugins) so that the file is not renamed several times.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 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 ConvertBinaryFile;
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33
34sub BEGIN {
35 @ExcelPlugin::ISA = ('ConvertBinaryFile');
36}
37
38my $arguments =
39 [ { 'name' => "process_exp",
40 'desc' => "{BasePlugin.process_exp}",
41 'type' => "regexp",
42 'reqd' => "no",
43 'deft' => &get_default_process_exp() }
44 ];
45
46my $options = { 'name' => "ExcelPlugin",
47 'desc' => "{ExcelPlugin.desc}",
48 'abstract' => "no",
49 'inherits' => "yes",
50 'srcreplaceable' => "yes", # Source docs in Excel format can be replaced with GS-generated html
51 'args' => $arguments };
52
53sub new {
54 my ($class) = shift (@_);
55 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
56 push(@$pluginlist, $class);
57
58 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
59 push(@{$hashArgOptLists->{"OptList"}},$options);
60
61 my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
62
63 if ($self->{'info_only'}) {
64 # don't worry about any options etc
65 return bless $self, $class;
66 }
67
68 $self->{'filename_extension'} = "xls";
69 $self->{'file_type'} = "Excel";
70
71 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
72 if (!defined $secondary_plugin_options->{'HTMLPlugin'}) {
73 $secondary_plugin_options->{'HTMLPlugin'} = [];
74 }
75 if (!defined $secondary_plugin_options->{'TextPlugin'}) {
76 $secondary_plugin_options->{'TextPlugin'} = [];
77 }
78 my $html_options = $secondary_plugin_options->{'HTMLPlugin'};
79 my $text_options = $secondary_plugin_options->{'TextPlugin'};
80
81 push(@$html_options, "-input_encoding", "utf8");
82 push(@$html_options,"-extract_language") if $self->{'extract_language'};
83 push(@$html_options, "-file_rename_method", "none");
84
85 push(@$text_options, "-input_encoding", "utf8");
86 push(@$text_options,"-extract_language") if $self->{'extract_language'};
87 push(@$text_options, "-file_rename_method", "none");
88
89 $self = bless $self, $class;
90
91 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
92 return bless $self;
93}
94
95sub convert_post_process_old
96{
97 my $self = shift (@_);
98 my ($conv_filename) = @_;
99
100 my $outhandle=$self->{'outhandle'};
101
102 my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
103
104 # read in file ($text will be in utf8)
105 my $text = "";
106 $self->read_file ($conv_filename, $encoding, $language, \$text);
107
108 # turn any high bytes that aren't valid utf-8 into utf-8.
109 #unicode::ensure_utf8(\$text);
110
111 # Write it out again!
112 #$self->utf8_write_file (\$text, $conv_filename);
113}
114
115sub get_default_process_exp {
116 my $self = shift (@_);
117 return q^(?i)\.xls$^;
118}
119
120
1211;
Note: See TracBrowser for help on using the repository browser.