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

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

A modification to allow a secondary plugin setting through ConvertToPlug

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