Changeset 18319 for gsdl/trunk/perllib
- Timestamp:
- 2009-01-06T18:40:53+13:00 (15 years ago)
- Location:
- gsdl/trunk/perllib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/doc.pm
r17057 r18319 49 49 sub new { 50 50 my $class = shift (@_); 51 my ($source_filename, $doc_type ) = @_;51 my ($source_filename, $doc_type, $rename_method) = @_; 52 52 53 53 … … 67 67 if (defined $source_filename) { 68 68 $source_filename = &util::filename_within_collection($source_filename); 69 $self->set_source_filename ($source_filename); 69 print STDERR "******doc.pm::new(): no file rename method provided\n" unless $rename_method; 70 $self->set_source_filename ($source_filename, $rename_method); 70 71 } 71 72 … … 144 145 sub set_source_filename { 145 146 my $self = shift (@_); 146 my ($source_filename ) = @_;147 my ($source_filename, $rename_method) = @_; 147 148 148 149 # Since the gsdlsourcefilename element goes into the doc.xml it has 149 150 # to be utf8. However, it should also *represent* the source filename 150 151 # (in the import directory) which may not be utf8 at all. 151 # For instance, if this meta element (gsdlsourcefilename) will be 152 # usedby other applications that parse doc.xml in order to locate153 # gsdlsourcefilename. Therefore, the solution is to URLencode the real154 # filename as this is a binary-to-text encoding meaning that the155 # resulting string is ASCII (utf8).156 157 # print STDERR "******URL encoding the gsdl_source_filename $source_filename ";158 152 # For instance, if this meta element (gsdlsourcefilename) will be used 153 # by other applications that parse doc.xml in order to locate 154 # gsdlsourcefilename. Therefore, the solution is to URLencode or base64 155 # encode the real filename as this is a binary-to-text encoding meaning 156 # that the resulting string is ASCII (utf8). Decoding will give the original. 157 158 # print STDERR "******URL/base64 encoding the gsdl_source_filename $source_filename "; 159 159 160 # URLencode just the gsdl_source_filename, not the directory. Then prepend dir 160 161 my ($srcfilename,$dirname,$suffix) 161 162 = &File::Basename::fileparse($source_filename, "\\.[^\\.]+\$"); 162 163 # print STDERR "-> $srcfilename -> "; 163 $srcfilename = &u nicode::url_encode($srcfilename.$suffix);164 $srcfilename = &util::rename_file($srcfilename.$suffix, $rename_method); 164 165 $source_filename = &util::filename_cat($dirname, $srcfilename); 165 166 # print STDERR "$source_filename\n"; -
gsdl/trunk/perllib/strings.properties
r17939 r18319 716 716 BasePlugin.stems:stems 717 717 718 BasePlugin.file_rename_method:The method to be used in renaming the copy of the imported file and associated files. 719 720 BasePlugin.rename_method.url:Use url encoding in renaming files and associated files. 721 722 BasePlugin.rename_method.base64:Use base64 encoding in renaming imported files and associated files. 723 718 724 BibTexPlugin.desc:BibTexPlugin reads bibliography files in BibTex format. BibTexPlugin creates a document object for every reference in the file. It is a subclass of SplitTextFile, so if there are multiple records, all are read. 719 725 -
gsdl/trunk/perllib/unicode.pm
r18282 r18319 600 600 601 601 # When a filename on the filesystem is already URL-encoded, the 602 # URL to it will have %25s in inplace of every % sign, so that602 # URL to it will have %25s in place of every % sign, so that 603 603 # URLs in html pages can refer to the URL-encoded filename. 604 604 # This method changes the URL reference back into the actual … … 606 606 sub url_to_filename { 607 607 my ($text) =@_; 608 $text =~ s/%25/%/g ;608 $text =~ s/%25/%/g if is_url_encoded($text); 609 609 return $text; 610 610 } … … 619 619 # a url more than once this way. 620 620 sub filename_to_url { 621 my ($text) =@_; 622 623 if($text !~ m/%25/) { 624 $text =~ s/%/%25/g; 621 my ($text, $rename_method) = @_; 622 623 if(!defined $rename_method || $rename_method eq "url") { 624 if($text !~ m/%25/) { 625 $text =~ s/%/%25/g; 626 } 625 627 } 626 628 return $text; -
gsdl/trunk/perllib/util.pm
r17714 r18319 28 28 use File::Copy; 29 29 use File::Basename; 30 use MIME::Base64; # for base64 encoding 30 31 31 32 use strict; … … 994 995 } 995 996 997 # returns the given filename converted using either URL encoding or 998 # base64 encoding, as specified by $rename_method 999 sub rename_file { 1000 my ($filename, $rename_method) = @_; 1001 1002 my ($tailname,$dirname,$suffix) = File::Basename::fileparse($filename, "\\.[^\\.]+\$"); 1003 1004 if (!$rename_method) { 1005 print STDERR "WARNING: no file renaming method specified. Defaulting to using URL encoding...\n"; 1006 # Debugging information 1007 my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(1); 1008 print STDERR "Calling method; $cfilename:$cline $cpackage->$csubr\n"; 1009 } 1010 1011 if (!$rename_method || $rename_method eq "url") { 1012 $tailname = &unicode::url_encode($tailname); 1013 } 1014 elsif ($rename_method eq "base64") { 1015 $tailname = &MIME::Base64::encode_base64($tailname); 1016 $tailname =~ s/\s*//sg; # for some reason it adds spaces not just at end but also in middle 1017 } 1018 1019 $filename = "$tailname$suffix"; 1020 $filename = "$dirname$filename" if ($dirname ne "./"); 1021 1022 return $filename; 1023 } 1024 996 1025 1;
Note:
See TracChangeset
for help on using the changeset viewer.