=head1 NAME EPrints::Plugin::Export::MySimple =cut package EPrints::Plugin::Export::MySimple; use EPrints::Plugin::Export::TextFile; @ISA = ( "EPrints::Plugin::Export::TextFile" ); use strict; sub new { my( $class, %params ) = @_; my $self = $class->SUPER::new( %params ); $self->{name} = "Simple Metadata"; $self->{accept} = [ 'dataobj/eprint' ]; $self->{visible} = "all"; return $self; } sub output_dataobj { my( $plugin, $dataobj ) = @_; my $data = $plugin->convert_dataobj( $dataobj ); my $r = ""; foreach( @{$data} ) { next unless defined( $_->[1] ); $r.=$_->[0].": ".$_->[1]."\n"; } $r.="\n"; return $r; } sub dataobj_to_html_header { my( $plugin, $dataobj ) = @_; my $links = $plugin->{session}->make_doc_fragment; my $epdata = $plugin->convert_dataobj( $dataobj ); foreach( @{$epdata} ) { $links->appendChild( $plugin->{session}->make_element( "meta", name => "eprints.".$_->[0], content => $_->[1] ) ); $links->appendChild( $plugin->{session}->make_text( "\n" )); } return $links; } sub convert_dataobj { my( $plugin, $eprint ) = @_; my @epdata = (); my $dataset = $eprint->get_dataset; foreach my $fieldname ( qw/ creators_name creators_id type datestamp lastmod metadata_visibility latitude longitude title subjects full_text_status keywords note abstract date date_type official_url referencetext / ) { next unless $dataset->has_field( $fieldname ); next unless $eprint->is_set( $fieldname ); my $field = $dataset->get_field( $fieldname ); my $value = $eprint->get_value( $fieldname ); if( $field->isa("EPrints::MetaField::Multilang")) { my($values, $langs) = map {$_->get_value($eprint)} @{$field->property( "fields_cache" )}; $values = [$values] if ref($values) ne "ARRAY"; $langs = [$langs] if ref($values) ne "ARRAY"; foreach my $i (0..$#$values) { push @epdata, [ $fieldname, $values->[$i] ]; } } elsif( $field->get_property( "multiple" )) { foreach my $item ( @{$value} ) { if( $field->is_type( "name" ) ) { push @epdata, [ $fieldname, ($item->{family}||"").", ".($item->{given}||"") ]; }elsif($field->is_type("subject")){ my $subject = EPrints::DataObj::Subject->new( $plugin->{session}, $item); next unless(defined $subject); push @epdata, ["subject", EPrints::Utils::tree_to_utf8( $subject->render_description())]; } else { push @epdata, [ $fieldname, $item ]; } } } else { push @epdata, [ $fieldname, $value ]; } } # The citation for this eprint push @epdata, [ "citation", EPrints::Utils::tree_to_utf8( $eprint->render_citation() ) ]; foreach my $doc ( $eprint->get_all_documents ) { push @epdata, [ "document_url", $doc->get_url() ]; } return \@epdata; } 1; =head1 COPYRIGHT =for COPYRIGHT BEGIN Copyright 2000-2011 University of Southampton. =for COPYRIGHT END =for LICENSE BEGIN This file is part of EPrints L. EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. EPrints is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with EPrints. If not, see L. =for LICENSE END