|  |     | 
| (27 intermediate revisions by 2 users not shown) | 
| Line 1: | Line 1: | 
| − | This page proves an overview of the API calls you can use to access the data in a DataObj.  The example framing this is that of an export plugin.
 | + | #REDIRECT [[Accessing Metadata Fields]] | 
| − |   |  | 
| − | == The Plugin ==
 |  | 
| − |   |  | 
| − | Below is a very simple export plugin, which outputs a single eprint or list of eprints as Text citations.
 |  | 
| − |   |  | 
| − | <pre>
 |  | 
| − | package EPrints::Plugin::Export::Text;
 |  | 
| − |   |  | 
| − | use EPrints::Plugin::Export::TextFile;
 |  | 
| − |   |  | 
| − | @ISA = ( "EPrints::Plugin::Export::TextFile" );
 |  | 
| − |   |  | 
| − | use strict;
 |  | 
| − |   |  | 
| − | sub new
 |  | 
| − | {
 |  | 
| − |         my( $class, %opts ) = @_;
 |  | 
| − |   |  | 
| − |         my $self = $class->SUPER::new( %opts );
 |  | 
| − |   |  | 
| − |         $self->{name} = "ASCII Citation";
 |  | 
| − |         $self->{accept} = ['dataobj/eprint', 'list/eprint' ];
 |  | 
| − |         $self->{visible} = "all";
 |  | 
| − |   |  | 
| − |         return $self;
 |  | 
| − | }
 |  | 
| − |   |  | 
| − |   |  | 
| − | sub output_dataobj
 |  | 
| − | {
 |  | 
| − |         my( $plugin, $dataobj ) = @_;
 |  | 
| − |   |  | 
| − |         my $cite = $dataobj->render_citation;
 |  | 
| − |   |  | 
| − |         return EPrints::Utils::tree_to_utf8( $cite )."\n\n";
 |  | 
| − | }
 |  | 
| − |   |  | 
| − | 1;
 |  | 
| − | </pre>
 |  | 
| − |   |  | 
| − | Note the output_dataobj function.  In an export plugin, this will be called on every item in the list that is being exported, and the results for all items aggregated and outputted.
 |  | 
| − |   |  | 
| − | There are two function calls of particular interest that aid in retrieving and managing data:
 |  | 
| − |   |  | 
| − | <pre>
 |  | 
| − | my $cite = $dataobj->render_citation;
 |  | 
| − | </pre>
 |  | 
| − |   |  | 
| − | This returns an HTML DOM object containing the citation of the dataobj as specified in the configuration files (see cfg/citations/eprint/default.xml).  Given an HTML DOM object, the following call will convert it into a string:
 |  | 
| − |   |  | 
| − | <pre>
 |  | 
| − | my $text = EPrints::Utils::tree_to_utf8( $html_dom )
 |  | 
| − | </pre>
 |  | 
| − |   |  | 
| − | == Accessing Metadata==
 |  |