source: trunk/gsdl/perllib/plugins/WordPlug.pm@ 10279

Last change on this file since 10279 was 10279, 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: 5.8 KB
Line 
1###########################################################################
2#
3# WordPlug.pm -- plugin for importing Microsoft Word documents
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26# 12/05/02 Added usage datastructure - John Thompson
27
28package WordPlug;
29
30use ConvertToPlug;
31require StructuredHTMLPlug;
32use strict;
33no strict 'refs'; # allow filehandles to be variables and viceversa
34
35
36sub BEGIN {
37 @WordPlug::ISA = ('ConvertToPlug','StructuredHTMLPlug');
38}
39
40my $arguments =
41 [ { 'name' => "process_exp",
42 'desc' => "{BasPlug.process_exp}",
43 'type' => "regexp",
44 'deft' => &get_default_process_exp(),
45 'reqd' => "no" },
46 { 'name' => "title_header",
47 'desc' => "{WordPlug.title_header}",
48 'type' => "string" },
49 { 'name' => "check_toc",
50 'desc' => "{WordPlug.check_toc}",
51 'type' => "flag" },
52 { 'name' => "toc_header",
53 'desc' => "{WordPlug.toc_header}",
54 'type' => "string" },
55 { 'name' => "tof_header",
56 'desc' => "{WordPlug.tof_header}",
57 'type' => "string" },
58 { 'name' => "level1_header",
59 'desc' => "{WordPlug.level1_header}",
60 'type' => "string" },
61 { 'name' => "level2_header",
62 'desc' => "{WordPlug.level2_header}",
63 'type' => "string" },
64 { 'name' => "level3_header",
65 'desc' => "{WordPlug.level3_header}",
66 'type' => "string" }];
67
68my $options = { 'name' => "WordPlug",
69 'desc' => "{WordPlug.desc}",
70 'abstract' => "no",
71 'inherits' => "yes",
72 'args' => $arguments };
73
74sub new {
75 my ($class) = shift (@_);
76 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
77 push(@$pluginlist, $class);
78
79 if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
80 my $ws_arg = { 'name' => "windows_scripting",
81 'desc' => "{WordPlug.windows_scripting}",
82 'type' => "flag" };
83 push(@$arguments,$ws_arg);
84 }
85
86 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
87 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
88
89 my $self = (defined $hashArgOptLists)? new ConvertToPlug($pluginlist,$inputargs,$hashArgOptLists): new ConvertToPlug($pluginlist,$inputargs);
90
91 #this is passed through to gsConvert.pl by ConvertToPlug.pm
92 $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'};
93
94 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
95
96 if (!defined $secondary_plugin_options->{'HTMLPlug'}) {
97 $secondary_plugin_options->{'HTMLPlug'} = [];
98 }
99 if (!defined $secondary_plugin_options->{'TEXTPlug'}) {
100 $secondary_plugin_options->{'TEXTPlug'} = [];
101 }
102
103 my $html_options = $secondary_plugin_options->{'HTMLPlug'};
104 my $text_options = $secondary_plugin_options->{'TextPlug'};
105
106 # wvWare will always produce html files encoded as utf-8
107 if ($self->{'input_encoding'} eq "auto") {
108 $self->{'input_encoding'} = "utf8";
109 $self->{'extract_language'} = 1;
110 push(@$html_options,"-input_encoding", "utf8");
111 push(@$html_options,"-extract_language");
112
113 # Instruct HTMLPlug (when eventually accessed through read_into_doc_obj)
114 # to extract these metadata fields from the HEAD META fields
115 push(@$html_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
116 #push(@$html_options , "-title_sub", '^(Page\s+\d+)?(\s*1\s+)?');
117 }
118
119 $self = bless $self, $class;
120
121 $self->load_secondary_plugins($class,$secondary_plugin_options);
122
123 #return bless $self, $class;
124 return bless $self;
125}
126
127sub get_default_process_exp {
128 my $self = shift (@_);
129
130 return q^(?i)\.(doc|dot)$^;
131}
132
133sub convert_post_process
134{
135 my $self = shift (@_);
136 my ($conv_filename) = @_;
137
138 my $outhandle=$self->{'outhandle'};
139
140 my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
141
142 # read in file ($text will be in utf8)
143 my $text = "";
144 $self->read_file ($conv_filename, $encoding, $language, \$text);
145
146 # turn any high bytes that aren't valid utf-8 into utf-8.
147 unicode::ensure_utf8(\$text);
148
149 # Write it out again!
150}
151
152sub get_file_type {
153 my $self = shift (@_);
154 my $file_type = "Word";
155 return $file_type;
156}
157
158# Modified to cache HTML files for efficieny reasons rather
159# than delete all. HTML is modified not to use IE's VML.
160# VML uses WML files, so these can be deleted.
161sub cleanup_tmp_area {
162 my ($self) = @_;
163 if (defined $self->{'files_dir'}) {
164 my $html_files_dir = $self->{'files_dir'};
165
166 if (opendir(DIN,$html_files_dir)) {
167 my @wmz_files = grep( /\.wmz$/, readdir(DIN));
168 foreach my $f (@wmz_files) {
169 my $full_f = &util::filename_cat($html_files_dir,$f);
170 &util::rm($full_f);
171 }
172 closedir(DIN);
173 }
174 else {
175 # if HTML file has no supporting images, then no _files dir made
176 # => do nothing
177 }
178 }
179}
180
181# do plugin specific processing of doc_obj for HTML type
182sub process {
183 my $self = shift (@_);
184 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
185
186 return $self->process_type("doc", $base_dir, $file, $doc_obj);
187}
188
1891;
190
Note: See TracBrowser for help on using the repository browser.