Changeset 18320 for gsdl/trunk


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).

Location:
gsdl/trunk/perllib/plugins
Files:
7 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)
  • gsdl/trunk/perllib/plugins/ConvertBinaryFile.pm

    r17726 r18320  
    284284    # to work on Windows (IE or Firefox), as browsers are looking for filesystem-encoded
    285285    # files on the filesystem.
    286     $tailname = &unicode::url_encode($tailname);
     286    $tailname = &util::rename_file($tailname, $self->{'file_rename_method'});
    287287
    288288    $suffix = lc($suffix);
     
    429429    my $collect_file = &util::filename_within_collection($filename_full_path);
    430430    my $collect_conv_file = &util::filename_within_collection($conv_filename);
    431     $doc_obj->set_source_filename ($collect_file);
     431    $doc_obj->set_source_filename ($collect_file, $self->{'file_rename_method'});
    432432    $doc_obj->set_converted_filename($collect_conv_file);
    433433
  • gsdl/trunk/perllib/plugins/HTMLPlugin.pm

    r18135 r18320  
    635635# Given a filename in any encoding, will URL decode it to get back the original filename
    636636# in the original encoding. Because this method is intended to work out the *original*
    637 # filename*, it not URL decode any filename if a file by the name of the *URL-encoded*
     637# filename*, it does not URL decode any filename if a file by the name of the *URL-encoded*
    638638# string already exists in the local folder.
    639639# Return the original filename corresponding to the parameter URL-encoded filename, and
     
    11401140    }
    11411141
    1142     # Make sure this name uses only ASCII characters
    1143     # => use URL encoding, as it preserves original encoding
    1144     $newname = &unicode::url_encode($newname);
     1142    # Make sure this name uses only ASCII characters.
     1143    # We use either base64 or URL encoding, as these preserve original encoding
     1144    $newname = &util::rename_file($newname, $self->{'file_rename_method'});
    11451145
    11461146    $doc_obj->associate_file($filename, $newname, undef, $section);
  • gsdl/trunk/perllib/plugins/ImagePlugin.pm

    r17666 r18320  
    114114    if ($self->{'image_conversion_available'} == 1) {
    115115    my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
    116     my $url_encoded_filename = &unicode::url_encode($utf8_filename_no_path);
     116    my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
    117117    $self->generate_images($filename_full_path, $url_encoded_filename, $doc_obj, $doc_obj->get_top_section()); # should we check the return value?
    118118    } else {
  • gsdl/trunk/perllib/plugins/MP3Plugin.pm

    r17026 r18320  
    6060    'desc' => "{MP3Plugin.metadata_fields}",
    6161    'type' => "string",
    62     'deft' => "Title,Artist,Genre" } ];
     62    'deft' => "Title,Artist,Genre" },
     63      { 'name' => "file_rename_method",
     64    'desc' => "{BasePlugin.file_rename_method}",
     65    'type' => "enum",
     66    'deft' => &get_default_file_rename_method(), # by default rename imported files and assoc files using this encoding
     67    'list' => $BasePlugin::file_rename_method_list,
     68    'reqd' => "no"
     69      } ];
    6370
    6471my $options = { 'name'     => "MP3Plugin",
     
    8390sub get_default_process_exp {
    8491    return q^(?i)\.mp3$^;
     92}
     93
     94# rename imported files and assoc files using base64 encoding by default
     95# so that the urls generated will always work with media files even when
     96# opened in external applications (when wmv file names contain spaces in
     97# them and they get url-encoded, wmv player fails to open the doubly url-
     98# encoded url reference to the url-encoded filename).
     99sub get_default_file_rename_method() {
     100    return "base64";
    85101}
    86102
  • gsdl/trunk/perllib/plugins/OggVorbisPlugin.pm

    r17026 r18320  
    5151    'desc' => "{OggVorbisPlugin.add_technical_metadata}",
    5252    'type' => "flag",
    53     'deft' => "" } ];
     53    'deft' => "" },
     54      { 'name' => "file_rename_method",
     55    'desc' => "{BasePlugin.file_rename_method}",
     56    'type' => "enum",
     57    'deft' => &get_default_file_rename_method(), # by default rename imported files and assoc files using this encoding
     58    'list' => $BasePlugin::file_rename_method_list,
     59    'reqd' => "no"
     60      } ];
    5461
    5562my $options = { 'name'     => "OggVorbisPlugin",
     
    6673}
    6774
     75# rename imported media files using base64 encoding by default
     76# so that the urls generated will always work with external apps
     77sub get_default_file_rename_method() {
     78    return "base64";
     79}
    6880
    6981sub new
  • gsdl/trunk/perllib/plugins/ReadTextFile.pm

    r17213 r18320  
    133133
    134134    # create a new document
    135     my $doc_obj = new doc ($filename_full_path, "indexed_doc");
     135    my $doc_obj = new doc ($filename_full_path, "indexed_doc", $self->{'file_rename_method'});
    136136    my $top_section = $doc_obj->get_top_section();
    137137
Note: See TracChangeset for help on using the changeset viewer.