Changeset 10406
- Timestamp:
- 2005-08-03T13:38:56+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/plugins/ConvertToPlug.pm
r10352 r10406 24 24 # 25 25 ########################################################################### 26 27 26 # This plugin is inherited by such plugins as WordPlug, PPTPlug, PSPlug, RTFPlug 28 27 # and PDFPlug. It facilitates the conversion of these document types to either … … 97 96 { 98 97 my ($inputargs) = @_; 99 98 my ($convert_to_type,$windows_scripting); 99 $conver_to_type = "html"; 100 $windows_scripting = "false"; 100 101 for(my $intCounter = 0; $intCounter < scalar(@{$inputargs}) ; $intCounter++) 101 102 { 102 103 if($inputargs->[$intCounter] eq "-convert_to") 103 104 { 104 #if($inputargs->[$intCounter+1] eq "auto" || $inputargs->[$intCounter+1] =~ /pagedimg.*/i || $inputargs->[$intCounter+1] eq "text" || $inputargs->[$intCounter+1] eq "html")105 if($inputargs->[$intCounter+1] eq "auto" || $inputargs->[$intCounter+1] =~ /pagedimg.*/i || $inputargs->[$intCounter+1] eq "text" || $inputargs->[$intCounter+1] eq "html") 105 106 # if the setting is "auto" then refer to html for now 106 if($inputargs->[$intCounter+1] =~ /pagedimg.*/i || $inputargs->[$intCounter+1] eq "text" || $inputargs->[$intCounter+1] eq "html")107 #if($inputargs->[$intCounter+1] =~ /pagedimg.*/i || $inputargs->[$intCounter+1] eq "text" || $inputargs->[$intCounter+1] eq "html") 107 108 { 108 return$inputargs->[$intCounter+1];109 $conver_to_type = $inputargs->[$intCounter+1]; 109 110 } 110 else {return "html";}111 111 } 112 } 113 return "html"; 112 if ($inputargs->[$intCounter] eq "-windows_scripting") 113 { 114 $windows_scripting = "true"; 115 } 116 } 117 return ($conver_to_type,$windows_scripting); 114 118 } 115 119 … … 142 146 push(@$pluginlist, $class); 143 147 my $classPluginName = (defined $pluginlist->[0]) ? $pluginlist->[0] : $class; 144 my $strConvertTo= findType($inputargs);148 my ($strConvertTo,$blnWindowsScripting) = findType($inputargs); 145 149 146 150 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});} … … 152 156 $strConvertTo = "html"; 153 157 } 154 155 158 my $self = {}; 156 157 159 my $plugin_class =""; 158 159 if ($strConvertTo =~ /pagedimg.*/i){ 160 # If the WordPlug -windows_scripting is on, we will call StructuredHTMLPlug to format the 161 # HTML documents and then pass to HTMLPlug 162 if ($classPluginName eq "WordPlug" && $blnWindowsScripting eq "true" && 163 $ENV{'GSDLOS'} =~ /^windows$/i) { 164 $plugin_class = "StructuredHTML"."Plug"; 165 } elsif ($strConvertTo =~ /pagedimg.*/i){ 160 166 $plugin_class = "PagedImg"."Plug"; 161 167 } else { … … 165 171 my $plugin_package = $plugin_class.".pm"; 166 172 require $plugin_package; 167 168 # 173 174 #call its constructor with extra options that we've worked out! 169 175 my $arglist = $plugin_options->{$plugin_class}; 170 176 $self = (defined $hashArgOptLists)? new $plugin_class($pluginlist,$inputargs,$hashArgOptLists): new $plugin_class($pluginlist,$inputargs); 171 177 172 173 if ($strConvertTo eq "text") 178 if ($plugin_class eq "StructuredHTMLPlug") { 179 $self->{'convert_to'} = "StructuredHTML"; 180 $self->{'convert_to_ext'} = "html"; 181 # my $structhtml_options = []; 182 # push(@$structhtml_options,"-metadata_fields","Title,GENERATOR"); 183 # $secondary_plugin_options->{'StructuredHTMLPlug'} = $structhtml_options; 184 } 185 elsif ($strConvertTo eq "text") 174 186 { 175 187 #$self = (defined $hashArgOptLists)? new TEXTPlug($pluginlist,$inputargs,$hashArgOptLists): new TEXTPlug($pluginlist,$inputargs); 176 188 $self->{'convert_to'} = "TEXT"; 177 189 $self->{'convert_to_ext'} = "txt"; 178 my $text_options = [];179 push(@$text_options,"-metadata_fields","Title,GENERATOR");180 $secondary_plugin_options->{'TextPlug'} = $text_options;190 # my $text_options = []; 191 # push(@$text_options,"-metadata_fields","Title,GENERATOR"); 192 # $secondary_plugin_options->{'TextPlug'} = $text_options; 181 193 } 182 194 elsif ($strConvertTo =~ /pagedimg.*/i){ 183 #$self = (defined $hashArgOptLists)? new PagedImgPlug($pluginlist,$inputargs,$hashArgOptLists): new PagedImgPlug($pluginlist,$inputargs);195 # #$self = (defined $hashArgOptLists)? new PagedImgPlug($pluginlist,$inputargs,$hashArgOptLists): new PagedImgPlug($pluginlist,$inputargs); 184 196 $self->{'convert_to'} = "PagedImg"; 185 197 my $convert_to_ext = $strConvertTo; … … 192 204 $self->{'convert_to_ext'} = "png"; 193 205 } 194 my $pagedimg_options = [];195 push(@$pagedimg_options,"-metadata_fields","Title,GENERATOR");196 $secondary_plugin_options->{'PagedImgPlug'} = $pagedimg_options;206 # my $pagedimg_options = []; 207 # push(@$pagedimg_options,"-metadata_fields","Title,GENERATOR"); 208 # $secondary_plugin_options->{'PagedImgPlug'} = $pagedimg_options; 197 209 } else { 198 210 # HTML or auto 199 #$self = (defined $hashArgOptLists)? new HTMLPlug($pluginlist,$inputargs,$hashArgOptLists): new HTMLPlug($pluginlist,$inputargs);211 $self = (defined $hashArgOptLists)? new HTMLPlug($pluginlist,$inputargs,$hashArgOptLists): new HTMLPlug($pluginlist,$inputargs); 200 212 $self->{'convert_to'} = "HTML"; 201 213 $self->{'convert_to_ext'} = "html"; 202 my $html_options = []; 203 push(@$html_options,"-rename_assoc_files","1"); 204 push(@$html_options,"-metadata_fields","Title,GENERATOR"); 205 $secondary_plugin_options->{'HTMLPlug'} = $html_options; 206 } 207 214 # my $html_options = []; 215 # push(@$html_options,"-rename_assoc_files","1"); 216 # push(@$html_options,"-metadata_fields","Title,GENERATOR"); 217 # $secondary_plugin_options->{'HTMLPlug'} = $html_options; 218 } 208 219 return bless $self, $class; 209 220 } … … 226 237 sub deinit { 227 238 # called only once, after all plugin passes have been done 228 229 239 my ($self) = @_; 230 240 … … 252 262 # something like "html" or "word", but can be "best" (or the empty string) 253 263 # to indicate that the conversion utility should do the best it can. 254 255 264 sub tmp_area_convert_file { 256 265 my $self = shift (@_); … … 273 282 # Remove any white space from filename -- no risk of name collision, and 274 283 # makes later conversion by utils simpler. Leave spaces in path... 284 # tidy up the filename with space, dot, hyphen between 275 285 $tailname =~ s/\s+//g; 276 286 $tailname =~ s/\.+//g; 287 $tailname =~ s/\-+//g; 288 $suffix = lc($suffix); 277 289 my $tmp_filename = &util::filename_cat($tmp_dirname, "$tailname$suffix"); 278 279 290 &util::soft_link($input_filename, $tmp_filename); 280 281 291 my $verbosity = $self->{'verbosity'}; 282 292 if ($verbosity > 0) { … … 307 317 308 318 # remove symbolic link to original file 309 &util::rm($tmp_filename);319 #&util::rm($tmp_filename); 310 320 311 321 # Check STDERR here … … 380 390 381 391 my $output_ext = $self->{'convert_to_ext'}; 382 383 392 my $conv_filename = ""; 384 393 $conv_filename = $self->tmp_area_convert_file($output_ext, $filename); … … 387 396 if (! -e "$conv_filename") {return 0;} # allows continue on errors 388 397 $self->{'conv_filename'} = $conv_filename; 389 390 398 $self->convert_post_process($conv_filename); 391 399 … … 404 412 print $outhandle "Warning: Multiple secondary plugins not supported yet! Choosing $plugin_name\n."; 405 413 } 406 414 407 415 my $secondary_plugin = $secondary_plugins->{$plugin_name}; 408 416 … … 426 434 my ($filemeta) = $file =~ /([^\\\/]+)$/; 427 435 $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Source", &ghtml::dmsafe($filemeta)); 428 429 436 $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}"); 430 437 $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "FileSize", (-s $filename)); … … 441 448 # process the document 442 449 $processor->process($doc_obj); 443 ##$self->cleanup_tmp_area(); 450 # We don't clear up the tmp directory here, the tmp directory will be deleted if the user setup -removeold option 451 # in the import.pl 452 #$self->cleanup_tmp_area(); 444 453 445 454 $self->{'num_processed'} ++;
Note:
See TracChangeset
for help on using the changeset viewer.