Make js prompts translatable using _("...") and comment out unused vars.
[koha.git] / C4 / OAI / DC.pm
blobe19dd5e3e9a3cb8ab2f86437401da59013af87a6
1 # ---------------------------------------------------------------------
2 # Dublin Core helper class
3 # v1.0
4 # January 2007
5 # ------------------+--------------------------------------------------
6 # Ph. Jaillon |
7 # ------------------+----------------------+---------------------------
8 # Department of Computer Science |
9 # -----------------------------------------+-------------+-------------
10 # Ecole Nationale Superieure des Mines de St-Etienne | www.emse.fr
11 # -------------------------------------------------------+-------------
13 =head1 OAI::DC Dublin Core formating helper
15 OAI::DC is an helper class for Dublin Core metadata. As Dublin Core have a well known
16 set of fields, OAI::DC is a subclass of the OAI::DP class and it implements a default
17 behavior to build correct answers. The data references returned by Archive_GetRecord
18 and Archive_ListRecords must be instance providing the following method (they are used
19 to translate your own data to Dublin Core) : Title(), Identifier(), Subject(), Creator(),
20 Date(), Description(), Publisher(), Language() and Type(). The semantic of these methods is
21 the same as the corresponding Dublin Core field.
23 To return correct metadata, you must provide or overide theses methods:
25 =over
27 =over
29 =item B<new>: initialization step,
31 =item B<dispose>: clean up step,
33 =item B<Archive_ListSets>: return list of defined sets,
35 =item B<Archive_GetRecord>: return a record,
37 =item B<Archive_ListRecords>: return a list of records,
39 =item B<Archive_ListIdentifiers>: return a list of record identifiers,
41 =back
43 =back
45 =head2 new
47 =over
49 Object of this method is to build a new instance of your OAI data provider. At this step
50 you can overide somme default information about the repository, you can also initiate
51 connexion to a database... Parameters to the new method are user defined.
53 =back
55 =head2 dispose
57 =over
59 It's time to disconnect from database (if required). Must explicitly call SUPER::dispose().
61 =back
63 =head2 Archive_ListSets
65 =over
67 Return a reference to an array of list set. Each list set is a reference to a two element array.
68 The first element is the set name of the set and the second is its short description.
70 sub Archive_ListSets {
72 [ 'SET1', 'Description of the SET1'],
73 [ 'SET2', 'Description of the SET2'],
77 =back
79 =head2 Archive_GetRecord
81 =over
83 This method take a record identifier and metadata format as parameter. It must return a reference to
84 the data associated to identifier. Data are reference to a hash and must provide methodes describe
85 at the begining of DC section.
87 =back
89 =head2 Archive_ListRecords
91 =over
93 Object of this method is to return a list of records occording to the user query. Parameters of the method
94 are the set, the from date, the until date, the metadata type required and a resumption token if supported.
96 The method must return a reference to a list of records, the metadata type of the answer and reference to
97 token information. Token information must be undefined or a reference to a hash with the I<completeListSize>
98 and the I<cursor> keys set.
100 =back
102 =cut
104 package C4::OAI::DC;
106 use C4::OAI::DP;
107 use vars ('@ISA');
108 @ISA = ("C4::OAI::DP");
110 # format DC record
111 sub FormatDC
113 my ($self, $hashref) = @_;
115 return undef if( $hashref->Status() eq 'deleted' );
118 title => $hashref->Title(),
119 identifier => $hashref->Identifier(),
120 subject => $hashref->Subject(),
121 creator => $hashref->Creator(),
122 date => $hashref->Date(),
123 description => $hashref->Description(),
124 publisher => $hashref->Publisher(),
125 language => $hashref->Language(),
126 type => $hashref->Type(),
127 mdorder => [ qw (title creator subject description contributor publisher date type format identifier source language relation coverage rights) ]
131 # format header for ListIdentifiers
132 sub Archive_FormatHeader
134 my ($self, $hashref, $metadataFormat) = @_;
136 $self->FormatHeader ($hashref->Identifier()->[0] ,
137 $hashref->DateStamp(),
139 $hashref->Set()
143 # retrieve records from the source archive as required
144 sub Archive_FormatRecord
146 my ($self, $hashref, $metadataFormat) = @_;
148 if ($self->MetadataFormatisValid ($metadataFormat) == 0)
150 $self->AddError ('cannotDisseminateFormat', 'The value of metadataPrefix ('.$metadataFormat.') is not supported by the repository');
151 return '';
154 my $dc = $self->FormatDC ($hashref);
155 my $header = "<oaidc:dc xmlns=\"http://purl.org/dc/elements/1.1/\" ".
156 "xmlns:oaidc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" ".
157 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ".
158 "xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/ ".
159 "http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">\n";
160 my $footer = "</oaidc:dc>\n";
161 my $metadata = '';
163 $metadata = $header . $self->{'utility'}->FormatXML($dc) . $footer if( $dc );
165 $self->FormatRecord ($hashref->Identifier()->[0] ,
166 $hashref->DateStamp(),
167 $hashref->Status(),
168 $hashref->Set(),
169 $metadata,
175 # get full list of mdps or list for specific identifier
176 sub Archive_ListMetadataFormats
178 my ($self, $identifier) = @_;
180 if ((! defined $identifier) || ($identifier eq '')) {
181 return ['oai_dc'];
183 else {
184 $self->AddError ('idDoesNotExist', 'The value of the identifier argument is unknown or illegal in this repository');
186 return [];
190 # get full list of sets from the archive
191 sub Archive_ListSets
197 # get a single record from the archive
198 sub Archive_GetRecord
200 my ($self, $identifier, $metadataFormat) = @_;
202 $self->AddError ('idDoesNotExist', 'The value of the identifier argument is unknown or illegal in this repository');
203 undef;
206 # list metadata records from the archive
207 sub Archive_ListRecords
209 my ($self, $set, $from, $until, $metadataPrefix, $resumptionToken) = @_;
210 my $tokenInfo = undef;
212 $self->AddError ('noRecordsMatch', 'The combination of the values of arguments results in an empty set');
213 ( [], $resumptionToken, $metadataPrefix, $tokenInfo );
217 # list identifiers (headers) from the archive
218 sub Archive_ListIdentifiers
220 my ($self, $set, $from, $until, $metadataPrefix, $resumptionToken) = @_;
222 if (($metadataPrefix ne '') && ($self->MetadataFormatisValid ($metadataPrefix) == 0))
224 $self->AddError ('cannotDisseminateFormat', 'The value of metadataPrefix ('.$metadataPrefix.')is not supported by the repository');
225 return '';
228 $self->Archive_ListRecords ($set, $from, $until, $metadataPrefix, $resumptionToken);