package EPrints::Plugin::Export::OPFXML; use EPrints::Plugin::Export::XMLFile; @ISA = ( "EPrints::Plugin::Export::XMLFile" ); use strict; sub new { my( $class, %opts ) = @_; my $self = $class->SUPER::new( %opts ); $self->{name} = "Open Packaging Format XML"; # This plug-in can only output a single eprint record, no lists or other types of objects $self->{accept} = [ 'dataobj/eprint' ]; $self->{visible} = "all"; # Specify the mimetype so we can use an HTTP ACCEPT header to get this back. $self->{mimetype} = "application/oebps-package+xml; charset=utf-8"; # Again specify what we are exporting $self->{xmlns} = "http://www.idpf.org/2007/opf"; $self->{schemaLocation} = "http://www.idpf.org/2007/opf"; return $self; } # Method which is called to output the eprint, we would have output_list if we could handle lists sub output_dataobj { my( $plugin, $dataobj ) = @_; my $xml = $plugin->xml_dataobj( $dataobj ); return "" . EPrints::XML::to_string( $xml ); } # The method which actually does the work sub xml_dataobj { my( $plugin, $eprint ) = @_; my $repo = $plugin->{repository}; my $package = $repo->make_element("package", xmlns=>"http://www.idpf.org/2007/opf", "unique-identifier"=>"EPB-UUID", version=>"2.0"); my $metadata = $repo->make_element("metadata", "xmlns:opf"=>"http://www.idpf.org/2007/opf", "xmlns:dc"=>"http://purl.org/dc/elements/1.1/"); $package->appendChild($metadata); my $title = $repo->make_element("dc:title"); $title->appendText($eprint->value("title")); $metadata->appendChild($title); if( $eprint->exists_and_set( "creators" ) ) { foreach my $name ( @{ $eprint->get_value( "creators" ) } ) { # given name first my $creator = $repo->make_element("dc:creator"); $creator->appendText(EPrints::Utils::make_name_string( $name->{name}, 1 )); $metadata->appendChild($creator); } } return $package; } 1;