[10450] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15906] | 3 | # ConvertBinaryFile.pm -- plugin that facilitates conversion of binary files
|
---|
| 4 | # through gsConvert.pl
|
---|
[10450] | 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) 1999 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 |
|
---|
[17723] | 28 | # This plugin is inherited by such plugins as WordPlugin, PowerPointPlugin,
|
---|
[17726] | 29 | # PostScriptPlugin,
|
---|
[17723] | 30 | # RTFPlugin and PDFPlugin. It facilitates the conversion of these document types
|
---|
[15871] | 31 | # to either HTML, Text or a series of images. It works by dynamically loading
|
---|
[12741] | 32 | # an appropriate secondary plugin (HTMLPlug, StructuredHTMLPlug,
|
---|
[15871] | 33 | # PagedImagePlugin or TextPlugin) based on the plugin argument 'convert_to'.
|
---|
[12741] | 34 |
|
---|
[15871] | 35 | package ConvertBinaryFile;
|
---|
[10450] | 36 |
|
---|
[15906] | 37 | use AutoExtractMetadata;
|
---|
[10450] | 38 | use ghtml;
|
---|
[15871] | 39 | use HTMLPlugin;
|
---|
| 40 | use TextPlugin;
|
---|
| 41 | use PagedImagePlugin;
|
---|
[10450] | 42 |
|
---|
[10453] | 43 | use strict;
|
---|
| 44 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[11680] | 45 | no strict 'subs';
|
---|
[15871] | 46 |
|
---|
[10450] | 47 | sub BEGIN {
|
---|
[15906] | 48 | @ConvertBinaryFile::ISA = ('AutoExtractMetadata');
|
---|
[10450] | 49 | }
|
---|
| 50 |
|
---|
| 51 | my $convert_to_list =
|
---|
| 52 | [ { 'name' => "auto",
|
---|
[15871] | 53 | 'desc' => "{ConvertBinaryFile.convert_to.auto}" },
|
---|
[10450] | 54 | { 'name' => "html",
|
---|
[15871] | 55 | 'desc' => "{ConvertBinaryFile.convert_to.html}" },
|
---|
[10450] | 56 | { 'name' => "text",
|
---|
[15871] | 57 | 'desc' => "{ConvertBinaryFile.convert_to.text}" }
|
---|
[10450] | 58 | ];
|
---|
| 59 |
|
---|
| 60 | my $arguments =
|
---|
| 61 | [ { 'name' => "convert_to",
|
---|
[15871] | 62 | 'desc' => "{ConvertBinaryFile.convert_to}",
|
---|
[10450] | 63 | 'type' => "enum",
|
---|
| 64 | 'reqd' => "yes",
|
---|
| 65 | 'list' => $convert_to_list,
|
---|
[10890] | 66 | 'deft' => "auto" },
|
---|
[12961] | 67 | { 'name' => "keep_original_filename",
|
---|
[15871] | 68 | 'desc' => "{ConvertBinaryFile.keep_original_filename}",
|
---|
[12961] | 69 | 'type' => "flag" },
|
---|
[10450] | 70 | { 'name' => "title_sub",
|
---|
[16013] | 71 | 'desc' => "{HTMLPlugin.title_sub}",
|
---|
[10450] | 72 | 'type' => "string",
|
---|
| 73 | #'type' => "regexp",
|
---|
| 74 | 'deft' => "" },
|
---|
[11008] | 75 | { 'name' => "apply_fribidi",
|
---|
[15871] | 76 | 'desc' => "{ConvertBinaryFile.apply_fribidi}",
|
---|
[11008] | 77 | 'type' => "flag",
|
---|
| 78 | 'reqd' => "no" },
|
---|
[10450] | 79 | { 'name' => "use_strings",
|
---|
[15871] | 80 | 'desc' => "{ConvertBinaryFile.use_strings}",
|
---|
[10450] | 81 | 'type' => "flag",
|
---|
| 82 | 'reqd' => "no" },
|
---|
[15871] | 83 | ];
|
---|
[10450] | 84 |
|
---|
[15871] | 85 | my $options = { 'name' => "ConvertBinaryFile",
|
---|
| 86 | 'desc' => "{ConvertBinaryFile.desc}",
|
---|
[10450] | 87 | 'abstract' => "yes",
|
---|
| 88 | 'inherits' => "yes",
|
---|
| 89 | 'args' => $arguments };
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | sub load_secondary_plugins
|
---|
| 93 | {
|
---|
| 94 | my $self = shift (@_);
|
---|
| 95 | my ($class,$input_args,$hashArgOptLists) = @_;
|
---|
| 96 |
|
---|
[22597] | 97 | my @convert_to_list = split(",",$self->{'convert_to_plugin'});
|
---|
[10453] | 98 | my $secondary_plugins = {};
|
---|
[11680] | 99 | # find the plugin
|
---|
[10450] | 100 |
|
---|
| 101 | foreach my $convert_to (@convert_to_list) {
|
---|
| 102 | # load in "convert_to" plugin package
|
---|
[22597] | 103 | my $plugin_class = $convert_to;
|
---|
[10450] | 104 | my $plugin_package = $plugin_class.".pm";
|
---|
| 105 |
|
---|
[15116] | 106 | my $colplugname = undef;
|
---|
| 107 | if (defined $ENV{'GSDLCOLLECTDIR'}) {
|
---|
| 108 | $colplugname = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},
|
---|
| 109 | "perllib","plugins",
|
---|
| 110 | $plugin_package);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[11680] | 113 | my $mainplugname = &util::filename_cat($ENV{'GSDLHOME'},
|
---|
[15116] | 114 | "perllib","plugins",
|
---|
[11680] | 115 | $plugin_package);
|
---|
[10450] | 116 |
|
---|
[15116] | 117 | if ((defined $colplugname) && (-e $colplugname)) { require $colplugname;}
|
---|
[11680] | 118 | elsif (-e $mainplugname) { require $mainplugname; }
|
---|
| 119 | else {
|
---|
| 120 | &gsprintf(STDERR, "{plugin.could_not_find_plugin}\n",
|
---|
| 121 | $plugin_class);
|
---|
| 122 | die "\n";
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[10450] | 125 | # call its constructor with extra options that we've worked out!
|
---|
| 126 | my $arglist = $input_args->{$plugin_class};
|
---|
[11680] | 127 |
|
---|
| 128 | my ($secondary_plugin);
|
---|
| 129 | eval("\$secondary_plugin = new $plugin_class([],\$arglist)");
|
---|
| 130 | die "$@" if $@;
|
---|
[10450] | 131 | $secondary_plugins->{$plugin_class} = $secondary_plugin;
|
---|
| 132 | }
|
---|
| 133 | $self->{'secondary_plugins'} = $secondary_plugins;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | sub new {
|
---|
| 137 | my ($class) = shift (@_);
|
---|
| 138 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 139 | push(@$pluginlist, $class);
|
---|
| 140 | my $classPluginName = (defined $pluginlist->[0]) ? $pluginlist->[0] : $class;
|
---|
[15871] | 141 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 142 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[10450] | 143 |
|
---|
[15906] | 144 | my $self = new AutoExtractMetadata($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[22597] | 145 |
|
---|
| 146 | return bless $self, $class;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | # should be called by subclasses after checking and setting
|
---|
| 150 | # $self->{'convert_to'}
|
---|
| 151 | sub set_standard_convert_settings {
|
---|
| 152 | my $self =shift (@_);
|
---|
[10453] | 153 |
|
---|
[22597] | 154 | my $convert_to = $self->{'convert_to'};
|
---|
| 155 | if ($convert_to eq "auto") {
|
---|
| 156 | $convert_to = "html";
|
---|
| 157 | $self->{'convert_to'} = "html";
|
---|
[11680] | 158 | }
|
---|
| 159 |
|
---|
[22597] | 160 | if ($convert_to eq "html") {
|
---|
| 161 | $self->{'convert_to_plugin'} = "HTMLPlugin";
|
---|
[10450] | 162 | $self->{'convert_to_ext'} = "html";
|
---|
[22597] | 163 | } elsif ($convert_to eq "text") {
|
---|
| 164 | $self->{'convert_to_plugin'} = "TextPlugin";
|
---|
[10450] | 165 | $self->{'convert_to_ext'} = "txt";
|
---|
[22597] | 166 | } elsif ($convert_to eq "structuredhtml") {
|
---|
| 167 | $self->{'convert_to_plugin'} = "StructuredHTMLPlugin";
|
---|
[10453] | 168 | $self->{'convert_to_ext'} = "html";
|
---|
[22597] | 169 | } elsif ($convert_to =~ /^pagedimg/) {
|
---|
| 170 | $self->{'convert_to_plugin'} = "PagedImagePlugin";
|
---|
| 171 | my ($convert_to_ext) = $convert_to =~ /pagedimg\_(jpg|gif|png)/i;
|
---|
[10453] | 172 | $convert_to_ext = 'jpg' unless defined $convert_to_ext;
|
---|
| 173 | $self->{'convert_to_ext'} = $convert_to_ext;
|
---|
[10450] | 174 | }
|
---|
[22597] | 175 |
|
---|
[10450] | 176 | }
|
---|
| 177 | sub init {
|
---|
| 178 | my $self = shift (@_);
|
---|
| 179 | my ($verbosity, $outhandle, $failhandle) = @_;
|
---|
| 180 |
|
---|
| 181 | $self->SUPER::init($verbosity,$outhandle,$failhandle);
|
---|
| 182 |
|
---|
| 183 | my $secondary_plugins = $self->{'secondary_plugins'};
|
---|
| 184 |
|
---|
| 185 | foreach my $plug_name (keys %$secondary_plugins) {
|
---|
| 186 | my $plugin = $secondary_plugins->{$plug_name};
|
---|
| 187 | $plugin->init($verbosity,$outhandle,$failhandle);
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | sub deinit {
|
---|
| 192 | # called only once, after all plugin passes have been done
|
---|
| 193 |
|
---|
| 194 | my ($self) = @_;
|
---|
| 195 |
|
---|
| 196 | my $secondary_plugins = $self->{'secondary_plugins'};
|
---|
| 197 |
|
---|
| 198 | foreach my $plug_name (keys %$secondary_plugins) {
|
---|
| 199 | my $plugin = $secondary_plugins->{$plug_name};
|
---|
| 200 | $plugin->deinit();
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | sub convert_post_process
|
---|
| 205 | {
|
---|
| 206 | # by default do no post processing
|
---|
| 207 | return;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 |
|
---|
| 211 | # Run conversion utility on the input file.
|
---|
| 212 | #
|
---|
| 213 | # The conversion takes place in a collection specific 'tmp' directory so
|
---|
| 214 | # that we don't accidentally damage the input.
|
---|
| 215 | #
|
---|
| 216 | # The desired output type is indicated by $output_ext. This is usually
|
---|
| 217 | # something like "html" or "word", but can be "best" (or the empty string)
|
---|
| 218 | # to indicate that the conversion utility should do the best it can.
|
---|
| 219 | sub tmp_area_convert_file {
|
---|
| 220 | my $self = shift (@_);
|
---|
| 221 | my ($output_ext, $input_filename, $textref) = @_;
|
---|
| 222 |
|
---|
| 223 | my $outhandle = $self->{'outhandle'};
|
---|
| 224 | my $convert_to = $self->{'convert_to'};
|
---|
| 225 | my $failhandle = $self->{'failhandle'};
|
---|
| 226 | my $convert_to_ext = $self->{'convert_to_ext'};
|
---|
| 227 |
|
---|
| 228 | # derive tmp filename from input filename
|
---|
| 229 | my ($tailname, $dirname, $suffix)
|
---|
| 230 | = &File::Basename::fileparse($input_filename, "\\.[^\\.]+\$");
|
---|
| 231 |
|
---|
[15116] | 232 | # softlink to collection tmp dir
|
---|
| 233 | my $tmp_dirname = $dirname;
|
---|
| 234 | if(defined $ENV{'GSDLCOLLECTDIR'}) {
|
---|
| 235 | $tmp_dirname = $ENV{'GSDLCOLLECTDIR'};
|
---|
| 236 | } elsif(defined $ENV{'GSDLHOME'}) {
|
---|
| 237 | $tmp_dirname = $ENV{'GSDLHOME'};
|
---|
| 238 | }
|
---|
[21981] | 239 |
|
---|
[15116] | 240 | $tmp_dirname = &util::filename_cat($tmp_dirname, "tmp");
|
---|
| 241 | &util::mk_dir($tmp_dirname) if (!-e $tmp_dirname);
|
---|
[21981] | 242 |
|
---|
| 243 | # add the timestamp into the path otherwise we can run into problems
|
---|
| 244 | # if documents have the same name
|
---|
| 245 | my $timestamp = time;
|
---|
| 246 | my $time_tmp_dirname = &util::filename_cat($tmp_dirname, $timestamp);
|
---|
| 247 | $tmp_dirname = $time_tmp_dirname;
|
---|
| 248 | my $i = 1;
|
---|
| 249 | while (-e $tmp_dirname) {
|
---|
| 250 | $tmp_dirname = "$time_tmp_dirname$i";
|
---|
| 251 | $i++;
|
---|
| 252 | }
|
---|
| 253 | &util::mk_dir($tmp_dirname);
|
---|
| 254 |
|
---|
[15151] | 255 | # The following is not necessary and will cause problems with
|
---|
| 256 | # replacing_srcdoc_with_html in the GSDLremote case:
|
---|
[10450] | 257 | # Remove any white space from filename -- no risk of name collision, and
|
---|
| 258 | # makes later conversion by utils simpler. Leave spaces in path...
|
---|
| 259 | # tidy up the filename with space, dot, hyphen between
|
---|
[15151] | 260 | #$tailname =~ s/\s+//g;
|
---|
| 261 | #$tailname =~ s/\.+//g;
|
---|
| 262 | #$tailname =~ s/\-+//g;
|
---|
[12688] | 263 |
|
---|
[16888] | 264 | # convert to utf-8 otherwise we have problems with the doc.xml file later on
|
---|
| 265 | # print STDERR "**** filename $tailname$suffix is already UTF8\n" if &unicode::check_is_utf8($tailname);
|
---|
[16580] | 266 | $tailname = $self->SUPER::filepath_to_utf8($tailname) unless &unicode::check_is_utf8($tailname);
|
---|
[12688] | 267 |
|
---|
[16888] | 268 | # URLEncode this since htmls with images where the html filename is utf8 don't seem
|
---|
| 269 | # to work on Windows (IE or Firefox), as browsers are looking for filesystem-encoded
|
---|
| 270 | # files on the filesystem.
|
---|
[18339] | 271 | $tailname = &util::rename_file($tailname, $self->{'file_rename_method'}, "without_suffix");
|
---|
[16888] | 272 |
|
---|
[10450] | 273 | $suffix = lc($suffix);
|
---|
| 274 | my $tmp_filename = &util::filename_cat($tmp_dirname, "$tailname$suffix");
|
---|
[15166] | 275 |
|
---|
| 276 | # If gsdl is remote, we're given relative path to input file, of the form import/tailname.suffix
|
---|
| 277 | # But we can't softlink to relative paths. Therefore, we need to ensure that
|
---|
| 278 | # the input_filename is the absolute path, see http://perldoc.perl.org/File/Spec.html
|
---|
| 279 | my $ensure_path_absolute = 1; # true
|
---|
| 280 | &util::soft_link($input_filename, $tmp_filename, $ensure_path_absolute);
|
---|
[10450] | 281 | my $verbosity = $self->{'verbosity'};
|
---|
| 282 | if ($verbosity > 0) {
|
---|
| 283 | print $outhandle "Converting $tailname$suffix to $convert_to format\n";
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | my $errlog = &util::filename_cat($tmp_dirname, "err.log");
|
---|
| 287 |
|
---|
| 288 | # Execute the conversion command and get the type of the result,
|
---|
| 289 | # making sure the converter gives us the appropriate output type
|
---|
[22597] | 290 | my $output_type=$self->{'convert_to'};
|
---|
| 291 | # if ($convert_to =~ m/PagedImage/i) {
|
---|
| 292 | # $output_type = lc($convert_to)."_".lc($convert_to_ext);
|
---|
| 293 | # } else {
|
---|
| 294 | # $output_type = lc($convert_to);
|
---|
| 295 | # }
|
---|
[10450] | 296 |
|
---|
| 297 | my $cmd = "perl -S gsConvert.pl -verbose $verbosity ";
|
---|
| 298 | if (defined $self->{'convert_options'}) {
|
---|
| 299 | $cmd .= $self->{'convert_options'} . " ";
|
---|
| 300 | }
|
---|
| 301 | if ($self->{'use_strings'}) {
|
---|
| 302 | $cmd .= "-use_strings ";
|
---|
| 303 | }
|
---|
| 304 | $cmd .= "-errlog \"$errlog\" -output $output_type \"$tmp_filename\"";
|
---|
[22597] | 305 | print STDERR "calling cmd $cmd\n";
|
---|
[10450] | 306 | $output_type = `$cmd`;
|
---|
| 307 |
|
---|
| 308 | # remove symbolic link to original file
|
---|
| 309 | &util::rm($tmp_filename);
|
---|
[15116] | 310 |
|
---|
[10450] | 311 | # Check STDERR here
|
---|
| 312 | chomp $output_type;
|
---|
| 313 | if ($output_type eq "fail") {
|
---|
| 314 | print $outhandle "Could not convert $tailname$suffix to $convert_to format\n";
|
---|
| 315 | print $failhandle "$tailname$suffix: " . ref($self) . " failed to convert to $convert_to\n";
|
---|
[10994] | 316 | # The following meant that if a conversion failed, the document would be counted twice - do we need it for anything?
|
---|
| 317 | #$self->{'num_not_processed'} ++;
|
---|
[10450] | 318 | if (-s "$errlog") {
|
---|
| 319 | open(ERRLOG, "$errlog");
|
---|
| 320 | while (<ERRLOG>) {
|
---|
| 321 | print $outhandle "$_";
|
---|
| 322 | }
|
---|
| 323 | print $outhandle "\n";
|
---|
| 324 | close ERRLOG;
|
---|
| 325 | }
|
---|
| 326 | &util::rm("$errlog") if (-e "$errlog");
|
---|
| 327 | return "";
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | # store the *actual* output type and return the output filename
|
---|
| 331 | # it's possible we requested conversion to html, but only to text succeeded
|
---|
| 332 | #$self->{'convert_to_ext'} = $output_type;
|
---|
| 333 | if ($output_type =~ /html/i) {
|
---|
| 334 | $self->{'converted_to'} = "HTML";
|
---|
| 335 | } elsif ($output_type =~ /te?xt/i) {
|
---|
[15871] | 336 | $self->{'converted_to'} = "Text";
|
---|
[10450] | 337 | } elsif ($output_type =~ /item/i){
|
---|
[15871] | 338 | $self->{'converted_to'} = "PagedImage";
|
---|
[10450] | 339 | }
|
---|
| 340 |
|
---|
| 341 | my $output_filename = $tmp_filename;
|
---|
| 342 | if ($output_type =~ /item/i) {
|
---|
| 343 | # running under windows
|
---|
| 344 | if ($ENV{'GSDLOS'} =~ /^windows$/i) {
|
---|
| 345 | $output_filename = $tmp_dirname . "\\$tailname\\" . $tailname . ".$output_type";
|
---|
| 346 | } else {
|
---|
| 347 | $output_filename = $tmp_dirname . "\/$tailname\/" . $tailname . ".$output_type";
|
---|
| 348 | }
|
---|
| 349 | } else {
|
---|
| 350 | $output_filename =~ s/$suffix$/.$output_type/;
|
---|
| 351 | }
|
---|
[12688] | 352 |
|
---|
[10450] | 353 | return $output_filename;
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 |
|
---|
[15871] | 357 | # Override BasPlug read_into_doc_obj - we need to call secondary plugin stuff
|
---|
| 358 | sub read_into_doc_obj {
|
---|
[10450] | 359 | my $self = shift (@_);
|
---|
[16392] | 360 | my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
|
---|
[10450] | 361 |
|
---|
| 362 | my $outhandle = $self->{'outhandle'};
|
---|
[15871] | 363 |
|
---|
[16392] | 364 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
[15871] | 365 |
|
---|
[10450] | 366 | my $output_ext = $self->{'convert_to_ext'};
|
---|
| 367 | my $conv_filename = "";
|
---|
[15871] | 368 | $conv_filename = $self->tmp_area_convert_file($output_ext, $filename_full_path);
|
---|
[16580] | 369 |
|
---|
[10609] | 370 | if ("$conv_filename" eq "") {return -1;} # had an error, will be passed down pipeline
|
---|
| 371 | if (! -e "$conv_filename") {return -1;}
|
---|
[10450] | 372 | $self->{'conv_filename'} = $conv_filename;
|
---|
| 373 | $self->convert_post_process($conv_filename);
|
---|
[11008] | 374 |
|
---|
| 375 | # Run the "fribidi" (http://fribidi.org) Unicode Bidirectional Algorithm program over the converted file
|
---|
| 376 | # Added for fixing up Persian PDFs after being processed by pdftohtml, but may be useful in other cases too
|
---|
[15871] | 377 | if ($self->{'apply_fribidi'} && $self->{'converted_to'} =~ /(HTML|Text)/) {
|
---|
[11008] | 378 | my $fribidi_command = "fribidi \"$conv_filename\" >\"${conv_filename}.tmp\"";
|
---|
| 379 | if (system($fribidi_command) != 0) {
|
---|
| 380 | print STDERR "ERROR: Cannot run fribidi on \"$conv_filename\".\n";
|
---|
| 381 | }
|
---|
| 382 | else {
|
---|
| 383 | &util::mv("${conv_filename}.tmp", $conv_filename);
|
---|
| 384 | }
|
---|
| 385 | }
|
---|
| 386 |
|
---|
[10450] | 387 | my $secondary_plugins = $self->{'secondary_plugins'};
|
---|
| 388 | my $num_secondary_plugins = scalar(keys %$secondary_plugins);
|
---|
| 389 |
|
---|
| 390 | if ($num_secondary_plugins == 0) {
|
---|
| 391 | print $outhandle "Warning: No secondary plugin to use in conversion. Skipping $file\n";
|
---|
| 392 | return 0; # effectively block it
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | my @plugin_names = keys %$secondary_plugins;
|
---|
| 396 | my $plugin_name = shift @plugin_names;
|
---|
| 397 |
|
---|
| 398 | if ($num_secondary_plugins > 1) {
|
---|
| 399 | print $outhandle "Warning: Multiple secondary plugins not supported yet! Choosing $plugin_name\n.";
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | my $secondary_plugin = $secondary_plugins->{$plugin_name};
|
---|
| 403 |
|
---|
| 404 | # note: metadata is not carried on to the next level
|
---|
[16392] | 405 | ## **** I just replaced $metadata with {} in following
|
---|
[10450] | 406 | my ($rv,$doc_obj)
|
---|
[16392] | 407 | = $secondary_plugin->read_into_doc_obj ($pluginfo,"", $conv_filename, $block_hash, {}, $processor, $maxdocs, $total_count, $gli);
|
---|
[10450] | 408 |
|
---|
| 409 | if ((!defined $rv) || ($rv<1)) {
|
---|
| 410 | # wasn't processed
|
---|
| 411 | return $rv;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | # Override previous gsdlsourcefilename set by secondary plugin
|
---|
[15871] | 415 | my $collect_file = &util::filename_within_collection($filename_full_path);
|
---|
[10450] | 416 | my $collect_conv_file = &util::filename_within_collection($conv_filename);
|
---|
[18320] | 417 | $doc_obj->set_source_filename ($collect_file, $self->{'file_rename_method'});
|
---|
[20766] | 418 | ## set_source_filename does not set the doc_obj source_path which is used in archives dbs for incremental
|
---|
| 419 | # build. so set it manually.
|
---|
| 420 | $doc_obj->{'source_path'} = $filename_full_path;
|
---|
[10450] | 421 | $doc_obj->set_converted_filename($collect_conv_file);
|
---|
| 422 |
|
---|
[15871] | 423 | $self->set_Source_metadata($doc_obj, $filename_no_path);
|
---|
| 424 |
|
---|
[10450] | 425 | $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
|
---|
[15871] | 426 | $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "FileSize", (-s $filename_full_path));
|
---|
[10450] | 427 |
|
---|
[19053] | 428 | # ****
|
---|
| 429 | my ($tailname, $dirname, $suffix)
|
---|
| 430 | = &File::Basename::fileparse($filename_full_path, "\\.[^\\.]+\$");
|
---|
| 431 | $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "FilenameRoot", $tailname);
|
---|
| 432 |
|
---|
[10450] | 433 | # do plugin specific processing of doc_obj
|
---|
[15871] | 434 | unless (defined ($self->process($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli))) {
|
---|
[10450] | 435 | print STDERR "<ProcessingError n='$file'>\n" if ($gli);
|
---|
| 436 | return -1;
|
---|
| 437 | }
|
---|
[15871] | 438 |
|
---|
| 439 | my $topsection = $doc_obj->get_top_section();
|
---|
| 440 | $self->add_associated_files($doc_obj, $filename_full_path);
|
---|
[16392] | 441 |
|
---|
| 442 | # extra_metadata is already called by sec plugin in process??
|
---|
[15871] | 443 | $self->extra_metadata($doc_obj, $topsection, $metadata); # do we need this here??
|
---|
[10450] | 444 | # do any automatic metadata extraction
|
---|
| 445 | $self->auto_extract_metadata ($doc_obj);
|
---|
[10592] | 446 |
|
---|
| 447 | # have we found a Title??
|
---|
[15871] | 448 | $self->title_fallback($doc_obj,$topsection,$filename_no_path);
|
---|
[10592] | 449 |
|
---|
[15871] | 450 | $self->add_OID($doc_obj);
|
---|
[14928] | 451 |
|
---|
[15871] | 452 | return (1, $doc_obj);
|
---|
[14928] | 453 |
|
---|
[15871] | 454 | }
|
---|
[14928] | 455 |
|
---|
[15871] | 456 | sub process {
|
---|
| 457 | my $self = shift (@_);
|
---|
| 458 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
[10450] | 459 |
|
---|
[15871] | 460 | return $self->process_type($base_dir, $file, $doc_obj);
|
---|
[10450] | 461 | }
|
---|
| 462 |
|
---|
| 463 | # do plugin specific processing of doc_obj for doc_ext type
|
---|
| 464 | sub process_type {
|
---|
| 465 | my $self = shift (@_);
|
---|
[15871] | 466 | my ($base_dir, $file, $doc_obj) = @_;
|
---|
[10450] | 467 |
|
---|
[15871] | 468 | # need to check that not empty
|
---|
| 469 | my $doc_ext = $self->{'filename_extension'};
|
---|
| 470 | my $file_type = "unknown";
|
---|
| 471 | $file_type = $self->{'file_type'} if defined $self->{'file_type'};
|
---|
| 472 |
|
---|
[10450] | 473 | # associate original file with doc object
|
---|
| 474 | my $cursection = $doc_obj->get_top_section();
|
---|
| 475 | my $filename = &util::filename_cat($base_dir, $file);
|
---|
[12961] | 476 | my $assocfilename = "doc.$doc_ext";
|
---|
| 477 | if ($self->{'keep_original_filename'} == 1) {
|
---|
[16922] | 478 | # this should be the same filename that was used for the Source and SourceFile metadata,
|
---|
| 479 | # as we will use [SourceFile] in the srclink
|
---|
[16954] | 480 | $assocfilename = $doc_obj->get_assocfile_from_sourcefile();
|
---|
[12961] | 481 | }
|
---|
| 482 | $doc_obj->associate_file($filename, $assocfilename, undef, $cursection);
|
---|
[10450] | 483 |
|
---|
| 484 | # We use set instead of add here because we only want one value
|
---|
[15871] | 485 | $doc_obj->set_utf8_metadata_element($cursection, "FileFormat", $file_type);
|
---|
[21760] | 486 | my $srclink_filename = "doc.$doc_ext";
|
---|
| 487 | #my $doclink = "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/doc.$doc_ext\">";
|
---|
[12961] | 488 | if ($self->{'keep_original_filename'} == 1) {
|
---|
[21760] | 489 | $srclink_filename = "[SourceFile]";
|
---|
| 490 | #$doclink = "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">";
|
---|
[12961] | 491 | }
|
---|
[21760] | 492 | #$doc_obj->add_utf8_metadata ($cursection, "srclink", $doclink);
|
---|
[10450] | 493 | $doc_obj->add_utf8_metadata ($cursection, "srcicon", "_icon".$doc_ext."_");
|
---|
[21760] | 494 | #$doc_obj->add_utf8_metadata ($cursection, "/srclink", "</a>");
|
---|
| 495 | $doc_obj->add_utf8_metadata ($cursection, "srclink_file", $srclink_filename);
|
---|
[10450] | 496 | return 1;
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | 1;
|
---|
| 500 |
|
---|
| 501 |
|
---|
| 502 |
|
---|
| 503 |
|
---|
| 504 |
|
---|
| 505 |
|
---|
| 506 |
|
---|