Jump to content
Wiki Home
EPrints Home
Bazaar
Files
Main menu
Main menu
move to sidebar
hide
Navigation
Front Page
EPrints 3 Manual
EPrints Training Course
EPrints Glossary
Installing EPrints
How-to Configure EPrints
EPrints 3.2+ API
EPrints 3 Reference
EPrints Plugins
Wiki
All categories
Recent changes
Main Page
Help
EPrints Documentation
Search
Search
Appearance
Log in
Request account
Personal tools
Log in
Request account
Pages for logged out editors
learn more
Contributions
Talk
Editing
SWORD 2.0
(section)
Page
Discussion
British English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Basic framework ==== The very basic framework for an importer is just to register the importer with EPrints, and leave all functions to be handled by inheritence: <pre> package EPrints::Plugin::Import::RJ_Broker_2; use strict; use EPrints::Plugin::Import::Binary; use EPrints::Plugin::Import::Archive; our @ISA = qw/ EPrints::Plugin::Import::Archive /; sub new { my ( $class, %params ) = @_; my $self = $class->SUPER::new(%params); # The name to display $self->{name} = "RJ_Broker package"; # Who can see it, and whether we show it $self->{visible} = "all"; $self->{advertise} = 1; # What the importer produces $self->{produce} = [qw( list/eprint dataobj/eprint )]; # What mime-types can trigger this importer $self->{accept} = [ "application/vnd.rjbroker", "sword:http://opendepot.org/broker/1.0" ]; return $self; } ## end sub new 1; </pre> This defines a few important things: <pre> $self->{name} = "RJ_Broker package"; </pre> is the name to display in public <pre> # What the importer produces $self->{produce} = [qw( list/eprint dataobj/eprint )]; </pre> defines what the importer actually returns (some handle specific files [.pdf, .doc, .mp3], others may import several records in one go [eg EndNote files]) <pre> # What mime-types can trigger this importer $self->{accept} = [ "application/vnd.rjbroker", "sword:http://opendepot.org/broker/1.0" ]; </pre> Defines what content-types andh/or package-types trigger the use of this importer. (two importers registering to handle the same content-type is A bad Thing<sup>[tm]</sup> Whilst this is pretty, it's actually pretty useless as all it will do is replicate what <tt>Import::Archive</tt> does. To be useful, it needs to somehow read in some metadata and maybe attach some files. The first important task will be to handle the file deposited. For this, you need to create a function called <code>input_fh</code>, and it will have a framework something like: <pre> sub input_fh { my ( $plugin, %opts ) = @_; my $fh = $opts{fh}; my $dataset = $opts{dataset}; my $repo = $plugin->{session}; # get the type of file (should be zip) and the filename ($zipfile) for # the file just deposited. # (local method) my $zipfile = $plugin->upload_archive($fh); ## Do magic to get the XML file with the metadata my $epdata = $plugin->parse_epdcx_xml_data($xml_data); my $dataobj = $plugin->epdata_to_dataobj( $dataset, $epdata ); if ( defined $dataobj ) { push @ids, $dataobj->get_id; } return EPrints::List->new( dataset => $dataset, session => $repo, ids => \@ids ); } sub upload_archive { my ( $self, $fh ) = @_; use bytes; binmode($fh); my $zipfile = File::Temp->new(); binmode($zipfile); my $rc; my $lead; while ( $rc = sysread( $fh, my $buffer, 4096 ) ) { $lead = $buffer if !defined $lead; syswrite( $zipfile, $buffer ); } EPrints->abort("Error reading from file handle: $!") if !defined $rc; return $zipfile; } ## end sub upload_archive sub parse_epdcx_xml_data { my ( $plugin, $xml ) = @_; my $epdata = {}; ## parse the XML as needed... return $epdata; } ## end sub parse_epdcx_xml_data </pre>
Summary:
Please note that all contributions to EPrints Documentation may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
EPrints Documentation:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)