Changeset 10352
- Timestamp:
- 2005-07-29T14:25:23+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/plugins/ConvertToPlug.pm
r10278 r10352 31 31 # secondary_plugins to devide which format to 'convert_to'. If the argument is 32 32 # not present, the default is to inherit auto. 33 34 35 33 package ConvertToPlug; 36 34 … … 45 43 46 44 sub BEGIN { 47 @ ISA = ('BasPlug');45 @ConvertToPlug::ISA = ('BasPlug'); 48 46 } 49 47 … … 55 53 { 'name' => "text", 56 54 'desc' => "{ConvertToPlug.convert_to.text}" }, 57 { 'name' => "pagedimg -jpg",58 'desc' => "{ConvertToPlug.convert_to.pagedimg -jpg"},59 { 'name' => "pagedimg -gif",60 'desc' => "{ConvertToPlug.convert_to.pagedimg -gif"},61 { 'name' => "pagedimg -png",62 'desc' => "{ConvertToPlug.convert_to.pagedimg -png"},55 { 'name' => "pagedimg_jpg", 56 'desc' => "{ConvertToPlug.convert_to.pagedimg_jpg}"}, 57 { 'name' => "pagedimg_gif", 58 'desc' => "{ConvertToPlug.convert_to.pagedimg_gif}"}, 59 { 'name' => "pagedimg_png", 60 'desc' => "{ConvertToPlug.convert_to.pagedimg_png}"}, 63 61 ]; 64 62 … … 70 68 'list' => $convert_to_list, 71 69 'deft' => "html" }, 70 { 'name' => "title_sub", 71 'desc' => "{HTMLPlug.title_sub}", 72 'type' => "string", 73 #'type' => "regexp", 74 'deft' => "" }, 72 75 { 'name' => "use_strings", 73 76 'desc' => "{ConvertToPlug.use_strings}", … … 91 94 'args' => $arguments }; 92 95 93 94 96 sub findType 95 97 { … … 118 120 119 121 my @convert_to_list = split(",",$self->{'convert_to'}); 120 121 122 $secondary_plugins = {}; 122 123 … … 125 126 my $plugin_class = $convert_to."Plug"; 126 127 my $plugin_package = $plugin_class.".pm"; 128 127 129 require $plugin_package; 128 130 … … 152 154 153 155 my $self = {}; 156 157 my $plugin_class =""; 158 159 if ($strConvertTo =~ /pagedimg.*/i){ 160 $plugin_class = "PagedImg"."Plug"; 161 } else { 162 $plugin_class = uc($strConvertTo)."Plug"; 163 } 164 165 my $plugin_package = $plugin_class.".pm"; 166 require $plugin_package; 167 168 # call its constructor with extra options that we've worked out! 169 my $arglist = $plugin_options->{$plugin_class}; 170 $self = (defined $hashArgOptLists)? new $plugin_class($pluginlist,$inputargs,$hashArgOptLists): new $plugin_class($pluginlist,$inputargs); 171 172 154 173 if ($strConvertTo eq "text") 155 174 { 156 $self = (defined $hashArgOptLists)? new TEXTPlug($pluginlist,$inputargs,$hashArgOptLists): new TEXTPlug($pluginlist,$inputargs);175 #$self = (defined $hashArgOptLists)? new TEXTPlug($pluginlist,$inputargs,$hashArgOptLists): new TEXTPlug($pluginlist,$inputargs); 157 176 $self->{'convert_to'} = "TEXT"; 158 177 $self->{'convert_to_ext'} = "txt"; … … 162 181 } 163 182 elsif ($strConvertTo =~ /pagedimg.*/i){ 164 $self = (defined $hashArgOptLists)? new PagedImgPlug($pluginlist,$inputargs,$hashArgOptLists): new PagedImgPlug($pluginlist,$inputargs);183 #$self = (defined $hashArgOptLists)? new PagedImgPlug($pluginlist,$inputargs,$hashArgOptLists): new PagedImgPlug($pluginlist,$inputargs); 165 184 $self->{'convert_to'} = "PagedImg"; 166 #$self->{'convert_to'} = $strConvertTo;167 185 my $convert_to_ext = $strConvertTo; 168 $convert_to_ext =~ s/.*\ -(.*)/$1/i;186 $convert_to_ext =~ s/.*\_(.*)/$1/i; 169 187 if ($convert_to_ext eq "gif"){ 170 188 $self->{'convert_to_ext'} = "gif"; … … 179 197 } else { 180 198 # HTML or auto 181 $self = (defined $hashArgOptLists)? new HTMLPlug($pluginlist,$inputargs,$hashArgOptLists): new HTMLPlug($pluginlist,$inputargs);199 #$self = (defined $hashArgOptLists)? new HTMLPlug($pluginlist,$inputargs,$hashArgOptLists): new HTMLPlug($pluginlist,$inputargs); 182 200 $self->{'convert_to'} = "HTML"; 183 201 $self->{'convert_to_ext'} = "html"; … … 219 237 } 220 238 221 222 239 sub convert_post_process 223 240 { … … 239 256 my $self = shift (@_); 240 257 my ($output_ext, $input_filename, $textref) = @_; 241 258 242 259 my $outhandle = $self->{'outhandle'}; 243 260 my $convert_to = $self->{'convert_to'}; 244 261 my $failhandle = $self->{'failhandle'}; 245 262 my $convert_to_ext = $self->{'convert_to_ext'}; 246 263 247 264 # softlink to collection tmp dir 248 265 my $tmp_dirname … … 273 290 my $output_type=""; 274 291 if ($convert_to =~ m/PagedImg/i) { 275 $output_type = lc($convert_to)." -".lc($convert_to_ext);292 $output_type = lc($convert_to)."_".lc($convert_to_ext); 276 293 } else { 277 294 $output_type = lc($convert_to); … … 290 307 291 308 # remove symbolic link to original file 292 #&util::rm($tmp_filename);309 &util::rm($tmp_filename); 293 310 294 311 # Check STDERR here … … 312 329 # store the *actual* output type and return the output filename 313 330 # it's possible we requested conversion to html, but only to text succeeded 314 $self->{'convert_to_ext'} = $output_type;331 #$self->{'convert_to_ext'} = $output_type; 315 332 if ($output_type =~ /html/i) { 316 333 $self->{'converted_to'} = "HTML"; … … 323 340 my $output_filename = $tmp_filename; 324 341 if ($output_type =~ /item/i) { 325 $output_filename = $tmp_dirname . "\\$tailname\\" . $tailname . ".$output_type"; 342 # running under windows 343 if ($ENV{'GSDLOS'} =~ /^windows$/i) { 344 $output_filename = $tmp_dirname . "\\$tailname\\" . $tailname . ".$output_type"; 345 } else { 346 $output_filename = $tmp_dirname . "\/$tailname\/" . $tailname . ".$output_type"; 347 } 326 348 } else { 327 349 $output_filename =~ s/$suffix$/.$output_type/; … … 337 359 my $tmp_dirname 338 360 = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "tmp"); 339 #&util::rm_r($tmp_dirname);361 &util::rm_r($tmp_dirname); 340 362 &util::mk_dir($tmp_dirname); 341 363 } … … 347 369 my $self = shift (@_); 348 370 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_; 349 #if ($self->is_recursive()) {350 #die "BasPlug::read function must be implemented in sub-class for recursive plugins\n";351 #}371 #if ($self->is_recursive()) { 372 # die "BasPlug::read function must be implemented in sub-class for recursive plugins\n"; 373 # } 352 374 353 375 my $outhandle = $self->{'outhandle'}; 354 376 355 377 my ($block_status,$filename) = $self->read_block(@_); 356 378 return $block_status if ((!defined $block_status) || ($block_status==0)); 357 379 $file = $self->read_tidy_file($file); 358 380 359 381 my $output_ext = $self->{'convert_to_ext'}; 360 my $conv_filename = $self->tmp_area_convert_file($output_ext, $filename); 382 383 my $conv_filename = ""; 384 $conv_filename = $self->tmp_area_convert_file($output_ext, $filename); 385 361 386 if ("$conv_filename" eq "") {return 0;} # allows continue on errors 362 387 if (! -e "$conv_filename") {return 0;} # allows continue on errors … … 367 392 my $secondary_plugins = $self->{'secondary_plugins'}; 368 393 my $num_secondary_plugins = scalar(keys %$secondary_plugins); 394 369 395 if ($num_secondary_plugins == 0) { 370 396 print $outhandle "Warning: No secondary plugin to use in conversion. Skipping $file\n"; … … 380 406 381 407 my $secondary_plugin = $secondary_plugins->{$plugin_name}; 382 408 383 409 # note: metadata is not carried on to the next level 384 410 my ($rv,$doc_obj) … … 400 426 my ($filemeta) = $file =~ /([^\\\/]+)$/; 401 427 $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Source", &ghtml::dmsafe($filemeta)); 428 402 429 $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}"); 403 430 $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "FileSize", (-s $filename)); 404 431 405 432 # do plugin specific processing of doc_obj 406 433 unless (defined ($self->process(undef, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli))) { … … 414 441 # process the document 415 442 $processor->process($doc_obj); 416 ##$self->cleanup_tmp_area();443 ##$self->cleanup_tmp_area(); 417 444 418 445 $self->{'num_processed'} ++;
Note:
See TracChangeset
for help on using the changeset viewer.