Bugzilla – Attachment 65535 Details for
Bug 17807
Use XSLT_Handler in oai.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17807: Use XSLT_Handler in Koha::OAI
Bug-17807-Use-XSLTHandler-in-KohaOAI.patch (text/plain), 4.97 KB, created by
Nick Clemens (kidclamp)
on 2017-08-07 12:28:05 UTC
(
hide
)
Description:
Bug 17807: Use XSLT_Handler in Koha::OAI
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2017-08-07 12:28:05 UTC
Size:
4.97 KB
patch
obsolete
>From 1b2b16d6efe07cf5fca9094a070b726552cec16c Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 21 Dec 2016 15:03:18 +0100 >Subject: [PATCH] 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> >--- > Koha/OAI/Server/Record.pm | 22 +++++++++++++++------- > Koha/OAI/Server/Repository.pm | 32 ++++++++++---------------------- > 2 files changed, 25 insertions(+), 29 deletions(-) > >diff --git a/Koha/OAI/Server/Record.pm b/Koha/OAI/Server/Record.pm >index cf86495..7b1078b 100644 >--- a/Koha/OAI/Server/Record.pm >+++ b/Koha/OAI/Server/Record.pm >@@ -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 ) ); > >diff --git a/Koha/OAI/Server/Repository.pm b/Koha/OAI/Server/Repository.pm >index 50891c0..51b7b57 100644 >--- a/Koha/OAI/Server/Repository.pm >+++ b/Koha/OAI/Server/Repository.pm >@@ -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") ) { >@@ -167,24 +165,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; > } > > >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17807
:
58348
|
58349
|
63463
|
63464
|
63935
|
64045
|
64046
|
64047
|
64048
|
65534
|
65535
|
65536
|
66635
|
66636
|
66637