[1410] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15872] | 3 | # WordPlugin.pm -- plugin for importing Microsoft Word documents
|
---|
[1410] | 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 | ###########################################################################
|
---|
[15872] | 25 | package WordPlugin;
|
---|
[1410] | 26 |
|
---|
[15872] | 27 | use ConvertBinaryFile;
|
---|
[10254] | 28 | use strict;
|
---|
| 29 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[1410] | 30 |
|
---|
| 31 | sub BEGIN {
|
---|
[15872] | 32 | @WordPlugin::ISA = ('ConvertBinaryFile');
|
---|
[1410] | 33 | }
|
---|
| 34 |
|
---|
[4744] | 35 | my $arguments =
|
---|
| 36 | [ { 'name' => "process_exp",
|
---|
[15872] | 37 | 'desc' => "{BasePlugin.process_exp}",
|
---|
[6408] | 38 | 'type' => "regexp",
|
---|
[4744] | 39 | 'deft' => &get_default_process_exp(),
|
---|
[10514] | 40 | 'reqd' => "no" },
|
---|
| 41 | { 'name' => "description_tags",
|
---|
[15872] | 42 | 'desc' => "{HTMLPlugin.description_tags}",
|
---|
[10514] | 43 | 'type' => "flag" }
|
---|
[10355] | 44 | ];
|
---|
[3540] | 45 |
|
---|
[15872] | 46 | my $options = { 'name' => "WordPlugin",
|
---|
| 47 | 'desc' => "{WordPlugin.desc}",
|
---|
[6408] | 48 | 'abstract' => "no",
|
---|
[4744] | 49 | 'inherits' => "yes",
|
---|
[15114] | 50 | 'srcreplaceable' => "yes", # Source docs in Word can be replaced with GS-generated html
|
---|
[4744] | 51 | 'args' => $arguments };
|
---|
[3540] | 52 |
|
---|
[2811] | 53 | sub new {
|
---|
[10218] | 54 | my ($class) = shift (@_);
|
---|
| 55 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 56 | push(@$pluginlist, $class);
|
---|
[3540] | 57 |
|
---|
[10279] | 58 | if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
|
---|
[10405] | 59 | my $ws_arg = [ { 'name' => "windows_scripting",
|
---|
[15872] | 60 | 'desc' => "{WordPlugin.windows_scripting}",
|
---|
[10405] | 61 | 'type' => "flag",
|
---|
| 62 | 'reqd' => "no" },
|
---|
[11884] | 63 | { 'name' => "metadata_fields",
|
---|
[15969] | 64 | 'desc' => "{WordPlugin.metadata_fields}",
|
---|
[11884] | 65 | 'type' => "string",
|
---|
| 66 | 'deft' => "Title" },
|
---|
[10405] | 67 | { 'name' => "level1_header",
|
---|
[15872] | 68 | 'desc' => "{StructuredHTMLPlugin.level1_header}",
|
---|
[10405] | 69 | 'type' => "regexp",
|
---|
| 70 | 'reqd' => "no",
|
---|
| 71 | 'deft' => "" },
|
---|
| 72 | { 'name' => "level2_header",
|
---|
[15872] | 73 | 'desc' => "{StructuredHTMLPlugin.level2_header}",
|
---|
[10405] | 74 | 'type' => "regexp",
|
---|
| 75 | 'reqd' => "no",
|
---|
| 76 | 'deft' => "" },
|
---|
| 77 | { 'name' => "level3_header",
|
---|
[15872] | 78 | 'desc' => "{StructuredHTMLPlugin.level3_header}",
|
---|
[10405] | 79 | 'type' => "regexp",
|
---|
| 80 | 'reqd' => "no",
|
---|
| 81 | 'deft' => "" },
|
---|
| 82 | { 'name' => "title_header",
|
---|
[15872] | 83 | 'desc' => "{StructuredHTMLPlugin.title_header}",
|
---|
[10405] | 84 | 'type' => "regexp",
|
---|
| 85 | 'reqd' => "no",
|
---|
| 86 | 'deft' => "" },
|
---|
[11884] | 87 | { 'name' => "delete_toc",
|
---|
[15872] | 88 | 'desc' => "{StructuredHTMLPlugin.delete_toc}",
|
---|
[11884] | 89 | 'type' => "flag",
|
---|
[18591] | 90 | 'reqd' => "no" },
|
---|
[10405] | 91 | { 'name' => "toc_header",
|
---|
[15872] | 92 | 'desc' => "{StructuredHTMLPlugin.toc_header}",
|
---|
[10405] | 93 | 'type' => "regexp",
|
---|
| 94 | 'reqd' => "no",
|
---|
[11884] | 95 | 'deft' => "" }
|
---|
| 96 | ];
|
---|
[10405] | 97 |
|
---|
| 98 | push(@$arguments,@$ws_arg);
|
---|
[10279] | 99 | }
|
---|
| 100 |
|
---|
[15872] | 101 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 102 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[10441] | 103 |
|
---|
[15872] | 104 | my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[10218] | 105 |
|
---|
[10580] | 106 | if ($self->{'info_only'}) {
|
---|
| 107 | # don't worry about any options etc
|
---|
| 108 | return bless $self, $class;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[15872] | 111 | $self->{'filename_extension'} = "doc";
|
---|
| 112 | $self->{'file_type'} = "Word";
|
---|
| 113 |
|
---|
| 114 | #this is passed through to gsConvert.pl by ConvertBinaryFile.pm
|
---|
[10279] | 115 | $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'};
|
---|
[10405] | 116 |
|
---|
[12834] | 117 | # we always save as utf-8
|
---|
[15902] | 118 | # if ($self->{'input_encoding'} eq "auto") {
|
---|
| 119 | # $self->{'input_encoding'} = "utf8";
|
---|
| 120 | # }
|
---|
[12834] | 121 |
|
---|
[10279] | 122 | my $secondary_plugin_options = $self->{'secondary_plugin_options'};
|
---|
[10405] | 123 | if (defined $self->{'windows_scripting'}) {
|
---|
[15872] | 124 | if (!defined $secondary_plugin_options->{'StructuredHTMLPlugin'}){
|
---|
| 125 | $secondary_plugin_options->{'StructuredHTMLPlugin'} = [];
|
---|
| 126 | my $structhtml_options = $secondary_plugin_options->{'StructuredHTMLPlugin'};
|
---|
[12834] | 127 |
|
---|
[15872] | 128 | # Instruct HTMLPlugin (when eventually accessed through read_into_doc_obj)
|
---|
[10441] | 129 | # to extract these metadata fields from the HEAD META fields
|
---|
[18406] | 130 | push (@$structhtml_options, "-metadata_fields","Title,GENERATOR,date,author<Creator>");
|
---|
| 131 | push (@$structhtml_options, "-title_sub", '^(Page\s+\d+)?(\s*1\s+)?');
|
---|
[10441] | 132 | push (@$structhtml_options, "-description_tags") if $self->{'windows_scripting'};
|
---|
[18406] | 133 | push (@$structhtml_options, "-extract_language") if $self->{'extract_language'};
|
---|
[10496] | 134 | push (@$structhtml_options, "-delete_toc") if $self->{'delete_toc'};
|
---|
[10441] | 135 | push (@$structhtml_options, "-toc_header", $self->{'toc_header'}) if $self->{'toc_header'};
|
---|
| 136 | push (@$structhtml_options, "-title_header", $self->{'title_header'}) if $self->{'title_header'};
|
---|
| 137 | push (@$structhtml_options, "-level1_header", $self->{'level1_header'}) if $self->{'level1_header'};
|
---|
| 138 | push (@$structhtml_options, "-level2_header", $self->{'level2_header'})if $self->{'level2_header'};
|
---|
| 139 | push (@$structhtml_options, "-level3_header", $self->{'level3_header'}) if $self->{'level3_header'};
|
---|
[10723] | 140 | push (@$structhtml_options, "-metadata_fields", $self->{'metadata_fields'}) if $self->{'metadata_fields'};
|
---|
[10405] | 141 | }
|
---|
| 142 | }
|
---|
[15872] | 143 | if (!defined $secondary_plugin_options->{'HTMLPlugin'}) {
|
---|
| 144 | $secondary_plugin_options->{'HTMLPlugin'} = [];
|
---|
[10279] | 145 | }
|
---|
[15872] | 146 | if (!defined $secondary_plugin_options->{'TextPlugin'}) {
|
---|
| 147 | $secondary_plugin_options->{'TextPlugin'} = [];
|
---|
[10279] | 148 | }
|
---|
| 149 |
|
---|
[15872] | 150 | my $html_options = $secondary_plugin_options->{'HTMLPlugin'};
|
---|
| 151 | my $text_options = $secondary_plugin_options->{'TextPlugin'};
|
---|
| 152 | my $structhtml_options = $secondary_plugin_options->{'StructuredHTMLPlugin'};
|
---|
| 153 | # wvWare will always produce html files encoded as utf-8, so make sure the secondary HTMLPlugin knows this
|
---|
[10769] | 154 | push(@$html_options,"-input_encoding", "utf8");
|
---|
[12834] | 155 | push(@$html_options,"-extract_language") if $self->{'extract_language'};
|
---|
| 156 | push(@$html_options, "-description_tags") if $self->{'description_tags'};
|
---|
[11122] | 157 |
|
---|
[15872] | 158 | # Instruct HTMLPlugin (when eventually accessed through read_into_doc_obj)
|
---|
[10441] | 159 | # to extract these metadata fields from the HEAD META fields
|
---|
| 160 | push(@$html_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
|
---|
| 161 | push(@$html_options , "-title_sub", '^(Page\s+\d+)?(\s*1\s+)?');
|
---|
[11122] | 162 |
|
---|
| 163 | my $associate_tail_re = $self->{'associate_tail_re'};
|
---|
| 164 | if ((defined $associate_tail_re) && ($associate_tail_re ne "")) {
|
---|
| 165 | push(@$html_options, "-associate_tail_re", $associate_tail_re);
|
---|
| 166 | push(@$text_options, "-associate_tail_re", $associate_tail_re);
|
---|
[18406] | 167 | push(@$structhtml_options, "-associate_tail_re", $associate_tail_re) if defined $structhtml_options;
|
---|
[11122] | 168 | }
|
---|
[18406] | 169 |
|
---|
| 170 | push(@$html_options, "-file_rename_method", "none");
|
---|
| 171 | push(@$text_options, "-file_rename_method", "none");
|
---|
| 172 | push(@$structhtml_options, "-file_rename_method", "none") if defined $structhtml_options;
|
---|
| 173 |
|
---|
[10279] | 174 | $self = bless $self, $class;
|
---|
[10428] | 175 | $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
|
---|
[2811] | 176 |
|
---|
[10279] | 177 | return bless $self;
|
---|
[2811] | 178 | }
|
---|
| 179 |
|
---|
[1410] | 180 | sub get_default_process_exp {
|
---|
| 181 | my $self = shift (@_);
|
---|
| 182 |
|
---|
[3400] | 183 | return q^(?i)\.(doc|dot)$^;
|
---|
[1410] | 184 | }
|
---|
| 185 |
|
---|
[15872] | 186 | sub convert_post_process_old
|
---|
[10279] | 187 | {
|
---|
[1410] | 188 | my $self = shift (@_);
|
---|
[10279] | 189 | my ($conv_filename) = @_;
|
---|
[2515] | 190 |
|
---|
[10279] | 191 | my $outhandle=$self->{'outhandle'};
|
---|
[10441] | 192 |
|
---|
[10279] | 193 | my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
|
---|
| 194 |
|
---|
| 195 | # read in file ($text will be in utf8)
|
---|
| 196 | my $text = "";
|
---|
| 197 | $self->read_file ($conv_filename, $encoding, $language, \$text);
|
---|
| 198 |
|
---|
| 199 | # turn any high bytes that aren't valid utf-8 into utf-8.
|
---|
[10441] | 200 | #unicode::ensure_utf8(\$text);
|
---|
| 201 |
|
---|
[10279] | 202 | # Write it out again!
|
---|
[10441] | 203 | #$self->utf8_write_file (\$text, $conv_filename);
|
---|
[1410] | 204 | }
|
---|
| 205 |
|
---|
[10279] | 206 | # Modified to cache HTML files for efficieny reasons rather
|
---|
| 207 | # than delete all. HTML is modified not to use IE's VML.
|
---|
| 208 | # VML uses WML files, so these can be deleted.
|
---|
| 209 | sub cleanup_tmp_area {
|
---|
| 210 | my ($self) = @_;
|
---|
| 211 | if (defined $self->{'files_dir'}) {
|
---|
| 212 | my $html_files_dir = $self->{'files_dir'};
|
---|
| 213 |
|
---|
| 214 | if (opendir(DIN,$html_files_dir)) {
|
---|
| 215 | my @wmz_files = grep( /\.wmz$/, readdir(DIN));
|
---|
| 216 | foreach my $f (@wmz_files) {
|
---|
| 217 | my $full_f = &util::filename_cat($html_files_dir,$f);
|
---|
| 218 | &util::rm($full_f);
|
---|
| 219 | }
|
---|
| 220 | closedir(DIN);
|
---|
| 221 | }
|
---|
| 222 | else {
|
---|
| 223 | # if HTML file has no supporting images, then no _files dir made
|
---|
| 224 | # => do nothing
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[10441] | 229 |
|
---|
[1410] | 230 | 1;
|
---|
[10279] | 231 |
|
---|