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

Last change on this file since 10580 was 10580, checked in by kjdon, 19 years ago

if created from pluginfo.pl (self->info_only == 1)then don't load up the secondary plugins

  • 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 = (defined $hashArgOptLists)? new ConvertToPlug($pluginlist,$inputargs,$hashArgOptLists): new ConvertToPlug($pluginlist,$inputargs);
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 $self->{'extract_language'} = 1;
115 if (defined $secondary_plugin_options->{'HTMLPlug'}){
116 push(@$html_options,"-input_encoding", "utf8");
117 push(@$html_options,"-extract_language");
118
119 # Instruct HTMLPlug (when eventually accessed through read_into_doc_obj)
120 # to extract these metadata fields from the HEAD META fields
121 push(@$html_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
122 }
123 if (defined $secondary_plugin_options->{'PagedImgPlug'}){
124 push(@$pageimg_options,"-input_encoding", "utf8");
125 push(@$pageimg_options,"-extract_language");
126 }
127 }
128
129 $self = bless $self, $class;
130
131 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
132 return $self;
133}
134
135sub get_default_process_exp {
136 my $self = shift (@_);
137 return q^(?i)\.ppt$^;
138}
139
140sub get_file_type {
141 my $self = shift (@_);
142 my $file_type = "PPT";
143 return $file_type;
144}
145
146sub convert_post_process
147{
148 my $self = shift (@_);
149 my ($conv_filename) = @_;
150
151 my $outhandle=$self->{'outhandle'};
152 my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
153 # read in file ($text will be in utf8)
154 my $text = "";
155 $self->read_file ($conv_filename, $encoding, $language, \$text);
156
157 # turn any high bytes that aren't valid utf-8 into utf-8.
158 unicode::ensure_utf8(\$text);
159 # Write it out again!
160 $self->utf8_write_file (\$text, $conv_filename);
161}
162
163sub process {
164 my $self = shift (@_);
165 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
166
167 return $self->process_type("ppt",$base_dir,$file,$doc_obj);
168}
169
1701;
171
Note: See TracBrowser for help on using the repository browser.