Ignore:
Timestamp:
2009-01-06T19:03:58+13:00 (15 years ago)
Author:
ak19
Message:

Now plugins provide the option of base64 encoding or url encoding filenames that are to be renamed (when copied into the archives dir). Previously renamed files would always be url-encoded. URL-encoding is the default now for most plugins except MP3Plugin and OggVorbisPlugin, where the default is base64 encoding. Base64 encoding filenames upon renaming them was introduced so that more files that browsers try to open in external applications can open them, since url encoding does not seem to be implemented the same everywhere (for instance, windows media player is unable to handle url-encoded wmv filenames when such files are launched in it through the browser).

File:
1 edited

Legend:

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

    r18171 r18320  
    4444    @BasePlugin::ISA = ( 'PrintInfo' );
    4545}
     46
     47# the different methods that can be applied when renaming
     48# imported documents and their associated files
     49our $file_rename_method_list =
     50    [ { 'name' => "url",
     51    'desc' => "{BasePlugin.rename_method.url}" },
     52      { 'name' => "base64",
     53    'desc' => "{BasePlugin.rename_method.base64}" } ];
    4654
    4755our $encoding_list =
     
    126134    'deft' => "dc.Identifier",
    127135    'reqd' => "no",
    128     'modegli' => "2" },
    129 
     136    'modegli' => "2" },     
    130137#      { 'name' => "use_as_doc_identifier",
    131138#   'desc' => "{BasePlugin.use_as_doc_identifier}",
     
    133140#   'reqd' => "no" ,
    134141#   'deft' => "" } ,
    135      { 'name' => "no_cover_image",
     142      { 'name' => "no_cover_image",
    136143    'desc' => "{BasePlugin.no_cover_image}",
    137144    'type' => "flag",
     
    147154        'type' => "flag",
    148155        'reqd' => "no",
    149     'hiddengli' => "yes" } # deprecated, but leave in for old collections
    150 
     156    'hiddengli' => "yes" }, # deprecated, but leave in for old collections
     157      { 'name' => "file_rename_method",
     158    'desc' => "{BasePlugin.file_rename_method}",
     159    'type' => "enum",
     160    'deft' => &get_default_file_rename_method(), # by default rename imported files and assoc files using this encoding
     161    'list' => $file_rename_method_list,
     162    'reqd' => "no"
     163      }
    151164     
    152165      ];
     
    158171        'inherits' => "no",
    159172        'args'     => $arguments };
    160 
    161173
    162174sub new {
     
    346358
    347359    return "";
     360}
     361
     362# rename imported files and assoc files using URL encoding by default
     363# as this will work for most plugins and give more legible filenames
     364sub get_default_file_rename_method() {
     365    my $self = shift (@_);
     366    return "url";
    348367}
    349368
     
    566585
    567586# gets the filename with no path, converts to utf8, and then dm safes it.
    568 #filename_encoding set by user
     587# filename_encoding set by user
    569588sub filename_to_utf8_metadata
    570589{
     
    732751    my ($doc_obj, $filename_no_path, $file_encoding) = @_;
    733752
    734 
    735753    my $top_section = $doc_obj->get_top_section();
    736754   
    737755    # UTF-8 version of filename
    738756    my $filemeta = $self->filename_to_utf8_metadata($filename_no_path, $file_encoding);
    739 
     757   
    740758    # Source is the UTF8 display name - not necessarily the name of the file on the system
    741759    $doc_obj->set_utf8_metadata_element($top_section, "Source", $filemeta);
    742760
    743     # SourceFile is the url-reference to url-encoded filemeta:
    744     # it's a url that refers to the actual file on the system
    745     $filemeta = &unicode::url_encode($filemeta);
    746     $filemeta = &unicode::filename_to_url($filemeta);
     761    $filemeta = &util::rename_file($filemeta, $self->{'file_rename_method'});
     762    # If using URL encoding, then SourceFile is the url-reference to url-encoded
     763    # filemeta: it's a url that refers to the actual file on the system
     764    $filemeta = &unicode::filename_to_url($filemeta, $self->{'file_rename_method'});
     765
    747766    $doc_obj->set_utf8_metadata_element($top_section, "SourceFile", $filemeta);
    748767}
     
    797816    my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
    798817    # create a new document
    799     my $doc_obj = new doc ($filename_full_path, "indexed_doc");
     818    my $doc_obj = new doc ($filename_full_path, "indexed_doc", $self->{'file_rename_method'});
    800819    my $top_section = $doc_obj->get_top_section();
    801820
     
    10041023       
    10051024        # we need to make sure the filename is valid utf-8 - we do
    1006         # this by url encoding it
     1025        # this by url or base64 encoding it
    10071026        # $tail_filename is the name that we store the file as
    1008         $tail_filename = &unicode::url_encode($tail_filename);
     1027        $tail_filename = &util::rename_file($tail_filename, $self->{'file_rename_method'});
    10091028        $doc_obj->associate_file($full_filename,$tail_filename,$mimetype);
    1010         # then we need to encode the % signs in the filename, so that
    1011         # it works in a url
     1029        # If the filename is url_encoded, we need to encode the % signs
     1030        # in the filename, so that it works in a url
    10121031        my $url_tail_filename = &unicode::filename_to_url($tail_filename);
    10131032        # work out extended tail extension (i.e. matching tail re)
Note: See TracChangeset for help on using the changeset viewer.