source: trunk/gsdl/perllib/plugins/PPTPlug.pm@ 12834

Last change on this file since 12834 was 12834, checked in by kjdon, 18 years ago

these convertto plugins were all setting extract_language=1 to their secondary plugins. we don't want this - only pass to secondary plugin if user has asked for it. textcat can be very slow, so don't want to run it unless we have to

  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1###########################################################################
2#
3# PPTPlug.pm -- plugin for importing Microsoft PowerPoint 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 PPTPlug;
29
30use ConvertToPlug;
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33
34sub BEGIN {
35 @PPTPlug::ISA = ('ConvertToPlug');
36}
37
38my $convert_to_list =
39 [ { 'name' => "auto",
40 'desc' => "{ConvertToPlug.convert_to.auto}" },
41 { 'name' => "html",
42 'desc' => "{ConvertToPlug.convert_to.html}" },
43 { 'name' => "text",
44 'desc' => "{ConvertToPlug.convert_to.text}" },
45 { 'name' => "pagedimg_jpg",
46 'desc' => "{ConvertToPlug.convert_to.pagedimg_jpg}" },
47 { 'name' => "pagedimg_gif",
48 'desc' => "{ConvertToPlug.convert_to.pagedimg_gif}" },
49 { 'name' => "pagedimg_png",
50 'desc' => "{ConvertToPlug.convert_to.pagedimg_png}" }
51 ];
52
53my $arguments =
54 [ { 'name' => "process_exp",
55 'desc' => "{BasPlug.process_exp}",
56 'type' => "regexp",
57 'reqd' => "no",
58 'deft' => &get_default_process_exp()}
59 ];
60
61my $options = { 'name' => "PPTPlug",
62 'desc' => "{PPTPlug.desc}",
63 'abstract' => "no",
64 'inherits' => "yes",
65 'args' => $arguments };
66
67sub new {
68 my ($class) = shift (@_);
69 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
70 push(@$pluginlist, $class);
71
72 if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
73 my $ws_arg =[{ 'name' => "convert_to",
74 'desc' => "{ConvertToPlug.convert_to}",
75 'type' => "enum",
76 'reqd' => "yes",
77 'list' => $convert_to_list,
78 'deft' => "html" },
79 { 'name' => "windows_scripting",
80 'desc' => "{PPTPlug.windows_scripting}",
81 'type' => "flag",
82 'reqd' => "no" }
83 ];
84 push(@$arguments,@$ws_arg);
85 }
86
87 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
88 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
89
90
91 my @arg_array = @$inputargs;
92 my $self = new ConvertToPlug($pluginlist, $inputargs, $hashArgOptLists);
93
94 if ($self->{'info_only'}) {
95 # don't worry about any options etc
96 return bless $self, $class;
97 }
98
99 # ppthtml outputs utf-8 already.
100 #these are passed through to gsConvert.pl by ConvertToPlug.pm
101 $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'};
102 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
103
104 if ($self->{'windows_scripting'} && ($self->{'convert_to'} eq "PagedImg")) {
105 $secondary_plugin_options->{'PagedImgPlug'} = [];
106 } else {
107 $secondary_plugin_options->{'HTMLPlug'} = [];
108 }
109 my $html_options = $secondary_plugin_options->{'HTMLPlug'};
110 my $pageimg_options = $secondary_plugin_options->{'PagedImgPlug'};
111
112 if ($self->{'input_encoding'} eq "auto") {
113 $self->{'input_encoding'} = "utf8";
114 if (defined $secondary_plugin_options->{'HTMLPlug'}){
115 push(@$html_options,"-input_encoding", "utf8");
116 push(@$html_options,"-extract_language") if $self->{'extract_language'};
117
118 # Instruct HTMLPlug (when eventually accessed through read_into_doc_obj)
119 # to extract these metadata fields from the HEAD META fields
120 push(@$html_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
121 }
122 if (defined $secondary_plugin_options->{'PagedImgPlug'}){
123 push(@$pageimg_options,"-input_encoding", "utf8");
124 push(@$pageimg_options,"-extract_language") if $self->{'extract_language'};
125 }
126 }
127
128 $self = bless $self, $class;
129
130 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
131 return $self;
132}
133
134sub get_default_process_exp {
135 my $self = shift (@_);
136 return q^(?i)\.ppt$^;
137}
138
139sub get_file_type {
140 my $self = shift (@_);
141 my $file_type = "PPT";
142 return $file_type;
143}
144
145sub convert_post_process
146{
147 my $self = shift (@_);
148 my ($conv_filename) = @_;
149
150 my $outhandle=$self->{'outhandle'};
151 my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
152 # read in file ($text will be in utf8)
153 my $text = "";
154 $self->read_file ($conv_filename, $encoding, $language, \$text);
155
156 # turn any high bytes that aren't valid utf-8 into utf-8.
157 unicode::ensure_utf8(\$text);
158 # Write it out again!
159 $self->utf8_write_file (\$text, $conv_filename);
160}
161
162sub process {
163 my $self = shift (@_);
164 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
165
166 return $self->process_type("ppt",$base_dir,$file,$doc_obj);
167}
168
1691;
170
Note: See TracBrowser for help on using the repository browser.