Lines 2-7
package C4::Record;
Link Here
|
2 |
# |
2 |
# |
3 |
# Copyright 2006 (C) LibLime |
3 |
# Copyright 2006 (C) LibLime |
4 |
# Parts copyright 2010 BibLibre |
4 |
# Parts copyright 2010 BibLibre |
|
|
5 |
# Part copyright 2015 Universidad de El Salvador |
5 |
# |
6 |
# |
6 |
# This file is part of Koha. |
7 |
# This file is part of Koha. |
7 |
# |
8 |
# |
Lines 25-31
use strict;
Link Here
|
25 |
# please specify in which methods a given module is used |
26 |
# please specify in which methods a given module is used |
26 |
use MARC::Record; # marc2marcxml, marcxml2marc, changeEncoding |
27 |
use MARC::Record; # marc2marcxml, marcxml2marc, changeEncoding |
27 |
use MARC::File::XML; # marc2marcxml, marcxml2marc, changeEncoding |
28 |
use MARC::File::XML; # marc2marcxml, marcxml2marc, changeEncoding |
28 |
use MARC::Crosswalk::DublinCore; # marc2dcxml |
|
|
29 |
use Biblio::EndnoteStyle; |
29 |
use Biblio::EndnoteStyle; |
30 |
use Unicode::Normalize; # _entity_encode |
30 |
use Unicode::Normalize; # _entity_encode |
31 |
use C4::Biblio; #marc2bibtex |
31 |
use C4::Biblio; #marc2bibtex |
Lines 36-41
use YAML; #marcrecords2csv
Link Here
|
36 |
use Template; |
36 |
use Template; |
37 |
use Text::CSV::Encoded; #marc2csv |
37 |
use Text::CSV::Encoded; #marc2csv |
38 |
use Koha::SimpleMARC qw(read_field); |
38 |
use Koha::SimpleMARC qw(read_field); |
|
|
39 |
use Koha::XSLT_Handler; |
40 |
use Carp; |
39 |
|
41 |
|
40 |
use vars qw($VERSION @ISA @EXPORT); |
42 |
use vars qw($VERSION @ISA @EXPORT); |
41 |
|
43 |
|
Lines 220-270
sub marcxml2marc {
Link Here
|
220 |
|
222 |
|
221 |
=head2 marc2dcxml - Convert from ISO-2709 to Dublin Core |
223 |
=head2 marc2dcxml - Convert from ISO-2709 to Dublin Core |
222 |
|
224 |
|
223 |
my ($error,$dcxml) = marc2dcxml($marc,$qualified); |
225 |
my dcxml = marc2dcxml ($marc, $xml, $biblionumber, $format); |
224 |
|
226 |
|
225 |
Returns a DublinCore::Record object, will eventually return a Dublin Core scalar |
227 |
EXAMPLE |
226 |
|
228 |
|
227 |
FIXME: should return actual XML, not just an object |
229 |
my dcxml = marc2dcxml (undef, undef, 1, "oaidc"); |
|
|
230 |
|
231 |
Convert MARC or MARCXML to Dublin Core metadata (XSLT Transformation), |
232 |
optionally can get an XML directly from database (biblioitems.marcxml) |
233 |
without item information. This method take into consideration the syspref |
234 |
'marcflavour' (UNIMARC, MARC21 and NORMARC). |
235 |
Return an XML file with the format defined in C<$format> |
228 |
|
236 |
|
229 |
C<$marc> - an ISO-2709 scalar or MARC::Record object |
237 |
C<$marc> - an ISO-2709 scalar or MARC::Record object |
230 |
|
238 |
|
231 |
C<$qualified> - specify whether qualified Dublin Core should be used in the input or output [0] |
239 |
C<$xml> - a MARCXML file |
|
|
240 |
|
241 |
C<$biblionumber> - obtain the record directly from database (biblioitems.marcxml) |
242 |
|
243 |
C<$format> - accept three type of DC formats (oaidc, srwdc, and rdfdc ) |
232 |
|
244 |
|
233 |
=cut |
245 |
=cut |
234 |
|
246 |
|
235 |
sub marc2dcxml { |
247 |
sub marc2dcxml { |
236 |
my ($marc,$qualified) = @_; |
248 |
my ( $marc, $xml, $biblionumber, $format ) = @_; |
237 |
my $error; |
249 |
|
238 |
# test if it's already a MARC::Record object, if not, make it one |
250 |
# global variables |
239 |
my $marc_record_obj; |
251 |
my ( $marcxml, $record, $output ); |
240 |
if ($marc =~ /^MARC::Record/) { # it's already a MARC::Record object |
252 |
|
241 |
$marc_record_obj = $marc; |
253 |
# set the default path for intranet xslts |
242 |
} else { # it's not a MARC::Record object, make it one |
254 |
my $path2xslt = '/prog/en/xslt/'; |
243 |
eval { $marc_record_obj = MARC::Record->new_from_usmarc($marc) }; # handle exceptions |
255 |
|
|
|
256 |
# differents xslts to process (OAIDC, SRWDC and RDFDC) |
257 |
my $xslt_oaidc = C4::Context->config('intrahtdocs') . |
258 |
$path2xslt . |
259 |
C4::Context->preference('marcflavour') . |
260 |
'slim2OAIDC.xsl'; |
261 |
|
262 |
my $xslt_srwdc = C4::Context->config('intrahtdocs') . |
263 |
$path2xslt . |
264 |
C4::Context->preference('marcflavour') . |
265 |
'slim2SRWDC.xsl'; |
266 |
|
267 |
my $xslt_rdfdc = C4::Context->config('intrahtdocs') . |
268 |
$path2xslt . |
269 |
C4::Context->preference('marcflavour') . |
270 |
'slim2RDFDC.xsl'; |
271 |
|
272 |
if ( defined $marc ) { |
273 |
# no need to catch errors or warnings marc2marcxml do it instead |
274 |
$marcxml = C4::Record::marc2marcxml( $marc ); |
275 |
} elsif ( not defined $xml and defined $biblionumber ) { |
276 |
# get MARCXML biblio directly from biblioitems.marcxml without item information |
277 |
$marcxml = C4::Biblio::GetXmlBiblio( $biblionumber ); |
278 |
} else { |
279 |
$marcxml = $xml; |
280 |
} |
244 |
|
281 |
|
245 |
# conversion to MARC::Record object failed, populate $error |
282 |
# only proceed if MARC21 or UNIMARC; else clause is executed if marcflavour set it to NORMARC |
246 |
if ($@) { |
283 |
# generate MARC::Record object to see if not a marcxml record |
247 |
$error .="\nCreation of MARC::Record object failed: ".$MARC::File::ERROR; |
284 |
unless ( C4::Context->preference('marcflavour') eq 'NORMARC' ) { |
248 |
} |
285 |
eval { $record = MARC::Record->new_from_xml( |
249 |
} |
286 |
$marcxml, |
250 |
my $crosswalk = MARC::Crosswalk::DublinCore->new; |
287 |
'UTF-8', |
251 |
if ($qualified) { |
288 |
C4::Context->preference('marcflavour') |
252 |
$crosswalk = MARC::Crosswalk::DublinCore->new( qualified => 1 ); |
289 |
); |
253 |
} |
290 |
}; |
254 |
my $dcxml = $crosswalk->as_dublincore($marc_record_obj); |
291 |
} else { |
255 |
my $dcxmlfinal = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
292 |
eval { $record = MARC::Record->new_from_xml( |
256 |
$dcxmlfinal .= "<metadata |
293 |
$marcxml, |
257 |
xmlns=\"http://example.org/myapp/\" |
294 |
'UTF-8', |
258 |
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" |
295 |
'MARC21' |
259 |
xsi:schemaLocation=\"http://example.org/myapp/ http://example.org/myapp/schema.xsd\" |
296 |
); |
260 |
xmlns:dc=\"http://purl.org/dc/elements/1.1/\" |
297 |
}; |
261 |
xmlns:dcterms=\"http://purl.org/dc/terms/\">"; |
298 |
} |
262 |
|
299 |
|
263 |
foreach my $element ( $dcxml->elements() ) { |
300 |
# conversion to MARC::Record object failed |
264 |
$dcxmlfinal.="<"."dc:".$element->name().">".$element->content()."</"."dc:".$element->name().">\n"; |
301 |
if ( $@ ) { |
|
|
302 |
croak "Creation of MARC::Record object failed:"; |
303 |
} elsif ( $record->warnings() ) { |
304 |
carp "Warnings encountered while processing ISO-2709 record.\n"; |
305 |
my @warnings = $record->warnings(); |
306 |
foreach my $warn (@warnings) { |
307 |
carp "\t". $warn; |
308 |
}; |
309 |
} elsif ( $record =~ /^MARC::Record/ ) { # if OK makes xslt transformation |
310 |
my $xslt_engine = Koha::XSLT_Handler->new; |
311 |
if ( $format eq "oaidc" ) { |
312 |
$output = $xslt_engine->transform($marcxml, $xslt_oaidc); |
313 |
} elsif ( $format eq "srwdc" ) { |
314 |
$output = $xslt_engine->transform($marcxml, $xslt_srwdc); |
315 |
} else { |
316 |
$output = $xslt_engine->transform($marcxml, $xslt_rdfdc); |
317 |
} |
318 |
my $err = $xslt_engine->err; # error number |
319 |
my $errstr = $xslt_engine->errstr; # error message |
320 |
if ( $err ) { |
321 |
croak "Error when processing $errstr Error number: $err\n"; |
322 |
} else { |
323 |
return $output; |
324 |
} |
265 |
} |
325 |
} |
266 |
$dcxmlfinal .= "\n</metadata>"; |
|
|
267 |
return ($error,$dcxmlfinal); |
268 |
} |
326 |
} |
269 |
|
327 |
|
270 |
=head2 marc2modsxml - Convert from ISO-2709 to MODS |
328 |
=head2 marc2modsxml - Convert from ISO-2709 to MODS |