Changeset 21916


Ignore:
Timestamp:
2010-04-20T13:10:05+12:00 (11 years ago)
Author:
kjdon
Message:

made this work with a user specified process_exp so that your metadata files don't have to be named metadata.xml

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/MetadataXMLPlugin.pm

    r21905 r21916  
    163163}
    164164
     165sub get_doctype {
     166    my $self = shift(@_);
     167   
     168    return "(Greenstone)?DirectoryMetadata"
     169}
     170
     171sub can_process_this_file {
     172    my $self = shift(@_);
     173    my ($filename) = @_;
     174
     175    if (-f $filename && $self->SUPER::can_process_this_file($filename) && $self->check_doctype($filename)) {
     176    return 1; # its a file for us
     177    }
     178    return 0;
     179}
     180
     181sub check_doctype {
     182    my $self = shift (@_);
     183   
     184    my ($filename) = @_;
     185
     186    if (open(XMLIN,"<$filename")) {
     187    my $doctype = $self->get_doctype();
     188    ## check whether the doctype has the same name as the root element tag
     189    while (defined (my $line = <XMLIN>)) {
     190        ## find the root element
     191        if ($line =~ /<([\w\d:]+)[\s>]/){
     192        my $root = $1;
     193        if ($root !~ $doctype){
     194            close(XMLIN);
     195            return 0;
     196        }
     197        else {
     198            close(XMLIN);
     199            return 1;
     200        }
     201        }
     202    }
     203    close(XMLIN);
     204    }
     205   
     206    return undef; # haven't found a valid line
     207   
     208}
    165209
    166210sub file_block_read {
     
    168212    my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $gli) = @_;
    169213
    170     my $filename = &util::filename_cat($base_dir, $file);
    171     if ($filename !~ /metadata\.xml$/ || !-f $filename) {
    172         return undef;
    173     }
    174 
    175     $block_hash->{'metadata_files'}->{$filename} = 1;
     214    my $filename_full_path = &util::filename_cat($base_dir, $file);
     215    return undef unless $self->can_process_this_file($filename_full_path);   
     216
     217    $block_hash->{'metadata_files'}->{$filename_full_path} = 1;
    176218
    177219    return 1;
     
    186228
    187229    my $filename = &util::filename_cat($base_dir, $file);
    188     if ($filename !~ /metadata\.xml$/ || !-f $filename) {
    189         return undef;
    190     }
     230    return undef unless $self->can_process_this_file($filename);   
    191231
    192232    $self->{'metadata-file'} = $file;
    193233    $self->{'metadata-filename'} = $filename;
    194 
    195234
    196235    my $outhandle = $self->{'outhandle'};
     
    328367}
    329368
    330 #sub combine_metadata_structures
    331 #{
    332 #    my $self = shift(@_);
    333 #
    334 #    my ($mdref1, $mdref2) = @_;
    335 #    &metadatautil::combine_metadata_structures($mdref1, $mdref2);
    336 #}
    337369
    338370
Note: See TracChangeset for help on using the changeset viewer.