Changeset 18320 for gsdl/trunk/perllib/plugins/BasePlugin.pm
- Timestamp:
- 2009-01-06T19:03:58+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/plugins/BasePlugin.pm
r18171 r18320 44 44 @BasePlugin::ISA = ( 'PrintInfo' ); 45 45 } 46 47 # the different methods that can be applied when renaming 48 # imported documents and their associated files 49 our $file_rename_method_list = 50 [ { 'name' => "url", 51 'desc' => "{BasePlugin.rename_method.url}" }, 52 { 'name' => "base64", 53 'desc' => "{BasePlugin.rename_method.base64}" } ]; 46 54 47 55 our $encoding_list = … … 126 134 'deft' => "dc.Identifier", 127 135 'reqd' => "no", 128 'modegli' => "2" }, 129 136 'modegli' => "2" }, 130 137 # { 'name' => "use_as_doc_identifier", 131 138 # 'desc' => "{BasePlugin.use_as_doc_identifier}", … … 133 140 # 'reqd' => "no" , 134 141 # 'deft' => "" } , 135 { 'name' => "no_cover_image",142 { 'name' => "no_cover_image", 136 143 'desc' => "{BasePlugin.no_cover_image}", 137 144 'type' => "flag", … … 147 154 'type' => "flag", 148 155 '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 } 151 164 152 165 ]; … … 158 171 'inherits' => "no", 159 172 'args' => $arguments }; 160 161 173 162 174 sub new { … … 346 358 347 359 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 364 sub get_default_file_rename_method() { 365 my $self = shift (@_); 366 return "url"; 348 367 } 349 368 … … 566 585 567 586 # gets the filename with no path, converts to utf8, and then dm safes it. 568 # filename_encoding set by user587 # filename_encoding set by user 569 588 sub filename_to_utf8_metadata 570 589 { … … 732 751 my ($doc_obj, $filename_no_path, $file_encoding) = @_; 733 752 734 735 753 my $top_section = $doc_obj->get_top_section(); 736 754 737 755 # UTF-8 version of filename 738 756 my $filemeta = $self->filename_to_utf8_metadata($filename_no_path, $file_encoding); 739 757 740 758 # Source is the UTF8 display name - not necessarily the name of the file on the system 741 759 $doc_obj->set_utf8_metadata_element($top_section, "Source", $filemeta); 742 760 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 747 766 $doc_obj->set_utf8_metadata_element($top_section, "SourceFile", $filemeta); 748 767 } … … 797 816 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file); 798 817 # 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'}); 800 819 my $top_section = $doc_obj->get_top_section(); 801 820 … … 1004 1023 1005 1024 # we need to make sure the filename is valid utf-8 - we do 1006 # this by url encoding it1025 # this by url or base64 encoding it 1007 1026 # $tail_filename is the name that we store the file as 1008 $tail_filename = &u nicode::url_encode($tail_filename);1027 $tail_filename = &util::rename_file($tail_filename, $self->{'file_rename_method'}); 1009 1028 $doc_obj->associate_file($full_filename,$tail_filename,$mimetype); 1010 # then we need to encode the % signs in the filename, so that1011 # i t works in a url1029 # If the filename is url_encoded, we need to encode the % signs 1030 # in the filename, so that it works in a url 1012 1031 my $url_tail_filename = &unicode::filename_to_url($tail_filename); 1013 1032 # work out extended tail extension (i.e. matching tail re)
Note:
See TracChangeset
for help on using the changeset viewer.