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

Last change on this file since 10427 was 10427, checked in by chi, 19 years ago

Modification of the way passing argument and option list for the secondary plugin.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 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 $arguments =
39 [ { 'name' => "process_exp",
40 'desc' => "{BasPlug.process_exp}",
41 'type' => "regexp",
42 'reqd' => "no",
43 'deft' => &get_default_process_exp()}
44 ];
45
46my $options = { 'name' => "PPTPlug",
47 'desc' => "{PPTPlug.desc}",
48 'abstract' => "no",
49 'inherits' => "Yes",
50 'args' => $arguments };
51
52sub new {
53 my ($class) = shift (@_);
54 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
55 push(@$pluginlist, $class);
56
57 if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
58 my $ws_arg = { 'name' => "windows_scripting",
59 'desc' => "PPTPlug.windows_scripting}",
60 'type' => "flag",
61 'reqd' => "no" };
62 push(@$arguments,$ws_arg);
63 }
64
65 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
66 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
67
68
69 my @arg_array = @$inputargs;
70 my $self = (defined $hashArgOptLists)? new ConvertToPlug($pluginlist,$inputargs,$hashArgOptLists): new ConvertToPlug($pluginlist,$inputargs);
71
72 # ppthtml outputs utf-8 already.
73 #these are passed through to gsConvert.pl by ConvertToPlug.pm
74 $self->{'convert_options'} = "-windows_scripting" if $self->{'window_scripting'};
75 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
76
77 if ($self->{'windows_scripting'} && ($self->{'convert_to'} eq "PagedImg")) {
78 $secondary_plugin_options->{'PagedImgPlug'} = [];
79 } else {
80 $secondary_plugin_options->{'HTMLPlug'} = [];
81 }
82 my $html_options = $secondary_plugin_options->{'HTMLPlug'};
83 my $pageimg_options = $secondary_plugin_options->{'PagedImgPlug'};
84
85 if ($self->{'input_encoding'} eq "auto") {
86 $self->{'input_encoding'} = "utf8";
87 $self->{'extract_language'} = 1;
88 if (defined $secondary_plugin_options->{'HTMLPlug'}){
89 push(@$html_options,"-input_encoding", "utf8");
90 push(@$html_options,"-extract_language");
91
92 # Instruct HTMLPlug (when eventually accessed through read_into_doc_obj)
93 # to extract these metadata fields from the HEAD META fields
94 push(@$html_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
95 }
96 if (defined $secondary_plugin_options->{'PagedImgPlug'}){
97 push(@$pageimg_options,"-input_encoding", "utf8");
98 push(@$pageimg_options,"-extract_language");
99 }
100 }
101
102 $self = bless $self, $class;
103
104 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
105 return $self;
106}
107
108sub get_default_process_exp {
109 my $self = shift (@_);
110 return q^(?i)\.ppt$^;
111}
112
113sub get_file_type {
114 my $self = shift (@_);
115 my $file_type = "PPT";
116 return $file_type;
117}
118
119sub convert_post_process
120{
121 my $self = shift (@_);
122 my ($conv_filename) = @_;
123
124 my $outhandle=$self->{'outhandle'};
125 my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
126 # read in file ($text will be in utf8)
127 my $text = "";
128 $self->read_file ($conv_filename, $encoding, $language, \$text);
129
130 # turn any high bytes that aren't valid utf-8 into utf-8.
131 unicode::ensure_utf8(\$text);
132 # Write it out again!
133 $self->utf8_write_file (\$text, $conv_filename);
134}
135
136sub process {
137 my $self = shift (@_);
138 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
139
140 return $self->process_type("ppt",$base_dir,$file,$doc_obj);
141}
142
1431;
144
Note: See TracBrowser for help on using the repository browser.