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 1.3
(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!
=== Importer Plugin === The importer plugin is a perl package that handles the deposited file, and creates a new record in the repository for the record deposited. The Importer system is, as with all EPrints code, deeply hierarchical: # <code>EPrints::Plugin::Sword::Import::MyImporter</code> will inherit most of its code from <code>EPrints::Plugin::Sword::Import</code> # <code>EPrints::Plugin::Sword::Import</code> is never run directly, and inherits most it its functions from <code>EPrints::Plugin::Import</code> # <code>EPrints::Plugin::Import</code> is another ''base class'' (one that is there to provide central functions), and inherits from <code>EPrints::Plugin</code> # <code>EPrints::Plugin</code> is the ''base class'' for all plugins. In practice, the best way to learn how importers are written is to look at existing importers (<tt>~~eprints/perl-lib/EPrints/Plugin/Sword/Import/...</tt>) ==== 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::Sword::Import::MyImporter; use strict; use EPrints::Plugin::Sword::Import; our @ISA = qw/ EPrints::Plugin::Sword::Import /; sub new { my ( $class, %params ) = @_; my $self = $class->SUPER::new(%params); $self->{name} = "My Sword Importer"; return $self; } ## end sub new 1; </pre> This is actually pretty useless as all it will do is create a blank record, with the deposited file attached as a document. 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_file</code>, and it will have a framework something like: <pre> ## $opts{file} = $file; ## $opts{mime_type} = $headers->{content_type}; ## $opts{dataset_id} = $target_collection; ## $opts{owner_id} = $owner->get_id; ## $opts{depositor_id} = $depositor->get_id if(defined $depositor); ## $opts{no_op} = is this a No-op? ## $opts{verbose} = is this verbosed? sub input_file { my ( $plugin, %opts) = @_; my $session = $plugin->{session}; # needs to read the xml from the file: open my $fh, $file; my @xml = <$fh>; close $fh; my $xml = join '', @xml; my $epdata = {}; my $epdata = $plugin->parse_xml($xml); my $eprint = $dataset->create_object( $plugin->{session}, $epdata ); return $eprint; } sub parse_xml { my ($plugin, $xml) = @_; my $epdata = {}; #### do stuff return $epdata; } </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)