Changeset 394

Show
Ignore:
Timestamp:
04/22/07 14:50:36 (1 year ago)
Author:
miya
Message:

SVN::TracWiki: Use File::Extract.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • SVN-TracWiki/lib/SVN/TracWiki.pm

    r391 r394  
    1010use RPC::XML; 
    1111use RPC::XML::Client; 
     12use File::Extract; 
     13use UNIVERSAL::can; 
    1214 
    1315$RPC::XML::ENCODING = 'UTF-8'; 
     
    4143    my $self = shift; 
    4244 
    43     my @plugins = $self->load_plugins; 
     45    my $e = File::Extract->new; 
     46    $e->magic->add_file_ext('xls', 'application/excel'); 
     47    $self->{extractor} = $e; 
     48 
     49    $self->load_plugins; 
    4450 
    4551    my @files = $self->get_files; 
    4652 
    47     my $mimetypes = MIME::Types->new; 
     53 
    4854    my $temp_dir = $self->{config}->{svn}->{temp_dir}; 
    4955    for my $file ( @files ) { 
    5056        my $path = file( File::Spec->catfile( $temp_dir, $file ) ); 
    51         my $type = $mimetypes->mimeTypeOf($path); 
    52         for my $plugin ( @plugins ) { 
    53             next unless $plugin->check_mime_type($type); 
    54             my $text = $plugin->filter($path); 
    55             $text = "source:$file\n\n{{{\n" . $text . "\n}}}"; 
    56             $self->publish_to_wiki($file, $text); 
    57         } 
     57        my $r = $self->{extractor}->extract($path->stringify); 
     58 
     59        next unless $r; 
     60        my $text = $r->text; 
     61 
     62        Encode::_utf8_off($text) if Encode::is_utf8($text); 
     63 
     64        next if $r->mime_type eq 'text/plain' or $r->mime_type eq 'text/html'; 
     65 
     66        $text = "source:$file\n\n{{{\n" . $text . "\n}}}"; 
     67        $self->publish_to_wiki($file, $text); 
    5868    } 
    5969 
     
    6676    my @plugins; 
    6777    for ( $self->plugins ) { 
     78        next unless $_ =~ /SVN::TracWiki::Plugin::Extract::/; 
    6879        my $plugin = $_->new; 
    69         $plugin->register; 
    70         push @plugins, $plugin; 
    71     } 
    72  
    73     return @plugins; 
     80 
     81        my $e = $self->{extractor}; 
     82        my $ext = $plugin->ext; 
     83        $e->magic->add_file_ext($ext, $plugin->mime_type) if $ext; 
     84        $e->register_processor($_); 
     85    } 
    7486} 
    7587 
     
    125137 
    126138    if ( ref $res eq 'RPC::XML::fault' ) { 
    127         die $res->faultString; 
     139        die $res->string; 
    128140    } 
    129141    elsif ( !ref $res ) { 
  • SVN-TracWiki/lib/SVN/TracWiki/Plugin.pm

    r391 r394  
    11package SVN::TracWiki::Plugin; 
    2  
    3 use base qw( Class::Accessor::Fast ); 
    42 
    53