Changeset 1446
- Timestamp:
- 2000-08-25T13:05:54+12:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/plugins/ConvertToPlug.pm
r1435 r1446 38 38 package ConvertToPlug; 39 39 40 use BasPlug; 40 41 use HTMLPlug; 41 42 use TEXTPlug; 42 43 43 44 sub BEGIN { 44 @ISA = ('HTMLPlug', 'TEXTPlug'); 45 @ISA = ('HTMLPlug'); 46 # @ISA = ('HTMLPlug', 'TEXTPlug'); 47 # @ISA = ('BasPlug'); #, 'HTMLPlug', 'TEXTPlug'); 45 48 } 46 49 … … 80 83 sub new { 81 84 my $class = shift (@_); 82 83 85 my ($plugin_name,$generate_format) = $class->parse_args(\@_); 84 85 86 my $self; 86 87 … … 96 97 $self->{'convert_to'} = "HTML"; 97 98 $self->{'convert_to_ext'} = "html"; 99 100 $self->{'rename_assoc_files'} = 1; 101 $self->{'metadata_fields'} .= ",GENERATOR"; 98 102 } 99 103 … … 103 107 104 108 105 # Run conversion utility on the input file. Output files generated in 106 # collection specific 'tmp' directory. 107 # The collection tmp area is used to convert Word, PDF etc documents into 108 # another format (such as text or HTML) suitable for reading and indexing 109 # Run conversion utility on the input file. 110 # 111 # The conversion takes place in a collection specific 'tmp' directory so 112 # that we don't accidentally damage the input. 113 # 114 # The desired output type is indicated by $output_ext. This is usually 115 # something like "html" or "word", but can be "best" (or the empty string) 116 # to indicate that the conversion utility should do the best it can. 109 117 110 118 sub tmp_area_convert_file { 111 119 my $self = shift (@_); 112 120 my ($output_ext,$input_filename, $textref) = @_; 121 122 my $convert_to = $self->{'convert_to'}; 113 123 114 124 # softlink to collection tmp dir … … 122 132 = File::Basename::fileparse($input_filename,'\..+'); 123 133 my $tmp_filename = &util::filename_cat($tmp_dirname,"$tailname$suffix"); 124 125 134 # Remove any white space from filename -- no risk of name collision, and 126 # makes lat ter conversion by utils simpler135 # makes later conversion by utils simpler 127 136 $tmp_filename =~ s/\s+//g; 128 137 129 138 &util::soft_link($input_filename,$tmp_filename); 130 131 my $output_filename132 = &util::filename_cat($tmp_dirname,"$tailname.$output_ext");133 $output_filename =~ s/\s+//g;134 139 135 140 my $verbosity = $self->{'verbosity'}; 136 141 if ($verbosity>0) 137 142 { 138 print STDERR "Converting $tailname$suffix to $self->{'convert_to'}\n"; 139 } 140 141 # run either gs2txt.pl or gs2html.pl to peform the requested conversion 142 if (system("gs2$output_ext.pl -verbose $verbosity \"$tmp_filename\"")>0) 143 { 144 print STDERR "Warning: unable to convert to $output_ext format\n"; 143 print STDERR "Converting $tailname$suffix to $convert_to format\n"; 144 } 145 146 # Execute the conversion command and get the type of the result, 147 # making sure the converter gives us the appropriate output type 148 my $output_type = lc($convert_to); 149 my $cmd = "gsConvert.pl -verbose $verbosity -output $output_type \"$tmp_filename\""; 150 $output_type = `$cmd`; 151 152 # Check STDERR here 153 154 chomp $output_type; 155 if ($output_type eq "fail") { 156 print STDERR "Could not convert $tailname$suffix to $convert_to format\n"; 157 exit 1; 145 158 } 146 159 147 160 # remove symbolic link to original file 148 161 &util::rm($tmp_filename); 162 163 # store the *actual* output type and return the output filename 164 $self->{'convert_to_ext'} = $output_type; 165 my $output_filename = $tmp_filename; 166 $output_filename =~ s/$suffix$/.$output_type/; 149 167 150 168 return $output_filename; … … 207 225 if ($convert_to eq "TEXT") 208 226 { 227 209 228 $ret_val = TEXTPlug::process($self,$textref,$pluginfo, 210 229 $tmp_dirname,$tmp_tailname,
Note:
See TracChangeset
for help on using the changeset viewer.