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
Create Export Plugins
(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!
==Hello World export plugin== http://en.wikipedia.org/wiki/Hello_world_program Export plugins are stored in: /opt/eprints3/perl_lib/EPrints/Plugin/Export/ Create a new file in this directory called ''HelloWorld.pm'', and paste the following code into it (this is a useful template for writing export plugins!): <pre> package EPrints::Plugin::Export::HelloWorld; use EPrints::Plugin::Export; @ISA = ( "EPrints::Plugin::Export" ); use strict; sub new { my( $class, %opts ) = @_; } sub output_dataobj { my( $plugin, $dataobj ) = @_; } 1; </pre> The ''new'' subroutine creates the plugin - this is where you '''register''' the plugin with EPrints. The ''output_dataobj'' subroutine is where you '''convert''' EPrints data to the output format. '''Perl notes: # <tt>package ...</tt> - the plugin (Perl module) namespace, which should always be EPrints::Plugin::Export::''PluginID'' (note that the file should be called ''PluginID''.pm) # <tt>use EPrints::Plugin::Export, @ISA=...</tt> - inherit all the internal wiring needed for EPrints to use your plugin ===Register Hello World plugin=== Add the following to the ''new'' subroutine to register the plugin with EPrints: <pre> sub new { my( $class, %opts ) = @_; my $self = $class->SUPER::new( %opts ); $self->{name} = "Hello, World!"; $self->{accept} = [ 'dataobj/eprint', 'list/eprint' ]; $self->{visible} = "all"; $self->{suffix} = ".txt"; $self->{mimetype} = "text/plain; charset=utf-8"; return $self; } </pre> ===Convert EPrints data to Hello World data=== Add the following to the ''output_dataobj'' subroutine: <pre> sub output_dataobj { my( $plugin, $dataobj ) = @_; my $title = $dataobj->get_value( "title" ); return "Hello, World! $title\n\n"; } </pre> This subroutine "converts" an eprint object by getting its title and using it in a Hello, World! message. ===Testing the Hello World plugin=== Save the ''HelloWorld.pm'' file and then restart the Web server, eg.: service httpd restart '''Why do I need to restart the Web server?''' EPrints uses mod_perl which loads all Perl modules at start up; therefore whenever these modules change they need to be reloaded. The Hello World export plugin handles lists of eprints and single eprints. Therefore, EPrints displays it in the list of export plugins on the search results page: [[Image:Hello-world-export.png|frame|none|Selecting the Hello World export plugin from the search results page]] When the Hello World export plugin is activated, the ''convert_dataobj'' subroutine is applied to every item in the list to produce the result: [[Image:Hello-world-export-result.png|frame|none|The output of the Hello World export plugin]]
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)