Changeset 10406


Ignore:
Timestamp:
2005-08-03T13:38:56+12:00 (19 years ago)
Author:
chi
Message:

If the -windows_scripting is on in WordPlug, the secondary plugin will be StructuredHTMLPlug which can't
be decided base on -convert_to. Hence, it is coded in this program. Also, a modification to tidy up
the source filename (get rid of . and - within the filename) is added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/ConvertToPlug.pm

    r10352 r10406  
    2424#
    2525###########################################################################
    26 
    2726# This plugin is inherited by such plugins as WordPlug, PPTPlug, PSPlug, RTFPlug
    2827# and PDFPlug. It facilitates the conversion of these document types to either
     
    9796{
    9897    my ($inputargs) = @_;
    99    
     98    my ($convert_to_type,$windows_scripting);
     99    $conver_to_type = "html";
     100    $windows_scripting = "false";
    100101    for(my $intCounter = 0; $intCounter < scalar(@{$inputargs}) ; $intCounter++)
    101102    {
    102103    if($inputargs->[$intCounter] eq "-convert_to")
    103104    {
    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")
    105106        # 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")
    107108        {
    108         return $inputargs->[$intCounter+1];
     109        $conver_to_type = $inputargs->[$intCounter+1];
    109110        }
    110         else {return "html";}
    111111    }
    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);
    114118}
    115119
     
    142146    push(@$pluginlist, $class);
    143147    my $classPluginName = (defined $pluginlist->[0]) ? $pluginlist->[0] : $class;
    144     my $strConvertTo = findType($inputargs);
     148    my ($strConvertTo,$blnWindowsScripting) = findType($inputargs);
    145149
    146150    if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
     
    152156    $strConvertTo = "html";
    153157    }
    154 
    155158    my $self = {};
    156 
    157159    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){
    160166    $plugin_class = "PagedImg"."Plug";
    161167    } else {
     
    165171    my $plugin_package = $plugin_class.".pm";
    166172    require $plugin_package;
    167    
    168     # call its constructor with extra options that we've worked out!
     173
     174    #call its constructor with extra options that we've worked out!
    169175    my $arglist = $plugin_options->{$plugin_class};
    170176    $self = (defined $hashArgOptLists)? new $plugin_class($pluginlist,$inputargs,$hashArgOptLists): new $plugin_class($pluginlist,$inputargs);
    171177
    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")
    174186    {
    175187    #$self = (defined $hashArgOptLists)? new TEXTPlug($pluginlist,$inputargs,$hashArgOptLists): new TEXTPlug($pluginlist,$inputargs);
    176188    $self->{'convert_to'} = "TEXT";
    177189    $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;
    181193    }
    182194    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);
    184196    $self->{'convert_to'} = "PagedImg";
    185197    my $convert_to_ext = $strConvertTo;
     
    192204        $self->{'convert_to_ext'} = "png";
    193205    }
    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;
    197209    } else {
    198210    # 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);
    200212    $self->{'convert_to'} = "HTML";
    201213    $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    }
    208219    return bless $self, $class;
    209220}
     
    226237sub deinit {
    227238    # called only once, after all plugin passes have been done
    228 
    229239    my ($self) = @_;
    230240
     
    252262# something like "html" or "word", but can be "best" (or the empty string)
    253263# to indicate that the conversion utility should do the best it can.
    254 
    255264sub tmp_area_convert_file {
    256265    my $self = shift (@_);
     
    273282    # Remove any white space from filename -- no risk of name collision, and
    274283    # makes later conversion by utils simpler. Leave spaces in path...
     284    # tidy up the filename with space, dot, hyphen between
    275285    $tailname =~ s/\s+//g;
    276 
     286    $tailname =~ s/\.+//g;
     287    $tailname =~ s/\-+//g;
     288    $suffix = lc($suffix);
    277289    my $tmp_filename = &util::filename_cat($tmp_dirname, "$tailname$suffix");
    278 
    279290    &util::soft_link($input_filename, $tmp_filename);
    280 
    281291    my $verbosity = $self->{'verbosity'};
    282292    if ($verbosity > 0) {
     
    307317
    308318    # remove symbolic link to original file
    309     &util::rm($tmp_filename);
     319    #&util::rm($tmp_filename);
    310320
    311321    # Check STDERR here
     
    380390   
    381391    my $output_ext = $self->{'convert_to_ext'};
    382 
    383392    my $conv_filename = "";
    384393    $conv_filename = $self->tmp_area_convert_file($output_ext, $filename);
     
    387396    if (! -e "$conv_filename") {return 0;} # allows continue on errors
    388397    $self->{'conv_filename'} = $conv_filename;
    389    
    390398    $self->convert_post_process($conv_filename);
    391399   
     
    404412    print $outhandle "Warning: Multiple secondary plugins not supported yet!  Choosing $plugin_name\n.";
    405413    }
    406     
     414   
    407415    my $secondary_plugin = $secondary_plugins->{$plugin_name};
    408416
     
    426434    my ($filemeta) = $file =~ /([^\\\/]+)$/;
    427435    $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Source", &ghtml::dmsafe($filemeta));
    428 
    429436    $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
    430437    $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "FileSize", (-s $filename));
     
    441448    # process the document
    442449    $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();
    444453
    445454    $self->{'num_processed'} ++;
Note: See TracChangeset for help on using the changeset viewer.