Bug 17807: Use XSLT_Handler in Koha::OAI
Replacing some code in the OAI modules by a call to an existing module. Note that the xmldoc format is used in the transform call to get a xml document object. The stylesheet method of Repository now only returns the name of the xsl file to be used instead of a cached xslt object. Similar functionality inside XSLT_Handler is used when calling transform. Note: We still lack unit tests in this area. I did not see the need for adding something for stylesheet since it only returns a simple string. The other change is made in Record::new; there are no tests for this module yet and the heart of the change here is actually tested already in XSLT_Handler.t. Note: I benchmarked calls to Repository in the old and the new situation and did not see significant changes. Test plan: [1] Run t/db_dependent/OAI/Server.t [2] Run oai.pl with ListRecords and marcxml. [3] Run oai.pl with ListRecords and oai_dc. Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
60bddbcc96
commit
6719eee83a
2 changed files with 25 additions and 29 deletions
|
@ -21,6 +21,7 @@ package Koha::OAI::Server::Record;
|
|||
use Modern::Perl;
|
||||
use HTTP::OAI;
|
||||
use HTTP::OAI::Metadata::OAI_DC;
|
||||
use XML::LibXML;
|
||||
|
||||
use base ("HTTP::OAI::Record");
|
||||
|
||||
|
@ -40,14 +41,21 @@ sub new {
|
|||
$self->header->setSpec($setSpec);
|
||||
}
|
||||
|
||||
my $parser = XML::LibXML->new();
|
||||
my $record_dom = $parser->parse_string( $marcxml );
|
||||
my $format = $args{metadataPrefix};
|
||||
if ( $format ne 'marc21' && $format ne 'marcxml' ) {
|
||||
my %args = (
|
||||
my $format = $args{metadataPrefix};
|
||||
my $record_dom;
|
||||
if ( $format ne 'marcxml' ) {
|
||||
my $args = {
|
||||
OPACBaseURL => "'" . C4::Context->preference('OPACBaseURL') . "'"
|
||||
);
|
||||
$record_dom = $repository->stylesheet($format)->transform($record_dom, %args);
|
||||
};
|
||||
# call Koha::XSLT_Handler now
|
||||
$record_dom = $repository->{xslt_engine}->transform({
|
||||
xml => $marcxml,
|
||||
file => $repository->stylesheet($format),
|
||||
parameters => $args,
|
||||
format => 'xmldoc',
|
||||
});
|
||||
} else {
|
||||
$record_dom = XML::LibXML->new->parse_string( $marcxml );
|
||||
}
|
||||
$self->metadata( HTTP::OAI::Metadata->new( dom => $record_dom ) );
|
||||
|
||||
|
|
|
@ -32,13 +32,11 @@ use Koha::OAI::Server::GetRecord;
|
|||
use Koha::OAI::Server::ListRecords;
|
||||
use Koha::OAI::Server::ListIdentifiers;
|
||||
use XML::SAX::Writer;
|
||||
use XML::LibXML;
|
||||
use XML::LibXSLT;
|
||||
use YAML::Syck qw( LoadFile );
|
||||
use CGI qw/:standard -oldstyle_urls/;
|
||||
use C4::Context;
|
||||
use C4::Biblio;
|
||||
|
||||
use Koha::XSLT_Handler;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
@ -106,7 +104,7 @@ sub new {
|
|||
$self->{ koha_identifier } = C4::Context->preference("OAI-PMH:archiveID");
|
||||
$self->{ koha_max_count } = C4::Context->preference("OAI-PMH:MaxCount");
|
||||
$self->{ koha_metadata_format } = ['oai_dc', 'marc21', 'marcxml'];
|
||||
$self->{ koha_stylesheet } = { }; # Build when needed
|
||||
$self->{ xslt_engine } = Koha::XSLT_Handler->new;
|
||||
|
||||
# Load configuration file if defined in OAI-PMH:ConfFile syspref
|
||||
if ( my $file = C4::Context->preference("OAI-PMH:ConfFile") ) {
|
||||
|
@ -170,24 +168,14 @@ sub get_biblio_marcxml {
|
|||
|
||||
sub stylesheet {
|
||||
my ( $self, $format ) = @_;
|
||||
|
||||
my $stylesheet = $self->{ koha_stylesheet }->{ $format };
|
||||
unless ( $stylesheet ) {
|
||||
my $xsl_file = $self->{ conf }
|
||||
? $self->{ conf }->{ format }->{ $format }->{ xsl_file }
|
||||
: ( C4::Context->config('intrahtdocs') .
|
||||
'/prog/en/xslt/' .
|
||||
C4::Context->preference('marcflavour') .
|
||||
'slim2OAIDC.xsl' );
|
||||
$xsl_file || die( "No stylesheet found for $format" );
|
||||
my $parser = XML::LibXML->new();
|
||||
my $xslt = XML::LibXSLT->new();
|
||||
my $style_doc = $parser->parse_file( $xsl_file );
|
||||
$stylesheet = $xslt->parse_stylesheet( $style_doc );
|
||||
$self->{ koha_stylesheet }->{ $format } = $stylesheet;
|
||||
}
|
||||
|
||||
return $stylesheet;
|
||||
my $xsl_file = $self->{ conf }
|
||||
? $self->{ conf }->{ format }->{ $format }->{ xsl_file }
|
||||
: ( C4::Context->config('intrahtdocs') .
|
||||
'/prog/en/xslt/' .
|
||||
C4::Context->preference('marcflavour') .
|
||||
'slim2OAIDC.xsl'
|
||||
);
|
||||
return $xsl_file;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue